- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGuiProjectFrame.java
More file actions
Latest commit
240 lines (216 loc) · 6.67 KB
/
Copy pathGuiProjectFrame.java
File metadata and controls
240 lines (216 loc) · 6.67 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
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
* NAME: Tommaso Marenzi
* OOAssessment: GuiProjectTM
*/
importjava.awt.*;
importjava.awt.event.*;
importjavax.swing.*;
importjava.io.File;
importjava.io.FileNotFoundException;
importjava.util.Scanner;
publicclassGuiProjectTMFrameextendsJFrame
{
privatestaticfinalintFRAME_WIDTH = 500;
privatestaticfinalintFRAME_HEIGTH = 250;
privatestaticfinalGridBagLayoutbagLayout = newGridBagLayout();
privatestaticfinalGridBagConstraintsc = newGridBagConstraints();
privatestaticJLabelbackground = newJLabel (newImageIcon("ItalialogoTM.png")), //creates a label with a picture as background
titleLabel = newJLabel("ITALIAN NATIONAL FOOTBALL TEAM MEMBERS"), // creates the label with the title
instructionLabel = newJLabel("Click NEXT to show players info, click EXIT to close the program."),
numberLabel = newJLabel("Number:"),
numberDisplay = newJLabel("**"),
positionLabel = newJLabel("Position:"),
positionDisplay = newJLabel("**"),
nameLabel = newJLabel("Full name:"),
nameDisplay = newJLabel("******* *******"),
dateOfBirthLabel = newJLabel("Date of birth:"),
dateOfBirthDisplay = newJLabel("DD-MM-YYYY");
privatestaticJButtonnextButton = newJButton("NEXT"),
exitButton = newJButton("EXIT");
privatestaticintnumClicks = 0;
publicGuiProjectTMFrame4()
{
super("GuiProjectTM A");
createComponents();
setSize(FRAME_WIDTH,FRAME_HEIGTH);
}
privatevoidcreateComponents()//specifies attributes for the components and add them to the panel
{
FontlabelFont = newFont("Calibri",Font.BOLD,15);//font for labels
FonttextFont = newFont("Calibri", Font.ITALIC,15);//font for text displayed
FonttitleFont = newFont("Calibri", Font.BOLD,20);//font for the title
setLayout(newBorderLayout());
add(background);//add background to the panel
background.setLayout(bagLayout); //set background layout
//set title label
titleLabel.setFont(titleFont);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 0.5;
c.gridwidth = 2;
c.gridx = 0;
c.gridy = 0;
background.add(titleLabel, c);
//set instructions Label
instructionLabel.setFont(textFont);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_START;
c.weightx = 0.5;
c.gridwidth = 2;
c.gridx = 0;
c.gridy = 1;
background.add(instructionLabel, c);
//set container with number labels
numberLabel.setFont(labelFont);
numberDisplay.setFont(textFont);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 2;
background.add(numberLabel, c);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 1;
c.gridy = 2;
background.add(numberDisplay, c);
//set position labels
positionLabel.setFont(labelFont);
positionDisplay.setFont(textFont);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 3;
background.add(positionLabel, c);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 1;
c.gridy = 3;
background.add(positionDisplay, c);
//set name labels
nameLabel.setFont(labelFont);
nameDisplay.setFont(textFont);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 4;
background.add(nameLabel, c);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 1;
c.gridy = 4;
background.add(nameDisplay, c);
//set date of birth labels
dateOfBirthLabel.setFont(labelFont);
dateOfBirthDisplay.setFont(textFont);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 5;
background.add(dateOfBirthLabel, c);
c.fill =GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.CENTER;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 1;
c.gridy = 5;
background.add(dateOfBirthDisplay, c);
//set next button and exit button
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_END;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 0;
c.gridy = 6;
background.add(nextButton, c);
c.fill = GridBagConstraints.HORIZONTAL;
c.anchor = GridBagConstraints.PAGE_END;
c.weightx = 0.5;
c.gridwidth = 1;
c.gridx = 1;
c.gridy = 6;
background.add(exitButton, c);
//add actionListener for nextButton
nextButton.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEvente)
{
fileReader();
numClicks++;
}
});
//add actionListener for exitButton
exitButton.addActionListener(newActionListener()
{
publicvoidactionPerformed(ActionEventevent)
{
setVisible(false);
}
});
}//end createComponents()
// method which performs the reading of the file
privatestaticvoidfileReader()
{
try
{
//construct the scanner for reading
FileinputFile = newFile("ItalianNationalFootballTeamTM.txt");
Scannerin = newScanner(inputFile);
//read the input
while(in.hasNextLine())
{
Stringline = in.nextLine();//read the next line
Stringelement = "";
intcounter = 0; //variable to count the number of tab found
intj = 0;// variable to keep track of the position of the previous tab
//read a nuber of line equals to the number of clicks
for(intx=0; x<numClicks; x++)
{
line = in.nextLine();
}
//read through the line until a tab is found
for(inti=0;counter < 4 && i < line.length(); i++)
{
charch = line.charAt(i); // convert the string element into a char type
if(ch == '\t')
{
switch (counter)
{
case0: element = line.substring(j, i+1);
numberDisplay.setText(element);
break;
case1: element = line.substring(j, i+1);
positionDisplay.setText(element);
break;
case2: element = line.substring(j, i+1);
nameDisplay.setText(element);
break;
case3: element = line.substring(j, i+1);
dateOfBirthDisplay.setText(element);
break;
default: numberDisplay.setText("END OF SWITCH");
break;
}//end switch
counter++; //increment the counter for number of tab found
j = i; // set j to the position of i
}//end if
}//end for
in.close();
}//end while
}//end try
catch(Exceptione){}
}//end fileReader()
}//end GuiProjectTMFrame