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 java.awt.*;
import java.awt.event.*;
public class TheMenu extends Frame
{
public TheMenu()
{
super("Main window, select below...");
setSize(300, 80);
setResizable(false);
FileMenu fileMenu = new FileMenu(this);
MenuBar mb = new MenuBar();
mb.add(fileMenu);
setMenuBar(mb);
[b] addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e) {
exit();
}
});
}
public void exit()
{
System.out.println("Application is exiting.");
setVisible(false);
dispose();
System.exit(0);
}[/b]
public static void main(String [] args)
{
TheMenu w = new TheMenu();
w.setVisible(true);
}
}
class FileMenu extends Menu implements ActionListener {
TheMenu mw;
public FileMenu(TheMenu m)
{
super("File");
mw = m;
MenuItem mi;
add(mi = new MenuItem("New entry"));
mi.addActionListener(this);
add(mi = new MenuItem("Find"));
mi.addActionListener(this);
addSeparator();
[b]add(mi = new MenuItem("Exit"));
mi.addActionListener(this); [/b]
}
[b]public void actionPerformed(ActionEvent e)
{
String item = e.getActionCommand();
System.out.println("You have selected: " + item);
[/b]
if (item.equals("New entry"))
{
CardLayoutManager c1=new CardLayoutManager();
c1.setVisible(true);
c1.pack();
c1.show();
}
else if (item.equals("Find"))
{
FindForm c2=new FindForm();
c2.setVisible(true);
c2.pack();
c2.show();
}
[b]else // Hit Exit //
{
mw.exit();
} [/b]
}
}