当前位置: 技术问答>java相关
JAVA初学者,在JDK中怎样写菜单事件?
来源: 互联网 发布时间:2015-11-03
本文导语: 我已经编写完了记事本的外观,菜单也挂上去了,但是怎样才能把需要的事件写上去那 ?请大家帮忙! | 这是一个菜单例子程序。你可以看看。 Menu1.java import java.awt.*; public class Menu1 extends Fram...
我已经编写完了记事本的外观,菜单也挂上去了,但是怎样才能把需要的事件写上去那 ?请大家帮忙!
|
这是一个菜单例子程序。你可以看看。
Menu1.java
import java.awt.*;
public class Menu1 extends Frame {
String[] flavors = { "Chocolate", "Strawberry",
"Vanilla Fudge Swirl", "Mint Chip",
"Mocha Almond Fudge", "Rum Raisin",
"Praline Cream", "Mud Pie" };
TextField t = new TextField("No flavor", 30);
MenuBar mb1 = new MenuBar();
Menu f = new Menu("File");
Menu m = new Menu("Flavors");
Menu s = new Menu("Safety");
// Alternative approach:
CheckboxMenuItem[] safety = {
new CheckboxMenuItem("Guard"),
new CheckboxMenuItem("Hide")
};
MenuItem[] file = {
new MenuItem("Open"),
new MenuItem("Exit")
};
// A second menu bar to swap to:
MenuBar mb2 = new MenuBar();
Menu fooBar = new Menu("fooBar");
MenuItem[] other = {
new MenuItem("Foo"),
new MenuItem("Bar"),
new MenuItem("Baz"),
};
Button b = new Button("Swap Menus");
public Menu1() {
for(int i = 0; i
Menu1.java
import java.awt.*;
public class Menu1 extends Frame {
String[] flavors = { "Chocolate", "Strawberry",
"Vanilla Fudge Swirl", "Mint Chip",
"Mocha Almond Fudge", "Rum Raisin",
"Praline Cream", "Mud Pie" };
TextField t = new TextField("No flavor", 30);
MenuBar mb1 = new MenuBar();
Menu f = new Menu("File");
Menu m = new Menu("Flavors");
Menu s = new Menu("Safety");
// Alternative approach:
CheckboxMenuItem[] safety = {
new CheckboxMenuItem("Guard"),
new CheckboxMenuItem("Hide")
};
MenuItem[] file = {
new MenuItem("Open"),
new MenuItem("Exit")
};
// A second menu bar to swap to:
MenuBar mb2 = new MenuBar();
Menu fooBar = new Menu("fooBar");
MenuItem[] other = {
new MenuItem("Foo"),
new MenuItem("Bar"),
new MenuItem("Baz"),
};
Button b = new Button("Swap Menus");
public Menu1() {
for(int i = 0; i