I use JDialog
as input for string
I am trying to But before clicking the text I received, I am clicking on the button.
This is my dialog:
public class AddMemberDialog JDialog {Private JTextField name; Public AddMemberDialog () {Super (New JFrame ("Add Member"), "Add Member"); This.setDefaultCloseOperation (JDialog.HIDE_ON_CLOSE); This.setMinimumSize (new dimension (500, 500)); This.name = new JTextField (); Add pocket button = new pocket ("add"); Add.addActionListener (new executable () {public zero action executed {closed}}}}; This.setLayout (new grid layout (2, 1, 5, 5)); This.add (name); This.add (add); This.pack (); } Private Zero Closing () {this.dispose (); } Public string getName () {this.name.getText () return); }}
and here I am using to get to string
:
AddMemberDialog input = new AddMemberDialog (); Input.setLocationRelativeTo (this); Input.setVisible (true); String txt = input.getName ();
import javax.swing.JDialog; Import javax.swing.JTextField; Import javax.swing.JButton; Import javax.swing.JFrame; Import java.awt.Dimension; Import java.awt.event.ActionListener; Import java.awt.event.ActionEvent; Import java.awt.GridLayout; Public Class AddMemberDialog JDialog {Private JTextField Extensions; Public static zero main (string [] args) {AddMemberDialog input = new AddMemberDialog (); Input.setLocationRelativeTo (zero); Input.setVisible (true); } Public AddMemberDialog () {Super (New JFrame ("Add Member"), "Add Member"); This.setDefaultCloseOperation (JDialog.HIDE_ON_CLOSE); This.setMinimumSize (new dimension (500, 500)); This.name = new JTextField (); Add pocket button = new pocket ("add"); Add.addActionListener (new executable () {public zero action executed {closed}}}}; Pocket button leinput = new pocket ("leinput"); TakeInput.addActionListener (new executable () {public zero action action (action event e) {string txt = getName (); system.out.println (txt);}}); This.setLayout (new grid layout (3, 1, 5, 5)); This.add (name); This.add (add); This.add (takeInput); This.pack (); } Private Zero Closing () {this.dispose (); } Public string getName () {this.name.getText () return); }}
OK, so basically, here's your problem, if you just leave the code
AddMemberDialog input = new AddMemberDialog () ; Input.setLocationRelativeTo (this); Input.setVisible (true); String txt = input.getName ();
This will take you to your input automatically, the second IDE reaches that line of code. That is, unless you put something in the IDE before there (and meet in the IDE), then there will no longer be any input, so to compensate, we do not input the program unless That we are not good and ready, so a button is required. In my above code, I made a new pocketton
and called it takeInput
. Along with this, it gave a activator
and in that ActionListener
, it did for the work you did. Now, when I have input, I can control it.
Comments
Post a Comment