问题描述
刚接触JAVA,希望指点下。代码如下:/**Tochangethistemplate,chooseTools|Templates*andopenthetemplateintheeditor.*/packagejavaapplication3;importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.*;importjava.io.*;/****@authorjieYu*/publicclassMyNoteBookextendsJFrameimplementsActionListener{privateJMenuBarmenuBar;privateJMenuItemmenuItem;privateJMenumenu;privateJTextAreatextArea;privateJScrollPanescrollPane;publicMyNoteBook(){super("MyNoteBook");setSize(800,600);setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);textArea=newJTextArea(5,30);Containercp=getContentPane();scrollPane=newJScrollPane(textArea);cp.add(scrollPane,BorderLayout.CENTER);menuBar=newJMenuBar();setJMenuBar(menuBar);}//AddfileMenutomenuBarpublicvoidaddFileMenu(){menu=newJMenu("File");menuBar.add(menu);menuItem=newJMenuItem("New");menu.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("New");menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,InputEvent.CTRL_MASK));menuItem=newJMenuItem("Open");menu.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("Open");menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O,InputEvent.CTRL_MASK));menuItem=newJMenuItem("Save");menuItem.add(menu);menuItem.addActionListener(this);menuItem.setActionCommand("Save");menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK));menuItem=newJMenuItem("Saveas");menuItem.add(menu);menuItem.addActionListener(this);menuItem.setActionCommand("Saveas");menu.addSeparator();menuItem=newJMenuItem("Exit");menuItem.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("Exit");}//AddeditMenutomenuBarpublicvoidaddEditMenu(){menu=newJMenu("Edit");menuBar.add(menu);menuItem=newJMenuItem("Cut");menu.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("Cut");menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X,InputEvent.CTRL_MASK));menuItem=newJMenuItem("Copy");menu.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("Copy");menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C,InputEvent.CTRL_MASK));menuItem=newJMenuItem("Paste");menu.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("Paste");menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V,InputEvent.CTRL_MASK));}//AddaboutMenutomenuBarpublicvoidaddAboutMenu(){menu=newJMenu("About");menuBar.add(menu);menuItem=newJMenuItem("Aboutsoftware");menu.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("Aboutsoftware");menuItem=newJMenuItem("Aboutus");menu.add(menuItem);menuItem.addActionListener(this);menuItem.setActionCommand("Aboutus");}//ActionPerformedpublicvoidactionPerformed(ActionEvente){Stringarg=e.getActionCommand();//if(arg.equals("New"))System.out.println("");elseif(arg.equals("Open"))System.out.println("");//openFile();//therecouldbeapublicclasselseif(arg.equals("Save"))System.out.println("");//saveFile();elseif(arg.equals("Saveas"))System.out.println("");elseif(arg.equals("Exit"))System.exit(0);//elseif(arg.equals("Cut"))System.out.println("");//cut();elseif(arg.equals("Copy"))System.out.println("");//copy();elseif(arg.equals("Paste"))System.out.println("");//paste();//elseif(arg.equals("Aboutsoftware")){JOptionPane.showOptionDialog(null,"Software:MyNoteBookn"+"Introduction:Ithassomesimplefunctionsn","Aboutsoftware",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}elseif(arg.equals("Aboutus")){JOptionPane.showOptionDialog(null,"Author:jieYun"+"2011-05-1012:47:15n","Aboutus",JOptionPane.DEFAULT_OPTION,JOptionPane.INFORMATION_MESSAGE,null,null,null);}}publicstaticvoidmain(String[]args){JFrameframe=newMyNoteBook();frame.show();}}