请参考下面的代码,不知是否满足你.
import javax.swing.*;
import java.awt.event.*;public class JMenuItem1 extends JFrame{ JTextArea theArea = null; public JMenuItem1(){
super("JMenuItem1");
theArea = new JTextArea();
theArea.setEditable(true);
getContentPane().add(new JScrollPane(theArea));
JMenuBar MBar = new JMenuBar();
MBar.setOpaque(true);
JMenu thefile = new JMenu("File");
thefile.setMnemonic('f');
JMenuItem newf = new JMenuItem("New");
JMenuItem open = new JMenuItem("Open");
JMenuItem close= new JMenuItem("Close");
final JMenuItem copy= new JMenuItem("Copy");
JMenuItem delete= new JMenuItem("Delete");
JMenuItem quit = new JMenuItem("Exit"); thefile.add(newf);
thefile.add(open);
thefile.add(close);
thefile.addSeparator();
thefile.add(copy);
thefile.add(delete);
thefile.addSeparator();
thefile.add(quit);
copy.setEnabled(false);
delete.setEnabled(false);
MBar.add(thefile);
setJMenuBar(MBar);
theArea.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e)
{
copy.setEnabled(true);
}
});
}//end of JMenuItem1() public static void main(String[] args){ JFrame F = new JMenuItem1();
F.setSize(400,200);
F.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});//end of addWindowListener
F.setVisible(true);
} // end of main
}//end of class JMenuItem1
import javax.swing.*;
import java.awt.event.*;public class JMenuItem1 extends JFrame{ JTextArea theArea = null; public JMenuItem1(){
super("JMenuItem1");
theArea = new JTextArea();
theArea.setEditable(true);
getContentPane().add(new JScrollPane(theArea));
JMenuBar MBar = new JMenuBar();
MBar.setOpaque(true);
JMenu thefile = new JMenu("File");
thefile.setMnemonic('f');
JMenuItem newf = new JMenuItem("New");
JMenuItem open = new JMenuItem("Open");
JMenuItem close= new JMenuItem("Close");
final JMenuItem copy= new JMenuItem("Copy");
JMenuItem delete= new JMenuItem("Delete");
JMenuItem quit = new JMenuItem("Exit"); thefile.add(newf);
thefile.add(open);
thefile.add(close);
thefile.addSeparator();
thefile.add(copy);
thefile.add(delete);
thefile.addSeparator();
thefile.add(quit);
copy.setEnabled(false);
delete.setEnabled(false);
MBar.add(thefile);
setJMenuBar(MBar);
theArea.addMouseMotionListener(new MouseMotionAdapter(){
public void mouseDragged(MouseEvent e)
{
copy.setEnabled(true);
}
});
}//end of JMenuItem1() public static void main(String[] args){ JFrame F = new JMenuItem1();
F.setSize(400,200);
F.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});//end of addWindowListener
F.setVisible(true);
} // end of main
}//end of class JMenuItem1
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货