62,612
社区成员
发帖
与我相关
我的任务
分享
package testDoClick;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainFrame extends JFrame{
private JButton doClickButton;
private JPanel panel;
public static void main(String[] args) {
MainFrame mainFrame = new MainFrame();
mainFrame.setTitle("测试doClick()");
}
public MainFrame(){
super();
this.setVisible(true);
this.setBounds(10, 10, 400, 200);
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(null);
panel = new JPanel();
panel.setBackground(new Color(135, 206, 250));
panel.setBounds(10, 10, 380, 150);
this.add(panel);
panel.setLayout(null);
doClickButton = new JButton("我想停下来");
doClickButton.setBounds(90, 50, 200, 50);
panel.add(doClickButton);
doClickButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println("我想停下来");
doClickButton.doClick(1000);
}
});
}
}
package testDoClick;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
public class MainFrame extends JFrame{
private JButton doClickButton;
private JPanel panel;
public static void main(String[] args) {
MainFrame mainFrame = new MainFrame();
mainFrame.setTitle("测试doClick()");
}
public MainFrame(){
super();
this.setVisible(true);
this.setBounds(10, 10, 400, 200);
this.setResizable(false);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setLayout(null);
panel = new JPanel();
panel.setBackground(new Color(135, 206, 250));
panel.setBounds(10, 10, 380, 150);
this.add(panel);
panel.setLayout(null);
doClickButton = new JButton("我想停下来");
doClickButton.setBounds(90, 50, 200, 50);
panel.add(doClickButton);
doClickButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
System.out.println("我想停下来");
doClickButton.doClick(1000);
}
});
}
}