我的是JDK1.8 什么包也不用导,Swing是JDK自带的功能
package com.dusk.bean;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Test3 {
public static void main(String[] args) {
JFrame frame=new JFrame();
frame.setTitle("测试button");
frame.setSize(400, 400);
frame.setLayout(null);
JButton button=new JButton("点击我");
button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
System.out.println("大神出没,请注意!");
}
});
button.setBounds(100,100,80, 40);
frame.add(button);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}