For some awkward reason whenever I set my desired frame to Visible(true) inside of my actionPerformed() it prints out the frame, with the title but no components and no colours that I have previous selected.
However, when setting the visibility to true in the top of my current frame(Without having to press the button) it working fine.
This is the frame I'm using:
But this is being printed once I set visibility to true inside the actionPerformed:
I have already got another frame(The main client frame) being set to true inside the actionPerformed() and it works fine. This is the first time this issue happened to me so I'm really not sure what's causing it.
I also assumed that it may be due to the fact that during the actionPerformed the client has to connect to the particular server details but then again, the Frame object is being instantiated as soon as the first frame is instantiated so it should be just fine..
Here is my actionPerformed(), sorry for messy code:
JButton connectButton = new JButton("Connect");
connectButton.setBackground(SystemColor.activeCaption);
connectButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
//If any of the first three fields are empty, turn them red
if(serverField.getText().equalsIgnoreCase("")){
lblSever.setForeground(new Color(240, 128, 128));
}
if(channelField.getText().equalsIgnoreCase("")){
lblChannel.setForeground(new Color(240, 128, 128));
}
if(nicknameField.getText().equalsIgnoreCase("")){
lblNickname.setForeground(new Color(240, 128, 128));
}
//Set Waiting Connection frame to true
wc.setVisible(true);
//None of the first three fields are empty
if(!serverField.getText().equalsIgnoreCase("")
&& !channelField.getText().equalsIgnoreCase("")
&& !nicknameField.getText().equalsIgnoreCase("")){
//Set current frame visibility to false
setVisible(false);
//Set connection details
Main.bot.setServer(serverField.getText());
Main.bot.setChannel(channelField.getText());
Main.bot.setNickname(nicknameField.getText());
Main.bot.setPassword(formattedTextField.getText());
//Connect to server and channel
try{
Main.bot.connect(serverField.getText());
Main.bot.changeNick(nicknameField.getText());
Main.bot.joinChannel(channelField.getText());
}catch(Exception e){ //Catch all errors, if invalid server is thrown, close Waiting Connection frame
InvalidServer error = new InvalidServer();
e.printStackTrace();
wc.setVisible(false);
wc.dispose();
error.setVisible(true);
}
setVisible(false);
//Custom Timer class
Timer runTime = new Timer();
while(runTime.getTimeElapsed() < 5000){
//To-Do
}
wc.setVisible(false);
//Instantiate next frame
MainFrame mainFrame = new MainFrame();
mainFrame.setVisible(true);
//Kill current frame
dispose();
}
}
});