import java.awt.BorderLayout;
public class text2 extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
text2 frame = new text2();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public text2() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
JScrollPane scrollPane = new JScrollPane();
contentPane.add(scrollPane, BorderLayout.CENTER);
final JTextArea textArea = new JTextArea();
scrollPane.setViewportView(textArea);
JMenuBar menuBar = new JMenuBar();
scrollPane.setColumnHeaderView(menuBar);
JMenu menu = new JMenu("\u7F16\u8F91");
menuBar.add(menu);
JMenuItem mntmCopy = new JMenuItem("copy");
mntmCopy.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.copy();
}
});
menu.add(mntmCopy);
JMenuItem mntmPaste = new JMenuItem("paste");
mntmPaste.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.paste();
}
});
menu.add(mntmPaste);
JMenuItem mntmCut = new JMenuItem("cut");
mntmCut.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {//mouseclick
textArea.cut();
}
});
menu.add(mntmCut);
}
}
这是改好的,原来的监听事件为mouseclick,可是就是不起作用,不知原因,请教帮助解答。
类似处的事件都是这样的:
JMenuItem mntmCut = new JMenuItem("cut");
mntmCut.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
text.cut();
}
});
menu.add(mntmCut);
结果触发不成功,但是想知道原因。。。。。。。。。。。
Smart猫小萌
相关分类