joptionpane

java WordGame program

柔情痞子 提交于 2019-12-13 05:08:41
问题 I am totally a beginner. This is a project for school. I just need to know, can anyone tell me why this won't run ? import javax.swing.JOptionPane; public class WordGame { public static void main(String[] args) { String name; name= JOptionPane.showInputDialog("Enter your name"); String age; age= JOptionPane.showInputDialog("Enter your age"); String city; city= JOptionPane.showInputDialog("Enter the name of a city"); String college; college= JOptionPane.showInputDialog("Enter the name of a

How do display Multiple Lines in a JOptionPane with ArrayList

泪湿孤枕 提交于 2019-12-13 00:24:37
问题 I'm trying to display 2 Arraylist in the JOptionPane. But I get the following on the dialog box 1,2,3,4 Swimming, Running, Cycling, Basketball I would like to show the info in the dialog box like the following: 1 Swimming 2 Running 3 Cycling 4 Basketball Please advise how do I go about? Here are my codes. import javax.swing.*; import java.util.ArrayList; public class gamelist { public static void main(String args[]){ ArrayList<String> sku = new ArrayList<String> (); sku.add("1"); sku.add("2")

JTextArea in JScrollPane wrapping words but missing letters

≯℡__Kan透↙ 提交于 2019-12-12 13:31:44
问题 I wanted to make a JOptionPane.showOptionDialog with some JTextArea and JLabel . The problem was that the dialog was too small and i didn't find any solutions, so i just decided to put my content in a JScrollPane . I saw that i must put all my JTextArea and my JLabel in a JPanel because adding them in the JScrollPane in a row doesn't allow me to put the viewport correctly. The final problem is that my JTextArea are wrapping words correctly but when i have words of 2 or 3 letters lenght, they

How to convert a JOptionPane to a JDialog

爷,独闯天下 提交于 2019-12-12 12:27:55
问题 I need to convert a JOptionPage to a JDialog, because I need to get rid of that quirky "OK" button. Below is the code... JOptionPane.showMessageDialog(null, Interface, caption, JOptionPane.WARNING_MESSAGE, icon); Interface is my GUI, "caption" is the title, then I have a warning message, then I have my custom icon. This might not even be possible with the given info, but I really need to get rid of that OK. Any help would be appreciated. 回答1: Why not simply create a JDialog and put your

JOptionPane with multiple buttons on each line?

徘徊边缘 提交于 2019-12-12 11:01:57
问题 How would I go about displaying a JOptionPane.showinputDialog() with multiple JButtons on each line? I am not talking about the Yes , No , Cancel buttons but multiple custom labeled JButtons that displays in the content area of JOptionPane.showinputDialog ? so I would need to get the value of the button pressed from the JOptionPane as well. 回答1: You can place any JComponents to the JOptionPane, there I can't see any limits, JOptionPane is same Top-Level Container as JFrame , JDialog or

Switch from one “Input dialog box” to another “input dialog box”?

99封情书 提交于 2019-12-12 06:38:42
问题 well hope you all are well.. I'm making a simple Phone book diary , so the problem is When i click new , it must open a dialog box JOptionPane , and yes it opens successfully, but after click ok i want to show a new dialog box again to ask phone number .. well i know to do coding but looking for a logic how to do that? here is my source codes: package phonebook; import javax.swing.*; public class MainProgram extends javax.swing.JFrame { public MainProgram() { initComponents(); } private void

How do I display something I enter in a JOptionPane on the JFrame?

送分小仙女□ 提交于 2019-12-12 04:46:32
问题 What I want to do is when I input something in JOptionPane, say, APPLES. I want to display it as APPLES in the JFrame. Now, if I want to input CATS next, it'll appear in the JFrame together with the APPLES. It should look like this: APPLES CATS And when I input more, it just displays and displays. The only way I know how to do it is to use setText for JLabel, but it's only displaying ONE word. How do I display ALL of the words I input? 回答1: but it's only displaying ONE word Hoping that you

No errors, but crashing - JOptionPane - JavaFX

馋奶兔 提交于 2019-12-12 04:30:03
问题 I am trying to get a pop-up message when the cake node is clicked on. It prints to the console, but "JOptionPane.showMessageDialog(null,"Test");" crashes the program when I click on the cake (no errors). Any ideas? class Cake extends Item { double dx=3,dy=1.6; Cake(String imageFile, double x, double y) { super(imageFile, x, y); } @Override public void move() { this.setX(this.getX()+dx); if(this.getX()>749 || this.getX()<-20) { dx=-dx; } this.setY(this.getY()+dy); if(this.getY()>530 || this

How to close a JFrame in the middle of a program

左心房为你撑大大i 提交于 2019-12-12 04:23:55
问题 public class JFrameWithPanel extends JFrame implements ActionListener, ItemListener { int packageIndex; double price; double[] prices = {49.99, 39.99, 34.99, 99.99}; DecimalFormat money = new DecimalFormat("$0.00"); JLabel priceLabel = new JLabel("Total Price: "+price); JButton button = new JButton("Check Price"); JComboBox packageChoice = new JComboBox(); JPanel pane = new JPanel(); TextField text = new TextField(5); JButton accept = new JButton("Accept"); JButton decline = new JButton(

UIManager in Java Swing not working consistently? / JOptionPane Message Background

試著忘記壹切 提交于 2019-12-12 01:48:05
问题 I'm trying to set the background color in my custom JOptionPane and no matter what, I cannot get the message part of the option pane to change color. Attempt #1 was to set the pane background and opaque. Attempt #2 was to also loop through the pane's components, and set the opaque and/or background attributes if they were JPanel or JLabel. This did not work for the message part. From what I can see, the JPanel does not even exist as one of the components. Attempt #3 was to use UIManager,