jbuilder 100例 java源码学习,非常不错,有需要朋友下来
源代码在线查看: frame1.java~21~
package keyevent; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Frame1 extends JFrame { JPanel contentPane; BorderLayout borderLayout1 = new BorderLayout(); Label label1 = new Label(); /**Construct the frame*/ public Frame1() { enableEvents(AWTEvent.WINDOW_EVENT_MASK); try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { //setIconImage(Toolkit.getDefaultToolkit().createImage(Frame1.class.getResource("[Your Icon]"))); contentPane = (JPanel) this.getContentPane(); label1.setAlignment(1); label1.setFont(new java.awt.Font("Dialog", 1, 80)); contentPane.setLayout(borderLayout1); this.setSize(new Dimension(243, 177)); this.setTitle("KeyEvent演示程序"); this.addKeyListener(new java.awt.event.KeyAdapter() { public void keyPressed(KeyEvent e) { this_keyPressed(e); } }); contentPane.add(label1, BorderLayout.CENTER); } /**Overridden so we can exit when window is closed*/ protected void processWindowEvent(WindowEvent e) { super.processWindowEvent(e); if (e.getID() == WindowEvent.WINDOW_CLOSING) { System.exit(0); } } void this_keyPressed(KeyEvent e) { String s = ""; label1.setText(s+=e.getKeyChar()); } }