java 记事本的菜单条部分代码,请指教。。。。。。
importjava.awt.*;importjava.awt.event.*;publicclassNoteBookMenuextendsMenuBarimplemen...
import java.awt.*;
import java.awt.event.*;
public class NoteBookMenu extends MenuBar implements ActionListener
{
public TextArea ta;
public Frame fm;
public NoteBookMenu()
{
super();
}
public NoteBookMenu(Frame fm,TextArea ta)
{
super();
this.fm=fm;
this.ta=ta;
fm.setMenuBar(this);
fm.add(ta);
}
public void setmenu(String menus[])
{
for(int i=0;i<menus.length;i++)
{
this.add(new Menu(menus[i]));
}
}
public void setmenuitem(String menuitems[][])
{
for(int i=0;i<menuitems.length;i++)
for(int j=0;j<menuitems[i].length;j++)
{
if(menuitems[i][j]!="")
this.getMenu(i).add(menuitems[i][j]);
else
this.getMenu(i).addSeparator();
}
}
public void addActionListeners(ActionListener actionl[][])
{
for(int i=0;i<this.getMenuCount();i++)
{
for(int j=0;j<this.getMenu(i).getItemCount();j++)
this.getMenu(i).getItem(j).addActionListener(actionl[i][j]);
}
}
public void actionPerformed(ActionEvent e)
{
ta.setText(ta.getText()+"你好");
}
public static void main(String args[])
{
String[] menus=new String[]{"菜单","编辑","查找","帮助"};
String[][] menuitems=new String[][]{{"打开","保存","","退出"},{"剪切","复 制","粘贴"},{"查找","查找替换"},{"帮帮你"}};
ActionListener[][] al=new ActionListener[4][4];
for(int i=0;i<menus.length;i++)
for(int j=0;j<menuitems[i].length;j++)
al[i][j]=new NoteBookMenu();
Frame fm=new Frame();
TextArea ta=new TextArea(30,70);
NoteBookMenu nb=new NoteBookMenu(fm,ta);
fm.pack();
nb.setmenu(menus);
nb.setmenuitem(menuitems);
nb.addActionListeners(al);
fm.setVisible(true);
}
} 展开
import java.awt.event.*;
public class NoteBookMenu extends MenuBar implements ActionListener
{
public TextArea ta;
public Frame fm;
public NoteBookMenu()
{
super();
}
public NoteBookMenu(Frame fm,TextArea ta)
{
super();
this.fm=fm;
this.ta=ta;
fm.setMenuBar(this);
fm.add(ta);
}
public void setmenu(String menus[])
{
for(int i=0;i<menus.length;i++)
{
this.add(new Menu(menus[i]));
}
}
public void setmenuitem(String menuitems[][])
{
for(int i=0;i<menuitems.length;i++)
for(int j=0;j<menuitems[i].length;j++)
{
if(menuitems[i][j]!="")
this.getMenu(i).add(menuitems[i][j]);
else
this.getMenu(i).addSeparator();
}
}
public void addActionListeners(ActionListener actionl[][])
{
for(int i=0;i<this.getMenuCount();i++)
{
for(int j=0;j<this.getMenu(i).getItemCount();j++)
this.getMenu(i).getItem(j).addActionListener(actionl[i][j]);
}
}
public void actionPerformed(ActionEvent e)
{
ta.setText(ta.getText()+"你好");
}
public static void main(String args[])
{
String[] menus=new String[]{"菜单","编辑","查找","帮助"};
String[][] menuitems=new String[][]{{"打开","保存","","退出"},{"剪切","复 制","粘贴"},{"查找","查找替换"},{"帮帮你"}};
ActionListener[][] al=new ActionListener[4][4];
for(int i=0;i<menus.length;i++)
for(int j=0;j<menuitems[i].length;j++)
al[i][j]=new NoteBookMenu();
Frame fm=new Frame();
TextArea ta=new TextArea(30,70);
NoteBookMenu nb=new NoteBookMenu(fm,ta);
fm.pack();
nb.setmenu(menus);
nb.setmenuitem(menuitems);
nb.addActionListeners(al);
fm.setVisible(true);
}
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询