English 中文(简体)
a GUI java方案需要一项行动活动,但纽芬兰
原标题:a GUI java program needing an action event button

我正在做一个简单的java方案,它代表的是Microsoft Word menu酒吧,在档案中,我补充说,它没有任何东西。

我需要你帮助告诉我,要让出国真正撤出并结束该方案,需要做些什么。

我的守则是:

public class MicrosoftWordMenu {
        public static void main(String [] args)
        {
        JPanel panel = new JPanel();
        JFrame frame = new JFrame("Microsoft Word");
        JMenuBar bar = new JMenuBar();
        JMenu menu = new JMenu("File");
        JMenu menu1 = new JMenu("Edit");
        JMenu menu2 = new JMenu("View");
        JMenu menu3 = new JMenu("Insert");
        JMenu menu4 = new JMenu("Format");
        JMenu menu5 = new JMenu("Tools");
        JMenu menu6 = new JMenu("Table");
        JMenu menu7 = new JMenu("Window");
        JMenu menu8 = new JMenu("Help");

        frame.add(bar, BorderLayout.NORTH);
        frame.add(panel);

        bar.add(menu);
        bar.add(menu1);
        bar.add(menu2);
        bar.add(menu3);
        bar.add(menu4);
        bar.add(menu5);
        bar.add(menu6);
        bar.add(menu7);
        bar.add(menu8);

        JMenuItem menuitem = new JMenuItem("New...");
        JMenuItem menuitem1 = new JMenuItem("Open...");
        JMenuItem menuitem2 = new JMenuItem("Close");
        JMenuItem menuitem3 = new JMenuItem("Save");
        JMenuItem menuitem4 = new JMenuItem("Save as...");
        JMenuItem menuitem5 = new JMenuItem("Save as web page...");
        JMenuItem menuitem6 = new JMenuItem("Web page preview ");
        JMenuItem menuitem7 = new JMenuItem("Print ");
        JMenuItem menuitem8 = new JMenuItem("Exit");

        menu.add(menuitem);
        menu.add(menuitem1);
        menu.add(menuitem2);
        menu.add(menuitem3);
        menu.add(menuitem4);
        menu.add(menuitem5);
        menu.add(menuitem6);
        menu.add(menuitem7);
        menu.add(menuitem8);

        frame.setSize(600,100);
        frame.setVisible(true);
        }

}
问题回答

还考虑使用Action, 以便让部件共享功能,如

此时,你只是重新构造了“全球倡议”的内容,但基本上空投了空壳。 尤其是,你创造了在菜单上出现的项目,但yount在这些项目中增加了任何行为。 (如果你没有告诉你在什么时候点击某个物品,你会怎样做?)

为了提供这种行为,你需要登记一份<条码>行动代码<>代码/代码>,在某一要素上将称作something,并届时将请你采取适当行动(例如:<条码>System.exit(0))。 See the tutorial on Writing [Swing] Activitieslecters for details.

我总是延长“抽象行动”类别(执行“生命行动”接口),使你能够重新采取行动。 通过扩大“摘要行动”范围,将援引“行动(行动)”方法。

public class CloseAction extends AbstractAction {

  public CloseAction() {
    super("Close");
  }

  public actionPerformed(ActionEvent e) {
    System.exit(1);  
  }

}

Now, to apply the above action to one of your buttons, you simply need to follow the below piece of code.

近布顿行动(新的近行动);

关闭的纽特将每次停办时都关闭你的申请。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...