Swing KeyLintener keyboard event listener
Advertisements
package Assis;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestEvent extends JFrame {
private static final long serialVersionUID = 1L;
public TestEvent() {
setSize(400, 300);
// addKeyListener(new Listener());
P p1 = new P();
System.out.println(p1.isFocusable());
p1.setFocusable(true);
p1.setBackground(Color.red);
this.getContentPane().add(BorderLayout.NORTH, p1);
P p2 = new P();
p2.setBackground(Color.green);
this.getContentPane().add(BorderLayout.SOUTH, p2);
setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
new TestEvent();
}
}
class P extends JPanel {
private static final long serialVersionUID = 1L;
public P() {
addKeyListener(new Listener());
this.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
System.out.println(e);
}
});
}
}
class Listener implements KeyListener {
public void keyPressed(KeyEvent e) {
System.out.println("---" + e);
}
public void keyReleased(KeyEvent e) {
}
public void keyTyped(KeyEvent e) {
}
}
Related Posts of Swing KeyLintener keyboard event listener
-
log4j easy application in java
JAVA development, frequently used the log output, in a so-called most of the software company will have its own set of configuration style, re-read the configuration file to initialize property of the log, it will be good, but sometimes may not need to fu
-
jboss ejb3 Message Driven Bean
Super Medium ejb hate. . . . . . . . . . . . . . . . . . . ================================================ To configure a Message Driven Bean in a different application server parameters are not the same. Currently only passed the test jboss. Message Dri
-
JDBC example of a long time do not have JDBC forgot
A back-up here to stay. The first: The second:
-
In the servlet use Bean
According to Sun's definition, JavaBean is a reusable software components. In fact JavaBean is a Java class, through the package into a property and methods of treatment of a function or a business object, referred to as bean. Because JavaBean is ...
-
hibernate generic generic DAO
package org.lzpeng.dao; import java.io.Serializable; import java.util.List; import org.hibernate.Criteria; import org.hibernate.Query; import org.hibernate.criterion.Criterion; import org.springside.modules.orm.hibernate.Page; /** * * @version 2009-1-10 *
-
Servlet brief introduction
Servlet brief introduction: Servlet is a small application server Are used to complete the B / S architecture, the client requests the response to treatment Platform independence, performance, able to run thread Servlet API for Servlet provides the s ...
-
First Hibernate Example
Curd a simple example. Source does not contain the dependent libraries, or playing too much of the package. PO object Note: One must have the default constructor 2 non-final modified. Otherwise useless lazy loading. UserDAOImpl category code, and other co
-
Struts2 + hibernate + spring problem user log in
dao layer services layer action jsp <tr> <td align="center"> <b> user name: </ b> </ td> <td> <s: textfield name = "czyNumber" cssClass = "textstyle" theme = "simple" size = &q












