Swing KeyLintener keyboard event listener

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();
                this.getContentPane().add(BorderLayout.NORTH, p1);

                P p2 = new P();
                this.getContentPane().add(BorderLayout.SOUTH, p2);


        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) {

class Listener implements KeyListener {
        public void keyPressed(KeyEvent e) {
                System.out.println("---" + e);

        public void keyReleased(KeyEvent e) {


        public void keyTyped(KeyEvent e) {

分类:Java 时间:2010-03-29 人气:537
blog comments powered by Disqus


  • public static void main (String args []) parameters 2010-05-15

    String args [] is the main function of main parameters, namely array of strings. Using eclipse in the editing, right-click to run the Java files in the Run As option, select Run Configurations. Main class in the Project and complete the project, resp

  • Why public static void main (String args []){} 2010-11-06

    main () is a Java program entry, program execution is the beginning of this entry. Class is a class member, main () method must be public members. So that it can be called in the execution environment. main () method does not produce the object can b

  • Difference between overloading and override 2010-09-16

    Difference between heavy and sometimes covering the class of the same function has a variety of ways, in the end achieved by that method, the caller depends on the given parameters. For example, teachers can train animals, acrobatics, for different a

  • (Transfer) JAVA face questions FAQ Series (6) - string (String) topics for 2010-04-22

    Once we have reviewed the side with the exam questions in the end often several String objects to create knowledge, this time we are entitled to interview several common primer, to a review of String objects related to some other areas. 1, String cla

  • JAVA face questions FAQ Series (6) - string (String) topics for collection 2010-05-27

    JAVA face questions FAQ Series (6) - string (String) topics for collection JAVA face questions FAQ Series (6) - string (String) topics for The last time we have together reviewed the exam in the end often face questions a few String objects to create

  • 浅析C#中的Main(String[] args)参数输入问题 2014-07-20

    本篇文章主要是对C#中的Main(String[] args)参数输入问题进行了详细的介绍,需要的朋友可以过来参考下,希望对大家有所帮助 指定相关的测试代码 首先,写一个用于测试的关于Main(String[] args)参数输入有关的代码类,如下: using System; public class Hello { public static void Main(String[] args) { switch (args[0]) { case "老板": Console.Write

  • Java, how to determine the empty string 2010-03-29

    The following is a Java to determine whether the empty string in several ways. Method One: Most people use a method, intuitive and convenient, but inefficient. Method 2: To compare the length of the string, high efficiency, yes I know the best method

  • java how to judge a Chinese string 2010-11-16

    There is a Character.UnicodeBlock in Java static class, Character.UnicodeBlock.of (char c) Returns the character literal. For example: class Test { / / Determine whether the Chinese character private boolean isChinese (char c) { Character.UnicodeBloc

  • java access modifiers public protected friendly private usage summary 2009-04-01

    First, the statement: java in, friendly, and this modifier is not an explicit statement of the member variables and methods of the former would not have any modifiers, the default is friendly. For clarity, sub-summed up in three different circumstanc

  • Switch: java database manipulation of the main lob types of data 2010-04-11

    Blob Clob and is divided into three kinds of operations: insert, update, and reading. For insertion, can be divided into two categories. One is the normal field can handle, one must first insert a blank for the clob / blob and then update the actual

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.140 (s). 12 q(s)