-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduna9.java
More file actions
53 lines (46 loc) · 1.79 KB
/
Copy pathduna9.java
File metadata and controls
53 lines (46 loc) · 1.79 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
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JFrame; //basic window
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JOptionPane;
public class duna9 extends JFrame{
private JTextField item1;
private JTextField item2;
private JTextField item3;
private JPasswordField passwordField;
public duna9(){
super("The title");
setLayout(new FlowLayout());
item1 = new JTextField(10);
add(item1);
item2 = new JTextField("Enter text here :");
add(item2);
item3 = new JTextField("uneditable",20);
item3.setEditable(false);
add(item3);
passwordField = new JPasswordField("mypass");
add(passwordField);
thehandler handler = new thehandler();
item1.addActionListener(handler);
item2.addActionListener(handler);
item3.addActionListener(handler);
passwordField.addActionListener(handler);
}
//methods is gonna be called whenever an event occurs
private class thehandler implements ActionListener{
public void actionPerformed(ActionEvent event){
String string = "";
if(event.getSource()==item1)
string=String.format("field 1 : %s",event.getActionCommand());
else if(event.getSource()==item2)
string=String.format("field 2 : %s",event.getActionCommand());
else if(event.getSource()==item3)
string=String.format("field 3 : %s",event.getActionCommand());
else if(event.getSource()==passwordField)
string=String.format("password field is : %s",event.getActionCommand());
JOptionPane.showMessageDialog(null,string);
}
}
}