Hi, so I want to make this kind of "webpage" thing with GUI and how can go to another "page" not open another frame when I click on one of the buttons. Like in my program one of the buttons are "Sign In" and when the user clicks it I want it to go to another page, and the user can also go "back" to the previous page. How do I do that?
As you can also see from my program right now, there are buttons but the buttons doesn't go/do anything when it is clicked.
Thanks.
as you can also see from my program right now,
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class firstPage implements ActionListener {
JFrame frame;
JPanel contentPane;
JLabel label;
JButton button;
JTextField name;
JLabel welcome;
public firstPage(){
/* Create and set up the frame */
frame = new JFrame("Sign In page");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
/* Creates and set up the size and colour of the frame */
contentPane = new JPanel();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
contentPane.setBorder(BorderFactory.createEmptyBorder(50, 50, 50, 50));
contentPane.setBackground(Color.black);
/* creates a button in the center */
button = new JButton("Enter");
button.setAlignmentX(JButton.CENTER_ALIGNMENT);
button.setActionCommand("Enter");
button.addActionListener(this);
contentPane.add(button);
button = new JButton("Sign In");
button.setAlignmentX(JButton.CENTER_ALIGNMENT);
button.setActionCommand("Sign In");
button.addActionListener(this);
contentPane.add(button);
button = new JButton("Sign Up");
button.setAlignmentX(JButton.CENTER_ALIGNMENT);
button.setActionCommand("Sign Up");
button.addActionListener(this);
contentPane.add(button);
/* Creates a button for exit */
button = new JButton("Exit");
button.setAlignmentX(JButton.CENTER_ALIGNMENT);
button.setActionCommand("Exit");
button.addActionListener(this);
contentPane.add(button);
frame.setContentPane(contentPane);
frame.pack();
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event) {
String eventName = event.getActionCommand();
if (eventName.equals("Enter")) {;
} else {
button.setActionCommand("Enter");
}
}
private static void runGUI() {
JFrame.setDefaultLookAndFeelDecorated(true);
firstPage greeting = new firstPage();
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
runGUI();
}
});
}
}