-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimpleGui2.java
More file actions
38 lines (33 loc) · 1.3 KB
/
SimpleGui2.java
File metadata and controls
38 lines (33 loc) · 1.3 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
import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class SimpleGui2 {
private static JFrame fr = null;
private static JButton btn = null;
public static void main(String args[]) {
// Let's make a button first
btn = new JButton("Click Me!");
btn.setMnemonic(KeyEvent.VK_C); // Now you can hit the button with Alt-C
btn.addActionListener(new ButtonListener()); // Allow the button to disable itself
// Let's make the panel with a flow layout.
// Flow layout allows the components to be
// their preferred size.
JPanel pane = new JPanel(new FlowLayout());
pane.add(btn); // Add the button to the pane
// Now for the frame
fr = new JFrame();
fr.setContentPane(pane); // Use our pane as the default pane
fr.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // Exit program when frame is closed
fr.setLocation(200, 200); // located at (200, 200)
fr.pack(); // Frame is ready. Pack it up for display.
fr.setVisible(true); // Make it visible
}
// Button event handler
static class ButtonListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
btn.setEnabled(false); // Disable the button
}
}
}