-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttonclick.java
56 lines (48 loc) · 1.27 KB
/
buttonclick.java
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package gui_tryouts;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class buttonclick implements ActionListener
{
JFrame frame;
JButton button;
JLabel label;
JPanel panel;
int count=0;
public buttonclick()
{
frame = new JFrame();
button = new JButton("Click me");
button.setBackground(Color.YELLOW);
button.setOpaque(true);
button.setBorderPainted(false);
button.addActionListener(this);
label = new JLabel("No. of clicks : 0");
panel = new JPanel();
panel.setBorder(BorderFactory.createEmptyBorder(100,100,100,100));
panel.setBackground(Color.pink);
panel.setLayout(new GridLayout(0,1));
panel.add(button);
panel.add(label);
frame.add(panel,BorderLayout.WEST);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("click the button(time waster)");
frame.pack();
frame.setVisible(true);
//for cross fading button boundaries
try {
UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
}
catch(Exception e){
e.printStackTrace();
}
}
public static void main(String[] args) {
new buttonclick();
}
public void actionPerformed(ActionEvent e) {
count++;
label.setText("No. of clicks : "+count);
}
}