Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class NextPageListener implements ActionListener
{
private NextPage nextPage;
public NextPageListener (NextPage nextPage)
{
this.nextPage = nextPage;
}
public void actionPerformed (ActionEvent e)
{
String cmd = e.getActionCommand ();
if (cmd.equals ("next page"))
{
nextPage.nextPage ();
}
}
}
public class NextPage extends JFrame
{
private JButton jb;
private JPanel mainpanel;
public NextPage ()
{
mainpanel = new JPanel ();
mainpanel.setLayout (new BorderLayout ());
this.getContentPane ().add (mainpanel);
jb = new JButton ("next page");
jb.addActionListener (new NextPageListener (this));
JTextField jtext = new JTextField ("first Page");
JPanel page1 = new JPanel ();
page1.add (jtext);
mainpanel.add (jb, BorderLayout.SOUTH);
mainpanel.add (page1, BorderLayout.CENTER);
setSize (400, 400);
setLocation (300, 300);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
}
public static void main (String args[])
{
new NextPage ();
}
public void nextPage ()
{
JPanel page2 = new JPanel ();
JLabel jlabel = new JLabel ("page 2");
page2.add (jlabel);
mainpanel.removeAll ();
mainpanel.add (page2, BorderLayout.CENTER);
mainpanel.updateUI ();
}
}