62,614
社区成员
发帖
与我相关
我的任务
分享
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class test {
public static void main(String[] args) {
JFrame window1 = newwindow(400, 300, "window1");
JButton button1 = newbutton(110, 35, "button1");
window1.add(button1);
button1.addActionListener(new button1click());
}
public static JFrame newwindow(int width, int height, String title) {
JFrame theframe = new JFrame(title);
theframe.setSize(width, height);
theframe.setLayout(new FlowLayout());
theframe.setVisible(true);
theframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
return theframe;
}
public static JButton newbutton(int width, int height, String title) {
JButton thebutton = new JButton(title);
thebutton.setPreferredSize(new Dimension(width, height));
return thebutton;
}
}
class button1click implements ActionListener {
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println(arg0.getActionCommand());
}
}