我已经浏览了挥杆教程,但我看不出我做错了什么。为什么当我点击 jmenuitem 时什么都没有发生?
我的第一堂课:
import javax.swing.*;
public class WordProcess{
/*TODO: make program end on close
*/
public static void main(String[] args) {
MainFrame frame = new MainFrame("Word Processor", 10000, 10000);
}
}
第二类:
import javax.swing.*;
public class MainFrame extends JFrame {
JMenuBar menubar = new JMenuBar();
public MainFrame(String name, int x, int y) {
setTitle(name);
setSize(x, y);
setVisible(true);
setJMenuBar(menubar);
//creates file menu and adds to menubar
//TODO populate with JMenuItems
JMenu filemenu = new JMenu("file");
filemenu.setVisible(true);
menubar.add(filemenu);
buttonnew buttonnew = new buttonnew("new");
buttonnew.setVisible(true);
filemenu.add(buttonnew);
}
}
第三类:
import javax.swing.*;
import java.awt.event.*;
public class buttonnew extends JMenuItem implements ActionListener{
buttonnew(String s) {
super();
super.setText(s);
addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent ae) {
JFrame newframe = new JFrame("sup");
}
}