Note that there are some explanatory texts on larger screens.

plurals
  1. POJava: How can I detect the user has finalised their save name without using an actionListener?
    primarykey
    data
    text
    <p>Basically I wan't to obtain a string from the user, I have created a class called "frames" in which I have a load of methods such as exitChoice(), infoPop(), ect... I wish to create one called getText(), and this is what I have so far:</p> <pre><code> public String getText() { JDialog textBox = new JDialog(frame, "Save Name", true); JTextField inputField = new JTextField(18); inputField.setText(save == null ? "new save" : save.saveName); textBox.setBounds(width, height, 275, 70); textBox.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); textBox.setLayout(new FlowLayout()); textBox.setAlwaysOnTop(true); textBox.setResizable(false); textBox.add(inputField); textBox.setVisible(true); return inputField.getText(); } </code></pre> <p>now I know this won't work, It simply gets the game stuck and I have to terminate it externally, I also understand why it doesn't work, that isn't the problem, I also know how to add a JButton, an action listener and work it from there,</p> <p>Basically I am trying to create a clean simple method which obtains a String from the user which is ALL contained within the method.</p> <p>Ideally I would like to write a line which reads along the lines of</p> <p>//EDIT: I know the method getText() does exist, sorry if it is misleading, I will ammend it</p> <pre><code>//String saveName = new JTextField.getText(); String saveName = new JTextInputGetterBoxThing(); </code></pre> <p>but as far as I have found so far this doesn't appear to exist, does anybody have any ideas? or ideally know of a one liner that I have missed?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload