如何创建一个具有多个文本字段的输入对话框(即可以输入多个输入)

时间:2021-03-16 17:04:12

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

嘿那里,我已经实现了一个输入DialogBox,但是它有一个文本字段。我需要一个输入DialogBox,它有许多文本字段来接收输入并将每个String存储在一个数组中。

What I have done so far:

到目前为止我做了什么:

alt text http://i47.tinypic.com/141kwes.jpg

alt text http://i47.tinypic.com/141kwes.jpg


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

非常感谢

2 个解决方案

#1


2  

Use a JDialog Form.

使用JDialog表单。

You can use more than one input fields in it.

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

You can see examples in this link.

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

#2


1  

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表示制动或制动线(基本上是按下输入键)我不能进入<>因为它在评论中刹车。

#1


2  

Use a JDialog Form.

使用JDialog表单。

You can use more than one input fields in it.

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

You can see examples in this link.

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

#2


1  

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表示制动或制动线(基本上是按下输入键)我不能进入<>因为它在评论中刹车。