-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGreetingsGUI.java
More file actions
129 lines (102 loc) · 4.31 KB
/
GreetingsGUI.java
File metadata and controls
129 lines (102 loc) · 4.31 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
*/
package za.ac.tut.gui;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.border.BevelBorder;
import javax.swing.border.LineBorder;
import javax.swing.border.TitledBorder;
/**
*
* @author Jacob
*/
public class GreetingsGUI extends JFrame{
//panels
private JPanel namePn1;
private JPanel surnamePn1;
private JPanel nameAndSurnamePn1;
private JPanel greetingsAreaPn1;
private JPanel btnsPn1;
private JPanel mainPn1;
private JPanel headingPn1;
//labels
private JLabel headingLb1;
private JLabel nameLb1;
private JLabel surnameLb1;
//textfields
private JTextField nameTxtFld;
private JTextField surnameTxtFld;
//text area
private JTextArea greetingsTxtArea;
//buttons
private JButton greetBtn;
private JButton clearBtn;
private JButton exitBtn;
//constructor
public GreetingsGUI()
{
setLayout( new BorderLayout());
setTitle ("Greetings GUI");
setSize(700, 750);
setBackground(Color.YELLOW);
//create panel
namePn1 = new JPanel(new FlowLayout());
surnamePn1 = new JPanel(new FlowLayout());
nameAndSurnamePn1 = new JPanel(new GridLayout(2,1));
greetingsAreaPn1 = new JPanel(new FlowLayout());
greetingsAreaPn1.setBorder(new TitledBorder(new LineBorder(Color.BLACK, 1)));
btnsPn1 = new JPanel(new FlowLayout());
mainPn1 = new JPanel(new BorderLayout());
headingPn1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
headingPn1.setBorder(new BevelBorder(BevelBorder.RAISED));
//create the label
headingLb1 = new JLabel("Greetings App");
nameLb1 = new JLabel("Name: ");
surnameLb1 = new JLabel("Surname: ");
//create the text fields
nameTxtFld = new JTextField(20);
surnameTxtFld = new JTextField(20);
//create text area
greetingsTxtArea = new JTextArea(40,50);
greetingsTxtArea.setEditable(false);
greetingsTxtArea.setText("Hello [name] [surname]");
//create buttons
greetBtn = new JButton("Greet");
clearBtn = new JButton("Clear");
exitBtn = new JButton("Exit");
//add name label text and textified to the name panel
namePn1.add(nameLb1);
namePn1.add(nameTxtFld);
//add surname label and textified to the surname panel
surnamePn1.add(surnameLb1);
surnamePn1.add(surnameTxtFld);
//add name and surname panel to the collective panel
nameAndSurnamePn1.add(namePn1);
nameAndSurnamePn1.add(surnamePn1);
//add the greetings area to its panel
greetingsAreaPn1.add(greetingsTxtArea);
//add buttons to their panel
btnsPn1.add(greetBtn);
btnsPn1.add(clearBtn);
btnsPn1.add(exitBtn);
//add all the panels to the main panel
mainPn1.add(nameAndSurnamePn1, BorderLayout.NORTH);
mainPn1.add(greetingsAreaPn1, BorderLayout.CENTER);
mainPn1.add(btnsPn1, BorderLayout.SOUTH);
//add the main panel to the frame's panel
add(headingPn1, BorderLayout.NORTH);
add(mainPn1, BorderLayout.CENTER);
//make frame visible
setVisible(true);
}
}