Name of Student: Ekambe Ganesh Roll No.
: 53
Experiment No.: 05 DOS:
Program code
1.
import [Link].*;
import [Link].*;
public class Pr5Ex extends Frame implements ActionListener {
private MenuBar menuBar;
private Menu colorMenu;
private MenuItem redItem, greenItem, blueItem, blackItem;
public Pr5Ex() {
initUI();
}
private void initUI() {
setTitle("Color Menu Example");
setSize(400, 300);
setLayout(new BorderLayout());
menuBar = new MenuBar();
colorMenu = new Menu("Colors");
redItem = new MenuItem("Red");
greenItem = new MenuItem("Green");
blueItem = new MenuItem("Blue");
blackItem = new MenuItem("Black");
[Link](this);
[Link](this);
[Link](this);
[Link](this);
[Link](redItem);
[Link](greenItem);
[Link](blueItem);
[Link]();
[Link](blackItem);
[Link](false);
[Link](colorMenu);
setMenuBar(menuBar);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
[Link](0);
}
Name of Student: Ekambe Ganesh Roll No.: 53
Experiment No.: 05 DOS:
});
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
String command = [Link]();
if ([Link]("Red")) {
setBackground([Link]);
} else if ([Link]("Green")) {
setBackground([Link]);
} else if ([Link]("Blue")) {
setBackground([Link]);
}
}
public static void main(String[] args) {
new Pr5Ex();
}
}
Output
Name of Student: Ekambe Ganesh Roll No.: 53
Experiment No.: 05 DOS:
Name of Student: Ekambe Ganesh Roll No.: 53
Experiment No.: 05 DOS:
Exercise
1.
import [Link].*;
import [Link].*;
public class Pr5e extends Frame {
MenuBar mb;
MenuItem m1, m2, m3, m4;
Menu mn;
MenuShortcut ms;
Pr5e() {
setTitle("MenuBar Demo");
setSize(500, 500);
setLayout(null);
ms = new MenuShortcut(KeyEvent.VK_X);
mn = new Menu("File");
mb = new MenuBar();
m1 = new MenuItem("New...");
m2 = new MenuItem("Open...");
m3 = new MenuItem("Save As...");
m4 = new MenuItem("Exit", ms);
[Link](m1);
[Link](m2);
[Link](m3);
[Link]();
[Link](m4);
[Link](mn);
setMenuBar(mb);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
[Link](0);
}
});
}
public static void main(String[] args) {
Pr5e md = new Pr5e();
[Link](true);
}
}
Name of Student: Ekambe Ganesh Roll No.: 53
Experiment No.: 05 DOS:
Output