import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
class menuc extends JFrame implements ActionListener
{
public static JTextField content;
public menuc()
{
setTitle("文件操作");
Container con = this.getContentPane();
con.setLayout(new BorderLayout());
this.setLocation(100,100);
this.setSize(500,600);
JMenu file , edit , help;
JMenuItem open,exit,copy,past,find,version,about,update;
file = new JMenu("文件"); edit = new JMenu("编辑"); help = new JMenu("帮助");
open = new JMenuItem("打开"); exit= new JMenuItem("离开"); copy= new JMenuItem("复制");
past = new JMenuItem("粘贴"); find = new JMenuItem("查找");
version = new JMenuItem("版本信息");update = new JMenuItem("更新"); about=new JMenuItem("关于我们");
content = new JTextField();
file.add(open); file.add(exit);
edit.add(copy); edit.add(past); edit.add(find);
help.add(version);
version.add(update); version.add(about);
open.addActionListener(this);
exit.addActionListener(this);
copy.addActionListener(this);
past.addActionListener(this);
find.addActionListener(this);
update.addActionListener(this);
about.addActionListener(this);
JMenuBar menubar = new JMenuBar();
content =new JTextField();
menubar.add(file); menubar.add(edit); menubar.add(help);
setJMenuBar(menubar);
con.add(content,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e)
{
content.setText(e.getActionCommand() + "被选中");
}
}public class menu extends Applet
{
menuc mymenu;
public void init()
{
mymenu = new menuc();
}
}
import javax.swing.*;
import java.awt.event.*;
import java.applet.*;
class menuc extends JFrame implements ActionListener
{
public static JTextField content;
public menuc()
{
setTitle("文件操作");
Container con = this.getContentPane();
con.setLayout(new BorderLayout());
this.setLocation(100,100);
this.setSize(500,600);
JMenu file , edit , help;
JMenuItem open,exit,copy,past,find,version,about,update;
file = new JMenu("文件"); edit = new JMenu("编辑"); help = new JMenu("帮助");
open = new JMenuItem("打开"); exit= new JMenuItem("离开"); copy= new JMenuItem("复制");
past = new JMenuItem("粘贴"); find = new JMenuItem("查找");
version = new JMenuItem("版本信息");update = new JMenuItem("更新"); about=new JMenuItem("关于我们");
content = new JTextField();
file.add(open); file.add(exit);
edit.add(copy); edit.add(past); edit.add(find);
help.add(version);
version.add(update); version.add(about);
open.addActionListener(this);
exit.addActionListener(this);
copy.addActionListener(this);
past.addActionListener(this);
find.addActionListener(this);
update.addActionListener(this);
about.addActionListener(this);
JMenuBar menubar = new JMenuBar();
content =new JTextField();
menubar.add(file); menubar.add(edit); menubar.add(help);
setJMenuBar(menubar);
con.add(content,BorderLayout.NORTH);
}
public void actionPerformed(ActionEvent e)
{
content.setText(e.getActionCommand() + "被选中");
}
}public class menu extends Applet
{
menuc mymenu;
public void init()
{
mymenu = new menuc();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货