java怎么设置jbutton每点一次的功能都不一样
1个回答
展开全部
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package imagetest;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame {
public Test() {
JButton btn = new JButton("关闭");
this.add(btn, BorderLayout.WEST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 300);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(JOptionPane.showConfirmDialog(Test.this, "确定关闭吗?","确认",JOptionPane.OK_CANCEL_OPTION)==0)
System.exit(0);}
});
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package imagetest;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Test extends JFrame {
public Test() {
JButton btn = new JButton("关闭");
this.add(btn, BorderLayout.WEST);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(300, 300);
btn.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if(JOptionPane.showConfirmDialog(Test.this, "确定关闭吗?","确认",JOptionPane.OK_CANCEL_OPTION)==0)
System.exit(0);}
});
}
public static void main(String[] args) {
new Test().setVisible(true);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询