-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGUI_project.java
173 lines (143 loc) · 5.33 KB
/
GUI_project.java
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
/**
*Text genereted by Simple GUI Extension for BlueJ
*/
import javax.swing.UIManager.LookAndFeelInfo;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.border.Border;
import javax.swing.*;
public class GUI_project extends JFrame {
private JMenuBar menuBar;
private JButton Addbtn;
private JButton Clearbtn;
private JLabel label1;
private JTextArea textarea1;
private JTextField textfield1;
//Constructor
public GUI_project(){
this.setTitle("GUI_project");
this.setSize(500,400);
//menu generate method
generateMenu();
this.setJMenuBar(menuBar);
//pane with null layout
JPanel contentPane = new JPanel(null);
contentPane.setPreferredSize(new Dimension(500,400));
contentPane.setBackground(new Color(192,192,192));
textarea1 = new JTextArea();
textarea1.setBounds(12,24,240,351);
textarea1.setBackground(new Color(255,255,255));
textarea1.setForeground(new Color(0,0,0));
textarea1.setEnabled(true);
textarea1.setFont(new Font("sansserif",0,12));
textarea1.setText("");
textarea1.setBorder(BorderFactory.createBevelBorder(1));
textarea1.setVisible(true);
textfield1 = new JTextField();
textfield1.setBounds(267,67,204,34);
textfield1.setBackground(new Color(255,255,255));
textfield1.setForeground(new Color(0,0,0));
textfield1.setEnabled(true);
textfield1.setFont(new Font("sansserif",0,12));
textfield1.setText("");
textfield1.setVisible(true);
Addbtn = new JButton();
Addbtn.setBounds(268,102,90,35);
Addbtn.setBackground(new Color(214,217,223));
Addbtn.setForeground(new Color(0,0,0));
Addbtn.setEnabled(true);
Addbtn.setFont(new Font("sansserif",0,12));
Addbtn.setText("Add Item");
Addbtn.setVisible(true);
//Set methods for mouse events
//Call defined methods
Addbtn.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
String txt = textfield1.getText().toString();
textarea1.append(IncreaseArraySize.addItem(txt));
for(String N : IncreaseArraySize.MYARRAY){
textarea1.append(N + "\n");
}
}
});
Clearbtn = new JButton();
Clearbtn.setBounds(357,102,115,35);
Clearbtn.setBackground(new Color(214,217,223));
Clearbtn.setForeground(new Color(0,0,0));
Clearbtn.setEnabled(true);
Clearbtn.setFont(new Font("sansserif",0,12));
Clearbtn.setText("Clear Textarea");
Clearbtn.setVisible(true);
//Set methods for mouse events
//Call defined methods
Clearbtn.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
textarea1.setText(null);
}
});
label1 = new JLabel();
label1.setBounds(270,25,226,32);
label1.setBackground(new Color(214,217,223));
label1.setForeground(new Color(0,0,0));
label1.setEnabled(true);
label1.setFont(new Font("sansserif",0,12));
label1.setText("Please enter an item (type 'end' to stop)");
label1.setVisible(true);
//adding components to contentPane panel
contentPane.add(Addbtn);
contentPane.add(Clearbtn);
contentPane.add(label1);
contentPane.add(textarea1);
contentPane.add(textfield1);
//adding panel to JFrame and seting of window position and close operation
this.add(contentPane);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.pack();
this.setVisible(true);
}
//Method mouseClicked for Addbtn
private void AddbtnClicked (MouseEvent evt) {
//TODO
}
//Method mouseClicked for Clearbtn
private void ClearbtnClicked (MouseEvent evt) {
//TODO
}
//method for generate menu
public void generateMenu(){
menuBar = new JMenuBar();
JMenu file = new JMenu("File");
JMenu tools = new JMenu("Tools");
JMenu help = new JMenu("Help");
JMenuItem open = new JMenuItem("Open ");
JMenuItem save = new JMenuItem("Save ");
JMenuItem exit = new JMenuItem("Exit ");
JMenuItem preferences = new JMenuItem("Preferences ");
JMenuItem about = new JMenuItem("About ");
file.add(open);
file.add(save);
file.addSeparator();
file.add(exit);
tools.add(preferences);
help.add(about);
menuBar.add(file);
menuBar.add(tools);
menuBar.add(help);
}
public static void main(String[] args){
System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
new GUI_project();
}
});
}
}