用java编写一个窗口一,窗口上有一个按钮,按钮记录单击按钮的次数.
1个回答
展开全部
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class JFrameTest extends JFrame{
private JButton button;
private Container content;
private int count=0;
public JFrameTest(){
super("JFrameTest");
this.setBounds(100,100,300,200);
content=this.getContentPane();
content.setLayout(new FlowLayout());
button=new JButton("还没有点击哦");
content.add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
count++;
button.setText("点击了"+count+"次");
}
});
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new JFrameTest();
}
}
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class JFrameTest extends JFrame{
private JButton button;
private Container content;
private int count=0;
public JFrameTest(){
super("JFrameTest");
this.setBounds(100,100,300,200);
content=this.getContentPane();
content.setLayout(new FlowLayout());
button=new JButton("还没有点击哦");
content.add(button);
button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
count++;
button.setText("点击了"+count+"次");
}
});
this.setVisible(true);
this.setResizable(false);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new JFrameTest();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询