-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSwingFrame3.java
More file actions
67 lines (57 loc) · 1.89 KB
/
Copy pathSwingFrame3.java
File metadata and controls
67 lines (57 loc) · 1.89 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
63
64
65
66
67
import javax.swing.*;
import java.awt.event.*;
public class NumberFrame extends JFrame
{
private JTextField inputField;
private JTextField prevField;
private JTextField nextField;
private JLabel inputLabel;
private JLabel prevLabel;
private JLabel nextLabel;
private JButton button;
public NumberFrame()
{
// Set the title and layout of the frame
setTitle("Number Frame");
setLayout(new FlowLayout());
// Create the labels and text fields
inputLabel = new JLabel("Input:");
add(inputLabel);
inputField = new JTextField(10);
add(inputField);
prevLabel = new JLabel("Previous:");
add(prevLabel);
prevField = new JTextField(10);
prevField.setEditable(false);
add(prevField);
nextLabel = new JLabel("Next:");
add(nextLabel);
nextField = new JTextField(10);
nextField.setEditable(false);
add(nextField);
// Create the button and add an action listener
button = new JButton("Go");
button.addActionListener(new ButtonListener());
add(button);
// Set the size and location of the frame
setSize(300, 150);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
// Get the input number from the input field
int input = Integer.parseInt(inputField.getText());
// Set the previous and next numbers in the prev and next fields
prevField.setText(String.valueOf(input - 1));
nextField.setText(String.valueOf(input + 1));
}
}
public static void main(String[] args)
{
NumberFrame frame = new NumberFrame();
frame.setVisible(true);
}
}