码迷,mamicode.com
首页 > 其他好文 > 详细

16.1

时间:2016-07-02 15:55:11      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

技术分享
 1 import java.awt.event.ActionEvent;
 2 import java.awt.event.ActionListener;
 3 
 4 import javax.swing.JButton;
 5 import javax.swing.JFrame;
 6 import javax.swing.JPanel;
 7 
 8 public class Test_16 extends JFrame{
 9 
10     public Test_16(){
11         JP J = new JP();        
12         add(J);
13     }
14     
15     
16     public static void main(String[] args) {
17         // TODO Auto-generated method stub
18         Test_16 t1 = new Test_16();
19         t1.setTitle("print");
20         t1.setSize(200,200);
21         t1.setFocusable(true);
22         t1.setLocationRelativeTo(null);
23         t1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
24         t1.setVisible(true);        
25     }    
26     
27     static class JP extends JPanel{    
28         JButton j1 = new JButton("Button1");
29         JButton j2 = new JButton("Button2");
30         public JP(){
31             add(j1);
32             add(j2);
33             j1.addActionListener(new ActionListener(){
34                 public void actionPerformed(ActionEvent e){
35                     System.out.println("j1 is pressed");
36                 }
37             });
38             j2.addActionListener(new ActionListener(){
39                 public void actionPerformed(ActionEvent e){
40                     System.out.println("j2 is pressed");
41                 }
42             });                        
43         }        
44     }
45     
46 }
Test_16.java

效果图:

技术分享

 

16.1

标签:

原文地址:http://www.cnblogs.com/wanjiang/p/5635398.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!