Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

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

like image 980
Haxed Avatar asked Jul 03 '10 05:07

Haxed


2 Answers

Use a JDialog Form.

You can use more than one input fields in it.

You can see examples in this link.

like image 86
BlueBird Avatar answered Oct 13 '22 00:10

BlueBird


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.

like image 26
Mikhail Avatar answered Oct 13 '22 00:10

Mikhail