-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDemo1.java
More file actions
59 lines (49 loc) · 1.55 KB
/
Demo1.java
File metadata and controls
59 lines (49 loc) · 1.55 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
49
50
51
52
53
54
55
56
57
58
59
package Codes;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
public class Demo1 extends JFrame { // implements ActionListener {
JButton b1 = new JButton("Ok");
JButton b2 = new JButton("Cancel");
Demo1() {
setSize(300, 300);
setLocation(200, 200);
getContentPane().setLayout(null);
b1.setBounds(20, 20, 70, 50);
b2.setBounds(100, 20, 70, 50);
// register the listener with button
/*
* b1.addActionListener(new ActionListener() {
*
* @Override public void actionPerformed(ActionEvent e) {
* JOptionPane.showMessageDialog(Demo1.this,
* "U Click On Ok, Hello User");
*
* } });
*/
b1.addActionListener((e) -> JOptionPane.showMessageDialog(Demo1.this, "U Click on Ok , Hello User"));
b2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(Demo1.this, "U Click On Cancel, Welcome User");
}
});
// getContentPane().setLayout(new FlowLayout());
getContentPane().add(b1);
getContentPane().add(b2);
// getContentPane().add(b1,BorderLayout.NORTH);
// getContentPane().add(b2,BorderLayout.SOUTH);
}
public static void main(String[] args) {
Demo1 obj = new Demo1();
obj.setVisible(true);
}
/*
* public void actionPerformed(ActionEvent e){ String msg = "";
* if(e.getActionCommand().equalsIgnoreCase("ok")){ msg = "Hello User"; }
* else { msg = "Welcome User"; } JOptionPane.showMessageDialog(this, msg);
* }
*/
}