当前位置: 技术问答>java相关
歪脚鸭java学习之经典旅程————————————第三问
来源: 互联网 发布时间:2015-10-11
本文导语: 请哪位用linux平台的兄弟帮我测试个程序。测试菜单快捷键的大小写问题。 文件名:Test.java 测试步骤和方法在代码里。 import java.awt.*; import java.awt.event.*; public class Test { public static void main(String args[]) ...
请哪位用linux平台的兄弟帮我测试个程序。测试菜单快捷键的大小写问题。
文件名:Test.java
测试步骤和方法在代码里。
import java.awt.*;
import java.awt.event.*;
public class Test
{
public static void main(String args[])
{
MenuFrame mf = new MenuFrame();
mf.setSize(new Dimension(300,200));
mf.setVisible(true);
}
}
class MenuFrame extends Frame implements ActionListener,ItemListener
{
MenuBar m_MenuBar;
Menu menuFile,menuEdit,m_Edit_Paste;
MenuItem mi_File_Open,mi_File_Close,mi_File_Exit,mi_Edit_Copy;
MenuItem pi_New,pi_Del,pi_Pro,mi_Paste_All,mi_Paste_Part;
CheckboxMenuItem mi_Edit_Cut;
PopupMenu popM;
TextArea ta;
MenuFrame()
{
super("Menu Windows");
ta = new TextArea("nnnnnntttNo Choice",5,20);
ta.addMouseListener(new HandMouse(this));
add("Center",ta);
popM = new PopupMenu();
pi_New = new MenuItem("New");
pi_New.addActionListener(this);
popM.add(pi_New);
pi_Del = new MenuItem("Del");
pi_Del.addActionListener(this);
popM.add(pi_Del);
pi_Pro = new MenuItem("Pro");
pi_Pro.addActionListener(this);
popM.add(pi_Pro);
ta.add(popM);
m_MenuBar = new MenuBar();
menuFile = new Menu("File");
mi_File_Open = new MenuItem("Open");
mi_File_Close = new MenuItem("Clos");
mi_File_Exit=new MenuItem("Exit");
mi_File_Open.setShortcut(new MenuShortcut('O'));//p==F1;P==p???? winxp下的编译结果
mi_File_Exit.setShortcut(new MenuShortcut('X'));//x==F9;X==x???
//第一步在MenuShortcut方法的参数用大写的O,X;编译后看窗口菜单的结果是否是(Ctrl+O,Ctrl+X)
//第二步在MenuShortcut方法的参数用小写的p,x;编译后看窗口菜单的结果
是否是(Ctrl+F1,Ctrl+F9)
//第二步在MenuShortcut方法的参数用小写的o,x;编译后窗口菜单的结果???
mi_File_Open.setActionCommand("Open");
mi_File_Exit.setActionCommand("Exit");
mi_File_Open.addActionListener(this);
mi_File_Close.addActionListener(this);
mi_File_Exit.addActionListener(this);
menuFile.add(mi_File_Open);
menuFile.add(mi_File_Close);
menuFile.addSeparator();
menuFile.add(mi_File_Exit);
m_MenuBar.add(menuFile);
menuEdit = new Menu("Edit");
mi_Edit_Copy = new MenuItem("Copy");
mi_Edit_Cut = new CheckboxMenuItem("Cut");
m_Edit_Paste = new Menu("Past");
mi_Paste_All=new MenuItem("AllP");
mi_Paste_Part=new MenuItem("ParP");
mi_Edit_Cut.addItemListener(this);
mi_Edit_Copy.addActionListener(this);
mi_Paste_Part.addActionListener(this);
mi_Paste_All.addActionListener(this);
menuEdit.add(mi_Edit_Copy);
menuEdit.add(mi_Edit_Cut);
menuEdit.addSeparator();
menuEdit.add(m_Edit_Paste);
m_Edit_Paste.add(mi_Paste_Part);
m_Edit_Paste.add(mi_Paste_All);
m_MenuBar.add(menuEdit);
this.setMenuBar(m_MenuBar);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() == "Exit")
{
dispose();
System.exit(0);
}
else
ta.setText("nnnnnnttt"+e.getActionCommand());
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() == mi_Edit_Cut)
if(((CheckboxMenuItem)e.getSource()).getState())
ta.setText("nnnnnnttt"+" was choiced "+((CheckboxMenuItem)e.getSource
()).getLabel());
else
ta.setText("nnnnnnttt"+" not choiced "+((CheckboxMenuItem)e.getSource
()).getLabel());
}
}
class HandMouse extends MouseAdapter
{
MenuFrame m_Parent;
HandMouse(MenuFrame mf)
{
m_Parent = mf;
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
m_Parent.popM.show((Component)e.getSource(),e.getX(),e.getY());
}
}
请把结果放在贴子上,能告诉我为什么最谢谢不过!!!!!!
文件名:Test.java
测试步骤和方法在代码里。
import java.awt.*;
import java.awt.event.*;
public class Test
{
public static void main(String args[])
{
MenuFrame mf = new MenuFrame();
mf.setSize(new Dimension(300,200));
mf.setVisible(true);
}
}
class MenuFrame extends Frame implements ActionListener,ItemListener
{
MenuBar m_MenuBar;
Menu menuFile,menuEdit,m_Edit_Paste;
MenuItem mi_File_Open,mi_File_Close,mi_File_Exit,mi_Edit_Copy;
MenuItem pi_New,pi_Del,pi_Pro,mi_Paste_All,mi_Paste_Part;
CheckboxMenuItem mi_Edit_Cut;
PopupMenu popM;
TextArea ta;
MenuFrame()
{
super("Menu Windows");
ta = new TextArea("nnnnnntttNo Choice",5,20);
ta.addMouseListener(new HandMouse(this));
add("Center",ta);
popM = new PopupMenu();
pi_New = new MenuItem("New");
pi_New.addActionListener(this);
popM.add(pi_New);
pi_Del = new MenuItem("Del");
pi_Del.addActionListener(this);
popM.add(pi_Del);
pi_Pro = new MenuItem("Pro");
pi_Pro.addActionListener(this);
popM.add(pi_Pro);
ta.add(popM);
m_MenuBar = new MenuBar();
menuFile = new Menu("File");
mi_File_Open = new MenuItem("Open");
mi_File_Close = new MenuItem("Clos");
mi_File_Exit=new MenuItem("Exit");
mi_File_Open.setShortcut(new MenuShortcut('O'));//p==F1;P==p???? winxp下的编译结果
mi_File_Exit.setShortcut(new MenuShortcut('X'));//x==F9;X==x???
//第一步在MenuShortcut方法的参数用大写的O,X;编译后看窗口菜单的结果是否是(Ctrl+O,Ctrl+X)
//第二步在MenuShortcut方法的参数用小写的p,x;编译后看窗口菜单的结果
是否是(Ctrl+F1,Ctrl+F9)
//第二步在MenuShortcut方法的参数用小写的o,x;编译后窗口菜单的结果???
mi_File_Open.setActionCommand("Open");
mi_File_Exit.setActionCommand("Exit");
mi_File_Open.addActionListener(this);
mi_File_Close.addActionListener(this);
mi_File_Exit.addActionListener(this);
menuFile.add(mi_File_Open);
menuFile.add(mi_File_Close);
menuFile.addSeparator();
menuFile.add(mi_File_Exit);
m_MenuBar.add(menuFile);
menuEdit = new Menu("Edit");
mi_Edit_Copy = new MenuItem("Copy");
mi_Edit_Cut = new CheckboxMenuItem("Cut");
m_Edit_Paste = new Menu("Past");
mi_Paste_All=new MenuItem("AllP");
mi_Paste_Part=new MenuItem("ParP");
mi_Edit_Cut.addItemListener(this);
mi_Edit_Copy.addActionListener(this);
mi_Paste_Part.addActionListener(this);
mi_Paste_All.addActionListener(this);
menuEdit.add(mi_Edit_Copy);
menuEdit.add(mi_Edit_Cut);
menuEdit.addSeparator();
menuEdit.add(m_Edit_Paste);
m_Edit_Paste.add(mi_Paste_Part);
m_Edit_Paste.add(mi_Paste_All);
m_MenuBar.add(menuEdit);
this.setMenuBar(m_MenuBar);
}
public void actionPerformed(ActionEvent e)
{
if(e.getActionCommand() == "Exit")
{
dispose();
System.exit(0);
}
else
ta.setText("nnnnnnttt"+e.getActionCommand());
}
public void itemStateChanged(ItemEvent e)
{
if(e.getSource() == mi_Edit_Cut)
if(((CheckboxMenuItem)e.getSource()).getState())
ta.setText("nnnnnnttt"+" was choiced "+((CheckboxMenuItem)e.getSource
()).getLabel());
else
ta.setText("nnnnnnttt"+" not choiced "+((CheckboxMenuItem)e.getSource
()).getLabel());
}
}
class HandMouse extends MouseAdapter
{
MenuFrame m_Parent;
HandMouse(MenuFrame mf)
{
m_Parent = mf;
}
public void mouseReleased(MouseEvent e)
{
if(e.isPopupTrigger())
m_Parent.popM.show((Component)e.getSource(),e.getX(),e.getY());
}
}
请把结果放在贴子上,能告诉我为什么最谢谢不过!!!!!!
|
up
|
up
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。