-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainFrame.java
More file actions
109 lines (86 loc) · 3.58 KB
/
MainFrame.java
File metadata and controls
109 lines (86 loc) · 3.58 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package runningShop;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.border.EtchedBorder;
import javax.swing.*;
public class MainFrame extends JFrame{
final private Font mainFont = new Font("Segoe print", Font.BOLD, 18);
JTextField tfFirstName, tfLastName;
JLabel lbWelcome;
public void initialize(){
/**************** Form Panel *****************/
JLabel lbFirstName = new JLabel("First Name");
lbFirstName.setFont(mainFont);
tfFirstName = new JTextField();
tfFirstName.setFont(mainFont);
JLabel lbLastName = new JLabel("Last Name");
lbLastName.setFont(mainFont);
tfLastName = new JTextField();
tfLastName.setFont(mainFont);
tfLastName.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String firstName = tfFirstName.getText();
String lastName = tfLastName.getText();
lbWelcome.setText("Hello " + firstName + " " + lastName);
}});
JPanel formPanel = new JPanel();
formPanel.setLayout(new GridLayout(4, 1, 5, 5));
formPanel.setOpaque(false);
formPanel.add(lbFirstName);
formPanel.add(tfFirstName);
formPanel.add(lbLastName);
formPanel.add(tfLastName);
/*******************Welcome Label**************/
lbWelcome = new JLabel();
lbWelcome.setFont(mainFont);
/*******************Buttons Panel**************/
JButton btnOK = new JButton("OK");
btnOK.setFont(mainFont);
btnOK.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
String firstName = tfFirstName.getText();
String lastName = tfLastName.getText();
lbWelcome.setText("Hello " + firstName + " " + lastName);
}
});
JButton btnClear = new JButton("Clear");
btnClear.setFont(mainFont);
btnClear.addActionListener(new ActionListener(){
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
tfFirstName.setText("");
tfLastName.setText("");
lbWelcome.setText("");
}
});
JPanel buttonsPanel = new JPanel();
buttonsPanel.setLayout(new GridLayout(2, 1, 5, 5));
buttonsPanel.setOpaque(false);
buttonsPanel.add(btnOK);
buttonsPanel.add(btnClear);
JPanel mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
mainPanel.setBackground(new Color(128, 128, 255));
mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
mainPanel.add(formPanel, BorderLayout.NORTH);
mainPanel.add(lbWelcome, BorderLayout.CENTER);
mainPanel.add(buttonsPanel, BorderLayout.SOUTH);
add(mainPanel);
setTitle("Shop");
setSize(500,500);
setMinimumSize(new Dimension(300,400));
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}
public static void main(String[] args) {
MainFrame myFrame = new MainFrame();
myFrame.initialize();
}
}