menuItem1[2].addActionListener (this);
menuItem1[3].addActionListener (this);
setJMenuBar (menuBar);
textArea = new JTextArea ();
scrollPane = new JScrollPane (textArea);
scrollPane.setVisible (false);
add (scrollPane, BorderLayout.CENTER);
setResizable (false);
setSize (800, 600);
setLocationRelativeTo (null);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
}
public static void main ( String[] args )
{
SwingUtilities.invokeLater (new Runnable ()
{
@Override
public void run ()
{
new MenuTester ();
}
});
}
@Override
public void actionPerformed ( ActionEvent e )
{
String command = e.getActionCommand ();
if ("新建".equals (command))
{
scrollPane.setVisible (true);
validate ();
}
else if ("关闭".equals (command))
{
scrollPane.setVisible (false);
textArea.setText ("");
validate ();
}
else if ("打开".equals (command))
{
scrollPane.setVisible (true);
validate ();
try
{
FileReader fr = new FileReader (FILE);
char[] cs = new char[1];
while (-1 != ( fr.read (cs) ))
{
textArea.append (new String (cs));
}
fr.close ();
}
catch (Exception e1)
{
e1.printStackTrace ();
}
}
else if ("保存".equals (command))
{
try
{
FileWriter fw = new FileWriter (FILE);
fw.write (textArea.getText ());
fw.flush ();
fw.close ();
}
catch (IOException e1)
{
e1.printStackTrace ();
}
}
}
}
java菜单import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class a extends JFrame implements ActionListener
{
JMenuBar a=new JMenuBar();
JMenu a1=new JMenu("编辑(E)");
JMenu a2=new JMenu("查看(V)");
JMenu a3=new JMenu("帮助(H)");
【java可选择菜单代码 java设置菜单项的快捷键】JMenuItem a11=new JMenuItem("复制(C)",'C');
JMenuItem a12=new JMenuItem("粘贴(P)",'P');
JMenuItem a21=new JMenuItem("标准型(T)",'T');
JMenuItem a22=new JMenuItem("科学型(S)",'S');
JMenuItem a31=new JMenuItem("帮助主题(H)",'H');
public a()
{
super("菜单");
a1.setMnemonic('E');
a2.setMnemonic('V');
a3.setMnemonic('H');
a.add(a1);
a.add(a2);
a.add(a3);
a1.add(a11);
a1.add(a12);
a2.add(a21);
a2.add(a22);
a3.add(a31);
setJMenuBar(a);
a11.addActionListener(this);
a12.addActionListener(this);
a21.addActionListener(this);
a22.addActionListener(this);
a31.addActionListener(this);
}
public void actionPerformed(ActionEvent e)
{
JMenuItem select=(JMenuItem)e.getSource();
}
public static void main(String [] args)
{
a frame=new a();
frame.setSize(300,200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
java可选择菜单代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java设置菜单项的快捷键、java可选择菜单代码的信息别忘了在本站进行查找喔 。
推荐阅读
- redis设置成不用密码登录,redis 不设置密码
- 苹果7p强制降级ios12,iphone7p强制降级教程
- javaee中代码换行,java编程换行
- 真实恒星模拟器游戏,恒星模拟器发展史
- c语言闹钟函数 c语言时钟函数
- 包含ios黄四月影院软件的词条
- 笔记本显卡好坏怎么分级,笔记本显卡好坏怎么分级别
- 如何成为社区电商司机,如何成为社区电商司机呢
- 复变函数python模块 知乎 复变函数