日期:2014-05-20 浏览次数:20782 次
import java.awt.Color;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.TextArea;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class Gui10 extends Panel {
public Gui10(String title) {
Frame frame = new Frame(title);
frame.setSize(200, 400);
frame.setLocationRelativeTo(null);
frame.setResizable(true);
init();
frame.add(this);
frame.setVisible(true);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private void init() {
final TextArea textArea = new TextArea(10, 20);
textArea.setBackground(Color.CYAN);
textArea.setText("test");
this.add(textArea);
textArea.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
}
@Override
public void keyReleased(KeyEvent e) {
System.out.println("arg0.getModifiers()=" + e.getModifiers());
System.out.println("arg0.getKeyCode()=" + e.getKeyCode());
// CTRL+C按下
if (e.getModifiers() == 2 && e.getKeyCode() == 67) {
System.out.println("CTRL+C......");
}
}
@Override
public void keyPressed(KeyEvent e) {
}
});
}
public static void main(String[] args) {
new Gui10("demo");
}
}