?? ch9_52.java
字號:
import javax.swing.*;
import java.awt.event.*;
public class ch9_52 extends JFrame
{
public ch9_52()
{
super("菜單演示");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(20,20,500,300);
}
public static void main(String [] args)
{
ch9_52 f=new ch9_52();
JMenuBar mbar=new JMenuBar();
JMenu mfile=f.buildFileMenu();
mbar.add(mfile);
mbar.setOpaque(true);
f.setJMenuBar(mbar);
f.setVisible(true);
}
public JMenu buildFileMenu()
{
JMenu theedit=new JMenu("文件");
theedit.setIcon(new ImageIcon("cut.gif"));
JCheckBoxMenuItem newf=new JCheckBoxMenuItem("新建(N)",new ImageIcon("new.gif"),false);
//添加事件處理
newf.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.out.print("fasdf");
}
});
theedit.add(newf);
return theedit;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -