-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwingExample.java
More file actions
63 lines (53 loc) · 1.48 KB
/
Copy pathSwingExample.java
File metadata and controls
63 lines (53 loc) · 1.48 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
60
61
62
package java1_2.swing;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
* Java 1.2 Swing GUI Framework Example Demonstrates Swing components
*/
public class SwingExample extends JFrame implements ActionListener
{
private JButton button;
private JLabel label;
private JTextField textField;
private int clickCount = 0;
public SwingExample()
{
setTitle("Java 1.2 Swing Example");
setSize(400, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new FlowLayout());
// Label
label = new JLabel("Welcome to Swing");
add(label);
// TextField
textField = new JTextField(20);
add(textField);
// Button
button = new JButton("Click Me");
button.addActionListener(this);
add(button);
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == button)
{
clickCount++;
label.setText("Button clicked " + clickCount + " times");
System.out.println("Button clicked! Text: " + textField.getText());
}
}
public static void main(String[] args)
{
System.out.println("=== Java 1.2 Swing GUI Framework ===\n");
System.out.println("Swing provides:");
System.out.println("- Lightweight components");
System.out.println("- Platform-independent look and feel");
System.out.println("- Rich component set");
System.out.println("- Better than AWT");
System.out.println("- MVC architecture");
System.out.println("\nCreating Swing window...");
SwingUtilities.invokeLater(() -> new SwingExample());
}
}