-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneButton.java
More file actions
38 lines (31 loc) · 1.04 KB
/
OneButton.java
File metadata and controls
38 lines (31 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class OneButton{
public static void main(String[] args) {
JFrame outerframe = new JFrame("Click the Button");
JButton noclick = new JButton("click me");
noclick.addMouseListener(new MouseAdapter(){
@Override
public void mouseEntered(MouseEvent evt){
noclick.setEnabled(false);
}
@Override
public void mouseExited(MouseEvent evt){
noclick.setEnabled(true);
}
@Override
public void mouseClicked(MouseEvent evt){
if (noclick.isEnabled()){
System.out.println("Plans for world button domination....Failed.");}
else
System.out.println("Valient effort, but you're too slow.");
}
});
Container contentPane = outerframe.getContentPane();
contentPane.add(noclick, BorderLayout.SOUTH);
outerframe.pack();
outerframe.setSize(600, 600);
outerframe.setVisible(true);
}
}