【发布时间】:2016-01-16 18:36:04
【问题描述】:
我有一个课堂作业,我用 Java 制作了一个带有 GUI 的简单会计程序。这是我第一次在 Java 中使用 GUI,而且我不是一个优秀的程序员。
当程序运行时,用户可以选择五个 JButton,单击这些按钮会将它们带到一个带有一些输入对话框的新 JFrame,这些对话框保存为字符串和双精度。 我的变量设置为类似
变量 = JOptionPane.showInputDialog("TEXTGOESHERE");
我的问题是,在对话框中输入值后,它们会再次弹出,就像在循环中一样。用户必须在每个对话框中输入两次。
其中一个按钮的代码:
pcButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFrame pcframe = new JFrame("Choosing a File Menu");
pcframe.setSize(760,500);
pcframe.add( new JPanel()
{
public void paintComponent( Graphics g )
{
super.paintComponent(g);
//ACTION BEGIN-----------------------------------------
出现两次的输入对话框:
compName = JOptionPane.showInputDialog("What is the name of your business?");
firstName = JOptionPane.showInputDialog("What is your first name?");
lastName = JOptionPane.showInputDialog("What is your last name?");
day = JOptionPane.showInputDialog("What is the day?");
month = JOptionPane.showInputDialog("What is the month?");
year = JOptionPane.showInputDialog("What is the year?");
String filename = JOptionPane.showInputDialog("Would you like file 1, 2, or 3? (Type in 1, 2, or 3");
filename = (filename + ".txt");
//Storing File into array
//Calculations
g.drawString("" + compName, 330, 15);
//More drawStrings
//ACTION END-------------------------------------------
}
});
pcframe.setVisible( true );
}
});
modePanel.add(pcButton);
当按下 pcButton 时,用户应该输入他们的姓名、文件等。但是,每个对话框输入都会显示两次。我希望输入只显示一次。
任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: java swing user-interface joptionpane