Repository navigation
Expand file tree
/
Copy pathHomePage.java
More file actions
356 lines (304 loc) · 12.6 KB
/
Copy pathHomePage.java
File metadata and controls
356 lines (304 loc) · 12.6 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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.util.Objects;
public class HomePage extends JFrame {
static int[] jumlah = {0};
static Long[] nik1 = {0L};
static Long[] no = {0L};
static String[] titik = {"tes", "toto"};
static String[] alphabet = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "u", "V", "W", "X", "Y", "Z"};
public HomePage() {
Pelanggan p = new Pelanggan();
//frame homepage
this.setSize(800, 500);
this.getContentPane().setBackground(Color.decode("#9a8c98"));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLayout(null);
// label Eka bis
JLabel eka = new JLabel();
eka.setText("Sistem Pemesanan Bis Eka");
eka.setFont(new Font("Tahoma", Font.BOLD, 17));
eka.setForeground(Color.decode("#f9dcc4"));
eka.setBounds(268, 0, 300, 40);
this.add(eka);
//Textfield nama penumpang
JLabel nama = new JLabel();
nama.setText("Nama Penumpang");
nama.setFont(new Font("Tahoma", Font.BOLD, 17));
nama.setForeground(Color.decode("#f9dcc4"));
nama.setBounds(20, 60, 300, 25);
this.add(nama);
JTextField isiNama = new JTextField();
isiNama.setFont(new Font("Tahoma", Font.PLAIN, 15));
isiNama.setEditable(true);
isiNama.setBackground(Color.decode("#ecf39e"));
isiNama.setBounds(20, 90, 300, 25);
p.setNama(isiNama.getText());
this.add(isiNama);
//Warn kl bukan angka
JLabel warn3 = new JLabel("* Isi dengan angka!");
warn3.setForeground(Color.red);
warn3.setBounds(330, 120, 200, 25);
warn3.setVisible(false);
this.add(warn3);
JLabel warn4 = new JLabel("* Isi dengan angka!");
warn4.setForeground(Color.red);
warn4.setBounds(330, 180, 200, 25);
warn4.setVisible(false);
this.add(warn4);
//Textfield NIK penumpang
JLabel nik = new JLabel();
nik.setText("NIK Penumpang");
nik.setFont(new Font("Tahoma", Font.BOLD, 17));
nik.setForeground(Color.decode("#f9dcc4"));
nik.setBounds(20, 120, 300, 25);
this.add(nik);
JTextField isiNik = new JTextField();
isiNik.setFont(new Font("Tahoma", Font.PLAIN, 15));
isiNik.setEditable(true);
isiNik.setBackground(Color.decode("#ecf39e"));
isiNik.setBounds(20, 150, 300, 25);
this.add(isiNik);
//Textfield No Handphone
JLabel noHP = new JLabel();
noHP.setText("No HP Penumpang");
noHP.setFont(new Font("Tahoma", Font.BOLD, 17));
noHP.setForeground(Color.decode("#f9dcc4"));
noHP.setBounds(20, 180, 300, 25);
this.add(noHP);
JTextField isiNoHP = new JTextField();
isiNoHP.setFont(new Font("Tahoma", Font.PLAIN, 15));
isiNoHP.setEditable(true);
isiNoHP.setBackground(Color.decode("#ecf39e"));
isiNoHP.setBounds(20, 210, 300, 25);
this.add(isiNoHP);
//Dropdown titik awal
JLabel awal = new JLabel();
awal.setText("Titik Awal");
awal.setFont(new Font("Tahoma", Font.BOLD, 17));
awal.setForeground(Color.decode("#f9dcc4"));
awal.setBounds(425, 60, 300, 25);
this.add(awal);
JComboBox<String> tAwal = new JComboBox<>(new String[]{"Wilangan", "Ngawi", "Gendingan", "Solo", "Kartosuro", "Jogja", "Magelang"});
tAwal.setFont(new Font("Tahoma", Font.PLAIN, 15));
tAwal.setBounds(425, 90, 300, 25);
tAwal.setBackground(Color.decode("#ecf39e"));
this.add(tAwal);
//Dropdown titik akhir
JLabel akhir = new JLabel();
akhir.setText("Titik Akhir");
akhir.setFont(new Font("Tahoma", Font.BOLD, 17));
akhir.setForeground(Color.decode("#f9dcc4"));
akhir.setBounds(425, 120, 300, 25);
this.add(akhir);
JComboBox<String> tAkhir = new JComboBox<>(new String[]{"Wilangan", "Ngawi", "Gendingan", "Solo", "Kartosuro", "Jogja", "Magelang"});
tAkhir.setFont(new Font("Tahoma", Font.PLAIN, 15));
tAkhir.setBounds(425, 150, 300, 25);
tAkhir.setBackground(Color.decode("#ecf39e"));
titik[1] = Objects.requireNonNull(tAkhir.getSelectedItem()).toString();
this.add(tAkhir);
//Harga
JLabel harga = new JLabel();
harga.setText("Harga / Tiket");
harga.setFont(new Font("Tahoma", Font.BOLD, 17));
harga.setForeground(Color.decode("#f9dcc4"));
harga.setBounds(315, 280, 300, 25);
this.add(harga);
//Text Harga
JTextArea display = new JTextArea();
display.setFont(new Font("Tahoma", Font.PLAIN, 15));
display.setText("Rp. "+p.getHarga(Objects.requireNonNull(tAwal.getSelectedItem()).toString(), tAkhir.getSelectedItem().toString())+",000");
display.setEditable(false);
display.setBackground(Color.decode("#ecf39e"));
display.setBounds(315, 310, 115, 25);
p.setHarga(p.getHarga(tAwal.getSelectedItem().toString(), tAkhir.getSelectedItem().toString()));
this.add(display);
//cekRute
JLabel warning = new JLabel();
warning.setVisible(false);
warning.setFont(new Font("Tahoma", Font.BOLD, 12));
warning.setForeground(Color.red);
warning.setBounds(400, 240, 375, 25);
boolean[] t = {false};
this.add(warning);
//Label jml tiket
JLabel jml = new JLabel("Jumlah Tiket");
jml.setForeground(Color.decode("#f9dcc4"));
jml.setBounds(425,180,300,25);
jml.setFont(new Font("Tahoma", Font.BOLD, 17));
this.add(jml);
//Panel jml tiket
JLabel showJumlah = new JLabel (String.valueOf(jumlah[0]));
showJumlah.setFont(new Font("Tahoma", Font.PLAIN, 15));
showJumlah.setForeground(Color.black);
showJumlah.setBounds(425, 210, 100, 25);
showJumlah.setVisible(true);
this.add(showJumlah);
JPanel jmlTiket = new JPanel();
jmlTiket.setLayout(null);
jmlTiket.setBounds(425, 210, 200, 25);
jmlTiket.setBackground(Color.decode("#ecf39e"));
this.add(jmlTiket);
//tombol buat nambah/nurunin jumlah tiket
JButton tambah = new JButton("^");
tambah.setFont(new Font("Tahoma", Font.BOLD, 17));
tambah.setForeground(Color.decode("#f9dcc4"));
tambah.setBackground(Color.decode("#4a4e69"));
tambah.setBorder(BorderFactory.createLineBorder(Color.black));
tambah.setBounds(625,209,50,27);
this.add(tambah);
tambah.addActionListener(e -> {
if(jumlah[0]==40){
showJumlah.setText(String.valueOf(jumlah[0]));
}
else {
jumlah[0]++;
showJumlah.setText(String.valueOf(jumlah[0]));
}
});
JButton turun = new JButton("v");
turun.setFont(new Font("Tahoma", Font.BOLD, 17));
turun.setForeground(Color.decode("#f9dcc4"));
turun.setBackground(Color.decode("#4a4e69"));
turun.setBorder(BorderFactory.createLineBorder(Color.black));
turun.setBounds(675,209,50,27);
this.add(turun);
turun.addActionListener(e -> {
if(jumlah[0]==0){
showJumlah.setText(String.valueOf(jumlah[0]));
}
else {
jumlah[0]--;
showJumlah.setText(String.valueOf(jumlah[0]));
}
});
ActionListener cekRute = e -> {
titik[0] = (String) tAwal.getSelectedItem();
titik[1] = (String) tAkhir.getSelectedItem();
String fromCity = tAwal.getSelectedItem().toString();
String toCity = tAkhir.getSelectedItem().toString();
String c = p.checkRoute(tAwal.getSelectedItem().toString(), tAkhir.getSelectedItem().toString());
warning.setText(c);
warning.setVisible(true);
t[0] = c.equals(" ");
};
tAwal.addActionListener(cekRute);
tAkhir.addActionListener(cekRute);
int[] price = {0};
ActionListener updateHarga = e -> {
String fromCity = tAwal.getSelectedItem().toString();
String toCity = tAkhir.getSelectedItem().toString();
price[0] = p.getHarga(fromCity, toCity);
display.setText("Rp. " + price[0]);
};
tAwal.addActionListener(updateHarga);
tAkhir.addActionListener(updateHarga);
// button lihat layout bis
JButton layout = new JButton();
layout.setText("Pilih Kursi");
layout.setForeground(Color.decode("#f9dcc4"));
layout.setBackground(Color.decode("#4a4e69"));
layout.setBounds(600, 390, 150, 40);
this.add(layout);
//Label warning belom diisi
JLabel[] warn = new JLabel[5];
for(int i=0;i<warn.length;i++) {
warn[i] = new JLabel();
warn[i].setFont(new Font("Tahoma", Font.BOLD, 12));
warn[i].setForeground(Color.red);
if(i<3) {
warn[i].setText("* Isi ini terlebih dahulu");
}
else{
warn[i].setText("* Isi dengan angka");
}
this.add(warn[i]);
warn[i].setVisible(false);
}
warn[0].setBounds(180, 60, 200, 25);
warn[1].setBounds(180, 120, 200, 25);
warn[2].setBounds(180, 180, 200, 25);
warn[3].setBounds(180, 120, 200, 25);
warn[4].setBounds(180, 180, 200, 25);
this.setVisible(true);
ImageIcon icon = new ImageIcon("C:\\Users\\adksp\\IdeaProjects\\StudyCase\\out\\Green Beige Organic Illustrative Brainstorm Presentation.png");
Image img = icon.getImage().getScaledInstance(450, 300, Image.SCALE_SMOOTH);
ImageIcon scaledIcon = new ImageIcon(img);
JLabel[] gambar = new JLabel[3];
int x3 = -100;
for (int i = 0; i < 3; i++) {
gambar[i] = new JLabel(scaledIcon);
gambar[i].setBounds(x3, 250, 450, 300);
this.add(gambar[i]);
x3+=175;
}
this.setVisible(true);
// Buka layout page
layout.addActionListener(e -> {
boolean[] b = {false, false};
//cek apkah isi nik mengandung huruf alphabet
for (String s : alphabet) {
if (!(isiNik.getText().toUpperCase().contains(s))) {
b[0] = false;
break;
}
}
//cek apkah isi nik sudah tidak mengandung huruf alphabet
for (String s : alphabet) {
if (!(isiNoHP.getText().toUpperCase().contains(s))) {
b[1] = false;
break;
}
}
//munculin si warning letter
warn3.setVisible(b[0]);
warn4.setVisible(b[1]);
if (isiNama.getText().isEmpty()) {
warn[0].setVisible(true);
}
else{
warn[0].setVisible(false);
}
if (isiNik.getText().isEmpty()) {
warn[1].setVisible(true);
}
else{
warn[1].setVisible(false);
for (String s : alphabet) {
if (isiNik.getText().toUpperCase().contains(s)) {
b[0] = true;
break;
}
if (!(isiNik.getText().toUpperCase().contains(s))) {
b[0] = false;
break;
}
}
warn[3].setVisible(b[0]);
}
if (isiNoHP.getText().isEmpty()) {
warn[2].setVisible(true);
}
else{
warn[2].setVisible(false);
for (String s : alphabet) {
if (isiNoHP.getText().toUpperCase().contains(s)) {
b[1] = true;
break;
}
}
warn[4].setVisible(b[1]);
}
if (!Objects.equals(isiNama.getText(), "") && !Objects.equals(isiNoHP.getText(), "") && !Objects.equals(isiNik.getText(), "")) {
if (t[0] && !b[0] && !b[1]) {
nik1[0] = Long.parseLong(isiNik.getText());
no[0] = Long.parseLong(isiNoHP.getText());
new Bis(isiNama.getText(), nik1[0], no[0], titik[0], titik[1], price[0], jumlah[0]);
this.setVisible(false);
this.dispose();
}
}
});
}
}