swing中的按钮事件

半城伤御伤魂 提交于 2020-02-17 04:54:03

package pack2;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

public class num_2v extends JFrame implements ActionListener{

  JButton jb;

  public num_2v(){

   jb = new JButton("确定");

   jb.addActionListener(this);

   this.add(jb);

   this.setSize(300,300);

   this.setLocationRelativeTo(null);

   this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

   this.setVisible(true);

  }     

  public static void main(String[] args) {

   new num_2v();

  }

  @Override

  public void actionPerformed(ActionEvent e) {

   // TODO 自动生成的方法存根

   System.out.println("点击了按钮");

  }

}

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!