-
Notifications
You must be signed in to change notification settings - Fork 0
/
SwingDemo.java
57 lines (57 loc) · 1.25 KB
/
SwingDemo.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
57
//Swings Demo
import java.awt.event.*;
import java.awt.*;
import javax.swing.*;
public class SwingDemo
{
public static JFrame jf;
private JTextField jt,jt1;
private JLabel jl;
private JButton jb;
private JPanel p;
public SwingDemo()
{
prepareGUI();
}
public static void main(String args[])
{
SwingDemo s=new SwingDemo();
s.showEventDemo();
}
public void prepareGUI()
{
jf= new JFrame("Java Swing");
jf.setSize(400,400);
jf.setLayout(new GridLayout(3,1));
jf.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent windowEvent){
System.exit(0);
}
});
p=new JPanel();
p.setLayout(new FlowLayout());
jl=new JLabel("Enter Text : ");
jt=new JTextField("",30);
jt1=new JTextField("",30);
p.add(jl);
p.add(jt);
p.add(jt1);
jf.setVisible(true);
}
private void showEventDemo()
{
jb=new JButton("Click");
jb.addActionListener(new ButtonClickListener());
p.add(jb);
jf.setVisible(true);
}
private class ButtonClickListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
String command = e.getActionCommand();
String text=jt.getText();
if( command.equals("Click")) {
jt1.setText(text);
}
}
}
}