packagefirstmenu;importjava.awt.Graphics;importjava.awt.MenuItem;importjavax.swing.JFrame;importjavax.swing.JMenu;importjavax.swing.JMenuBar;importjavax.swing.JMenuItem;i...
package firstmenu;
import java.awt.Graphics;
import java.awt.MenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
public class Menu extends JFrame{
public void Menu(){
JFrame f=new JFrame("菜单组件");
JMenuBar bar =new JMenuBar();
JMenuItem j1=new JMenuItem("Open");
JMenuItem j2=new JMenuItem("Save");
JMenuItem j3=new JMenuItem("Save as Template");
JMenu m1 = new JMenu("File");
mypanel mp=new mypanel();
f.add(bar);
this.setJMenuBar(bar);
bar.add(m1);
m1.add(j1);
m1.add(j2);
m1.add(j3);
this.setSize(800,600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.pack();
f.setVisible(true);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
new Menu();
}
}
class mypanel extends JPanel
{
public void paint(Graphics g)
{
super.paint(g);
}
}

展开