标签:main nic bar 菜单 editable ack tab 不能 alt
package shisanzhou;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.KeyStroke;
public class text {
public static void main(String[] args) {
JFrame frame=new JFrame("Welcome To MLDN");
JTextArea text=new JTextArea();
text.setEditable(true);
frame.getContentPane().add(new JScrollPane(text));
JMenu menuFile=new JMenu("文件");
menuFile.setIcon(new ImageIcon("d:"+File.separator+"icons"+File.separator+"file.gif"));
JMenuBar menuBar=new JMenuBar();
JMenuItem newItem=new JMenuItem("新建",new ImageIcon("d:"+File.separator+"icons"+File.separator+"new.gif"));
JMenuItem openItem=new JMenuItem("打开",new ImageIcon("d:"+File.separator+"icons"+File.separator+"open.gif"));
JMenuItem closeItem=new JMenuItem("关闭",new ImageIcon("d:"+File.separator+"icons"+File.separator+"close.gif"));
JMenuItem exitItem=new JMenuItem("退出",new ImageIcon("d:"+File.separator+"icons"+File.separator+"exit.gif"));
newItem.setMnemonic('N');
openItem.setMnemonic('O');
closeItem.setMnemonic('C');
exitItem.setMnemonic('E');
newItem.setAccelerator(KeyStroke.getKeyStroke('N',java.awt.Event.CTRL_MASK));
openItem.setAccelerator(KeyStroke.getKeyStroke('O',java.awt.Event.CTRL_MASK));
closeItem.setAccelerator(KeyStroke.getKeyStroke('C',java.awt.Event.ALT_MASK));
exitItem.setAccelerator(KeyStroke.getKeyStroke('E',java.awt.Event.ALT_MASK));
menuFile.add(newItem);
menuFile.add(openItem);
menuFile.add(closeItem);
menuFile.addSeparator();
menuFile.add(exitItem);
menuBar.add(menuFile);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent arg0) {
System.exit(1);
}});
frame.setJMenuBar(menuBar);
frame.setVisible(true);
frame.setSize(300,180);
frame.setLocation(300, 200);
}
}
最近上课速度有些快,学习内容也比较多,还不能熟练的运用,需要多加的练习。慢慢来不能太心急
标签:main nic bar 菜单 editable ack tab 不能 alt
原文地址:https://www.cnblogs.com/ZhangGuang29/p/11914612.html