Hey guys so I am able to set the default frame for my popup window that is called from a separate class. As you can probably tell I am an extreme noob to java. Any help would be appreciated.
This is the code that calls the second class to run.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.NumberFormat;
class Login extends JFrame implements ActionListener
{
JButton SUBMIT;
JPanel panel;
JLabel label1,label2;
final JTextField text1,text2;
Login()
{
label1 = new JLabel();
label1.setText(" Enter Username:");
label1.setForeground(Color.green);
text1 = new JTextField(10);
label2 = new JLabel();
label2.setText(" Enter Password:");
label2.setForeground(Color.green);
text2 = new JPasswordField(10);
SUBMIT=new JButton("SUBMIT");
SUBMIT.setOpaque(true);
SUBMIT.setBackground(Color.BLACK);
SUBMIT.setForeground(Color.green);
panel=new JPanel(new GridLayout(4,1));
panel.add(label1);
panel.add(text1);
panel.add(label2);
panel.add(text2);
panel.add(SUBMIT);
add(panel,BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("LOGIN or DIE!!!!!");
panel.setBackground(Color.black);
setDefaultLookAndFeelDecorated(true);
setLocationRelativeTo(null);
}
public void actionPerformed(ActionEvent ae)
{
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("McDinger") && value2.equals("welcome1")) {
ExerciseSevenPt2 page=new ExerciseSevenPt2();
page.setVisible(true);
JLabel label = new JLabel(" Welcome to The Java Cave, "+value1 + ". " + "Are you Worthy of the Cave?");
label.setOpaque(true);
label.setForeground(Color.green);
label.setBackground(Color.black);
page.getContentPane().add(label);
}
else{
System.out.println("enter the valid username and password OR ELSE!!!!!");
UIManager UI=new UIManager();
UI.put("OptionPane.messageForeground", Color.red);
UI.put("OptionPane.background", Color.black);
UI.put("Panel.background", Color.black);
JOptionPane.showMessageDialog(this,"Incorrect login or password Genius", "Error",JOptionPane.ERROR_MESSAGE);
setDefaultLookAndFeelDecorated(true);
}
}
}
class ExerciseSeven
{
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(300,100);
frame.setVisible(true);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}
}
And here is the second Class
import javax.swing.*;
import java.awt.*;
class ExerciseSevenPt2 extends JFrame
{
ExerciseSevenPt2()
{
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
setTitle("The Java Cave ");
setSize(400,70);
setLocationRelativeTo(null);
}
}
And here is my issue visually after executing the code. The bottom window is what I want the top one to look like.