可以啊!
简单测试:
package test;
import java.awt.FlowLayout;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
public class test1 extends JFrame
{
public test1()
{
this.setLayout(new FlowLayout());
this.setBounds(200, 100, 400, 300);
ImageIcon icon=new ImageIcon("p1.jpg");
Image image=icon.getImage();
ImageIcon icon2=new ImageIcon("d.jpg");
Image image2=icon2.getImage();
ImageIcon icon3=new ImageIcon("ex.png");
Image image3=icon3.getImage();
JMenuBar jb=new JMenuBar();
JMenu menu=new JMenu("system");
menu.setIcon(icon);
menu.setText("menu1");
JMenu menu2=new JMenu("system");
menu2.setIcon(icon2);
menu2.setText("menu2");
JMenuItem item=new JMenuItem("exit");
item.setIcon(icon3);
menu.add(item);
jb.add(menu);
jb.add(menu2);
this.add(jb);
this.setVisible(true);
}
public static void main(String[] args)
{
new test1();
}
}
|
|