Anyways i have yet to figure this out but i’m trying to make a GUI that’ll allow login and such.
Anyways here is methods
private void initialize() {
frame = new JFrame();
container = frame.getContentPane();
container.setLayout(new FlowLayout());
idLabel = new JLabel("Id:");
id = new JTextField("", 12);
passwordLabel = new JLabel("Password:");
password = new JPasswordField(8);
password.setEchoChar('*');
button2 = new JButton("Log in");
container.add(idLabel);
container.add(id);
container.add(passwordLabel);
container.add(password);
container.add(button2);
//container.add(legal, BorderLayout.CENTER);
frame.setSize( 250,200 );
frame.setVisible( true );
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
button2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent ae) {
if (ae.getSource() == button
&& id.getText().equals("1")
&& (new String(password.getPassword()))
.equals("2"))
container.remove(idLabel);
container.remove(id);
container.remove(passwordLabel);
container.remove(password);
container.remove(button2);
secondScreen();
frame.setSize(300, 300);
}
});
}
public void secondScreen() {
//frame = new JFrame();
//container.add(text);
//layout = new FlowLayout();
container.remove(idLabel);
container.remove(id);
container.remove(passwordLabel);
container.remove(password);
container.remove(button2);
frame.setSize(300, 300);
frame.setTitle("second screen");
container = frame.getContentPane();
JContentPane = new JPanel();
JContentPane.setLayout(new BorderLayout());
frame.setResizable(false);
frame.pack();
area = new JTextArea();
area.setEditable(false);
text = new JTextField("testing");
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
frame.setVisible(true);
button = new JButton("testing");
button4 = new JButton("testing");
button3 = new JButton("testing");
container.add(button, BorderLayout.SOUTH);
container.add(button3, BorderLayout.EAST);
container.add(button4, BorderLayout.WEST);
container.add(area, BorderLayout.SOUTH);
button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent ae) {
if ( ae.getSource( ) == button )
sendMessage("Opening webpage.");
openWebpage();
}
});
}
yes, it’s really “nooby” as i’m still learning but what i want to do is once you hit the button “login” it’ll close that JFrame and secondScreen(); will open a new one with a different layout, or can someone tell me how to make it switch from a FlowLayout to a BorderLayout without causing any nullpointerexceptions.
None of my books have anything related to my problem and i don’t know what to do exactly. Help is VERY appreciated.