So i have a simple java GUI that has two editable text fields.
If i enter the first one, it will pop up a dialog that shows the first field.
##########################################
# Message x #
##########################################
# Your textfields #
# 1: this is an editable field #
# #
##########################################
If i enter, it will pop up a dialog that shows the second field.
##########################################
# Message x #
##########################################
# Your textfields #
# 2: this is an editable field 2 #
# #
##########################################
However, is it possible to pop up a dialog box that shows both fields at the same time?
##########################################
# Message x #
##########################################
# Your textfields #
# 1: this is an editable field #
# 2: this is an editable field 2 #
##########################################
This is what I've done so far:
My textFrames:
class EditTextFrame extends JFrame
{
private JTextField editableField1;
private JTextField editableField2;
public EditTextFrame()
{
setLayout(new FlowLayout());
editableField1 = new JTextField("This is an editable field", 25);
editableField2 = new JTextField("This is an editable field2", 25);
add(editableField1);
add(editableField2);
TextFieldHandler handler = new TextFieldHandler();
editableField1.addActionListener(handler);
editableField2.addActionListener(handler);
}
My ActionEvents:
private class TextFieldHandler implements ActionListener
{
@Override
public void actionPerformed(ActionEvent e)
{
String string1 = "";
String string2 = "";
if (e.getSource() == editableField1)
string1 = String.format("1: %s",
e.getActionCommand());
if (e.getSource() == editableField2)
string2 = String.format("2: %s",
e.getActionCommand());
JOptionPane.showMessageDialog(null, "Your textfields \n" + string1 + string2
);
}
}
I know that my string concat is useless as one of them will be empty since the if statement stops after a condition is met.. but i cant seem to find a way to work around..