java 如何制作具有多个文本字段的输入对话框(即可以接受多个输入)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3170427/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 00:40:01  来源:igfitidea点击:

How to make an input dialogbox which has more than one textfield(ie. can take many inputs)

javaswinginputtextfielddialog

提问by Haxed

I have implemented an inputDialogBox, however this has one textfield. I need an input DialogBox which has many textfieldsto take input from and store each String in an array.

我已经实现了一个输入对话框,但是它有一个 textfield。我需要一个输入 DialogBox,它有许多文本字段,可以从每个字符串中获取输入并将其存储在一个数组中。

What I have done so far:

到目前为止我做了什么:

alt text

替代文字



CODE

代码

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

public class second extends JFrame implements ActionListener {

JLabel enterName;
JTextField name;
JButton click;
String storeName;

public second() {

    setLayout(null);
    setSize(300, 250);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    click = new JButton("Click");
    click.setBounds(100, 190, 60, 30);
    click.addActionListener(this);
    add(click);
}

public void actionPerformed(ActionEvent e) {

    if (e.getSource() == click) {
    String response = JOptionPane.showInputDialog(null,
                "What is your name?",
                "Enter your name",
                JOptionPane.QUESTION_MESSAGE);
    }
    }

    public static void main(String args[]) {

    second s = new second();
    s.setVisible(true);
}
}


Many Thanks

非常感谢

回答by BlueBird

Use a JDialog Form.

使用 JDialog 窗体。

You can use more than one input fields in it.

您可以在其中使用多个输入字段。

You can see examples in this link.

您可以在此链接中查看示例。

回答by Mikhail

All you have to do is:

您所要做的就是:

String response = JOptionPane.showInputDialog
(null,"<html>Whats your name?"+ "<br>Enter your name:",JOptionPane.QUESTION_MESSAGE);

The br stands for brake or brake line(basically hitting enter key) I cant enter the <> cause it brakes the line in comments.

br 代表刹车或刹车线(基本上是按回车键)我无法输入 <> 因为它会在评论中刹车。