java showinputdialog_java - JOptionPane.showInputDialog中的多个输入
有沒有一種方法可以在JOptionPane.showInputDialog中創建多個輸入,而不是只創建一個輸入?
最佳答案:
對。您知道可以將任何Object放入大多數Object的JOptionPane.showXXX methods參數中,并且經常會發現Object恰好是一個JPanel參數。
在您的情況下,也許您可以使用一個包含多個JPanel的JTextFieldsimport javax.swing.*;
public class JOptionPaneMultiInput {
public static void main(String[] args) {
JTextField xField = new JTextField(5);
JTextField yField = new JTextField(5);
JPanel myPanel = new JPanel();
myPanel.add(new JLabel("x:"));
myPanel.add(xField);
myPanel.add(Box.createHorizontalStrut(15)); // a spacer
myPanel.add(new JLabel("y:"));
myPanel.add(yField);
int result = JOptionPane.showConfirmDialog(null, myPanel,
"Please Enter X and Y Values", JOptionPane.OK_CANCEL_OPTION);
if (result == JOptionPane.OK_OPTION) {
System.out.println("x value: " + xField.getText());
System.out.println("y value: " + yField.getText());
}
}
}
創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎總結
以上是生活随笔為你收集整理的java showinputdialog_java - JOptionPane.showInputDialog中的多个输入的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux java 共享内存_Linu
- 下一篇: 台达plc自由口通讯_台达PLC和ABB