I have a dialog for the client GUI that asks for the IP address and port of the server you want to connect to. I have everything else, but how can I make it so that when the user clicks βOKβ in my dialog box, that he starts something? Here is what I still have:
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JDialog; import javax.swing.JOptionPane; import javax.swing.JTextField; public class ClientDialog { JTextField ip = new JTextField(20); JTextField port = new JTextField(20); GUI gui = new GUI(); Client client = new Client(); JOptionPane optionPane; public void CreateDialog(){ Object msg[] = {"IP: ", ip, "\nPort: ", port}; optionPane = new JOptionPane(); optionPane.setMessage(msg); optionPane.setMessageType(JOptionPane.INFORMATION_MESSAGE); JDialog dialog = optionPane.createDialog(null, "Connect to a server"); dialog.setVisible(true); if(dialog == JOptionPane.OK_OPTION){ System.out.println(ip); String ipMsg = ip.getText(); int portMsg = Integer.parseInt(port.getText()); gui.CreateConsole(client, ipMsg, portMsg); } } }
I know that the code is incorrect, but I want that when the user types βOKβ in the dialog box, I can run some code. Thanks!
user569322
source share