我想创建一个用于POS系统的新窗口。用户输入用于客户具有的金额并且窗口必须显示交换金额。我新JOptionPane
功能(我一直在使用JAVAFX
,这是不同的)。Java Swing:从JOptionPane获取文本值
这是我的代码:
public static void main(String[] argv) throws Exception {
String newline = System.getProperty("line.separator");
int cost = 100;
int amount = Integer.parseInt(JOptionPane.getText()) // this is wrong! This needs to come from user input box in the same window.
JFrame frame = new JFrame();
String message = "Enter the amount of money"+newline+"The exchange money is: "+amount-cost;
String text = JOptionPane.showInputDialog(frame, message);
if (text == null) {
// User clicked cancel
}
有没有什么建议?
可能请你进一步澄清了一下!对我来说,你想为用户提出一个'JOptionPane',现在当用户在同一个'JOptionPane'中输入某些东西作为输入时,你希望在同一个'JOptionPane'内部的东西可以改变,关于用户输入。我对吗? – 2014-10-28 17:27:06
好的 - 显示JOptionPane:有一个文本字段和消息字段。如果文本写入文本字段中,消息字段将会更改。 – charen 2014-10-28 17:33:48
只需使用你自己的'Component'传递给'JOptionPane',并让你的'Component'处理事件和更新 – Robin 2014-10-28 17:40:40