这是我的主要课程:
import javax.swing.*;
public class WordProcessor {
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);
buttonnew.addMouseListener(buttonnew);
}
}
最后
import javax.swing.*;
import java.awt.event.*;
public class buttonnew extends JMenuItem implements MouseListener{
buttonnew(String s) {
super();
super.setText(s);
}
public void mouseClicked(MouseEvent e){
System.out.println("hey-o");
}
@Override
public void mouseExited(MouseEvent e) {
}
public void mouseEntered(MouseEvent e) {
}
public void mouseReleased(MouseEvent e) {
}
public void mousePressed(MouseEvent e) {
}
}
当我单击 buttonneẅ 时没有任何反应。我迷路了!