Java键盘事件监听(2)

package com.han;

import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;

/**
 * 键盘事件监听(2)
 * @author HAN
 *
 */
public class KeyEvent_2 extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 8599016812375478424L;

	public KeyEvent_2() {
		// TODO Auto-generated constructor stub
		Container container = getContentPane();
		container.setLayout(new FlowLayout());
		JLabel label = new JLabel("实现只允许输入数字的文本框:");
		JTextField textField = new DigitOnlyField(10);
		container.add(label);
		container.add(textField);
		
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		KeyEvent_2 frame = new KeyEvent_2();
		frame.setTitle("实现只允许输入数字的文本框");
		frame.pack();
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

}


posted on 2012-07-12 05:16  java课程设计例子  阅读(178)  评论(0编辑  收藏  举报