-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjavalab26.java
More file actions
48 lines (45 loc) · 1.18 KB
/
Copy pathjavalab26.java
File metadata and controls
48 lines (45 loc) · 1.18 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
39
40
41
42
43
44
45
46
47
48
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.security.PrivateKey;
import javax.swing.*;
import java.util.Scanner;
class myCounter extends JFrame implements ActionListener{
JButton b;
JLabel l;
JTextField t;
int count = 0;
myCounter(){
createView();
setTitle("COunter");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(400, 400);
setLocationRelativeTo(null);
setResizable(true);
setVisible(true);
}
private void createView(){
JPanel panel = new JPanel();
getContentPane().add(panel);
panel.setLayout(new GridLayout(6,1,5,5));
l = new JLabel("Counter: ");
t = new JTextField(10000);
t.setText("0");
b = new JButton("count");
panel.add(l);
panel.add(t);
panel.add(b);
b.addActionListener(this);
}
public void actionPerformed(ActionEvent ae){
if(ae.getSource()==b){
count+=1;
t.setText(count+"");
}
}
}
public class javalab26 {
public static void main(String[] args) {
myCounter ob = new myCounter();
}
}