zoukankan      html  css  js  c++  java
  • 16.1

     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

    效果图:

  • 相关阅读:
    Vue 创建项目
    Vue组件之间的传参
    Vue自定义组件
    Python开发之路
    爬虫
    手撸系列
    Django从入门到不会放弃
    前端
    day29 TCP的三次握手 TCP的四次挥手 基于TCP的socket
    day28 客户端服务端架构介绍
  • 原文地址:https://www.cnblogs.com/wanjiang/p/5635398.html
Copyright © 2011-2022 走看看