-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPanelLauncher (13).java
More file actions
1115 lines (1008 loc) · 51.5 KB
/
Copy pathPanelLauncher (13).java
File metadata and controls
1115 lines (1008 loc) · 51.5 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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.awt.Color;
import javax.swing.ImageIcon;
public class PanelLauncher extends JFrame {
private JPanel panel0;
private JPanel panel1;
private JPanel panel2;
private JPanel panel3;
private JPanel panel4;
private JPanel panel5;
private JPanel panel6;
private JPanel panel7;
private JPanel panel8;
private JPanel panel9;
private JPanel panel10;
private JPanel gameOverPanel;
private int healthPoints = 100; // Initialize healthPoints to 100
JLabel healthLabel1;
JLabel healthLabel2;
JLabel healthLabel3;
JLabel healthLabel4;
JLabel healthLabel5;
JLabel healthLabel6;
JLabel healthLabel7;
JLabel healthLabel8;
JLabel healthLabel9;
public PanelLauncher() {
panel0 = new StartPanel();
panel1 = new FirstPanel();
panel2 = new SecondPanel();
panel3 = new ThirdPanel();
panel4 = new FourthPanel();
panel5 = new FifthPanel();
panel6 = new SixthPanel();
panel7 = new SeventhPanel();
panel8 = new EighthPanel();
panel9 = new NinthPanel();
panel10 = new LastPanel();
gameOverPanel = new GameOverPanel();
setPreferredSize(new Dimension(669, 455)); // Increased the height to accommodate health points
setLayout(new CardLayout());
add(panel0, "Panel0");
add(panel1, "panel1");
add(panel2, "panel2");
add(panel3, "panel3");
add(panel4, "panel4");
add(panel5, "panel5");
add(panel6, "panel6");
add(panel7, "panel7");
add(panel8, "panel8");
add(panel9, "panel9");
add(panel10, "panel10");
add(gameOverPanel, "gameOverPanel");
showPanel("panel0");
}
private void showPanel(String panelName) {
CardLayout cardLayout = (CardLayout) getContentPane().getLayout();
cardLayout.show(getContentPane(), panelName);
}
public static void main(String[] args) {
PanelLauncher frame = new PanelLauncher();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);
ImageIcon image = new ImageIcon("C:/Users/vidya/Downloads/VIDS GAME.png");
frame.setIconImage(image.getImage());
}
public class StartPanel extends JPanel {
private JLabel imageLabel;
private JTextArea jcomp1;
private JButton jcomp5;
public StartPanel() {
// Construct components
imageLabel = new JLabel();
jcomp1 = new JTextArea();
jcomp5 = new JButton("START");
// Set layout to BorderLayout
setLayout(new BorderLayout());
// Create a container JPanel to hold the components vertically centered
JPanel containerPanel = new JPanel();
containerPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.fill = GridBagConstraints.HORIZONTAL;
constraints.anchor = GridBagConstraints.CENTER;
constraints.insets = new Insets(10, 10, 10, 10);
// Add imageLabel to the container panel
constraints.gridx = 2;
constraints.gridy = 0;
containerPanel.add(imageLabel, constraints);
// Add jcomp1 to the container panel
constraints.gridy = 1;
containerPanel.add(jcomp1, constraints);
// Set properties for the JTextArea (jcomp1)
jcomp1.setText("Hey Pal! Vidya welcomes you to the FIND THE KEY game.YOU ARE LOCKED IN A ROOM. Answer the questions, find the key to the door and escape.\n" +
"Rules are simple: give correct answers to get +13 health points, wrong answers deduct -50 health points. If you fail any of the challenges, it's not too late to start again! ;-) ");
jcomp1.setWrapStyleWord(true);
jcomp1.setLineWrap(true);
jcomp1.setEditable(false);
jcomp1.setBackground(new Color(0, 0, 0, 0));
jcomp1.setFont(new Font("Arial", Font.PLAIN, 16));
// Add the container panel to the center of StartPanel
add(containerPanel, BorderLayout.CENTER);
// Add jcomp5 to the south of StartPanel
add(jcomp5, BorderLayout.SOUTH);
// Set the image for imageLabel
ImageIcon imageIcon = new ImageIcon("C:/Users/vidya/Desktop/findthekey.jpeg");
imageLabel.setIcon(imageIcon);
// Add action listener to jcomp5
jcomp5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
showPanel("panel1");
}
});
}
}
private class GameOverPanel extends JPanel {
public GameOverPanel() {
ImageIcon image = new ImageIcon("C:/Users/vidya/Desktop/gameover.png");
JLabel label = new JLabel(" YOU ARE DEAD !! ", image, JLabel.CENTER);
label.setHorizontalTextPosition(JLabel.CENTER);
label.setVerticalTextPosition(JLabel.BOTTOM);
label.setIconTextGap(-5);
label.setForeground(Color.BLACK);
label.setFont(new Font("Georgia", Font.BOLD, 30));
setLayout(new BorderLayout()); // Set the layout manager to BorderLayout
add(label, BorderLayout.CENTER); // Add the label to the center of the panel
}
}
private class FirstPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JButton jcomp6;
// private JLabel healthLabel1;
public FirstPanel() {
// Construct components
jcomp1 = new JButton("1. Polymorphism");
jcomp2 = new JButton("2. Inheritance");
jcomp3 = new JButton("3. Abstraction");
jcomp4 = new JLabel("Which of the following concepts promotes the idea of 'code once, reuse many times'? ");
jcomp5 = new JLabel("");
healthLabel1 = new JLabel("Health Points: " + healthPoints);
jcomp6 = new JButton("Back");
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel1);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(205, 145, 275, 20);
jcomp2.setBounds(205, 180, 275, 20);
jcomp3.setBounds(205, 210, 275, 20);
jcomp4.setBounds(95, 100, 900, 20);
jcomp5.setBounds(120, 35, 525, 20);
jcomp6.setBounds(500, 345, 80, 30);
healthLabel1.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp6.addActionListener(new ActionListener() {
// Back Button
public void actionPerformed(ActionEvent e) {
showPanel("Panel0");
}
});
jcomp2.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel2");
}
});
jcomp1.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp3.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class SecondPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private JLabel healthLabel2;
// private int healthPoints = 100; // Initial health points
public SecondPanel() {
// Construct components
jcomp1 = new JButton("1. It cannot be instantiated but provides a common base for subclasses");
jcomp2 = new JButton("2. It is a final class that cannot be extended");
jcomp3 = new JButton("3. It is a class with only static methods and variables");
jcomp4 = new JLabel("Good start !");
jcomp5 = new JLabel("Which of the following best describes the purpose of an abstract class in Java ?");
jcomp6 = new JLabel("");
healthLabel2 = new JLabel("Health Points: " + healthPoints);
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel2);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(100, 145, 475, 20);
jcomp2.setBounds(100, 180, 475, 20);
jcomp3.setBounds(100, 215, 475, 20);
jcomp4.setBounds(285, 50, 185, 15);
jcomp5.setBounds(100, 80, 485, 20);
jcomp6.setBounds(250, 180, 275, 25);
healthLabel2.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp1.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel3");
}
});
jcomp2.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
// showPanel("panel1");
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp3.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class ThirdPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private JLabel healthLabel3;
public ThirdPanel() {
// Construct components
jcomp1 = new JButton("1. Object encapsulation");
jcomp2 = new JButton("2. Object composition");
jcomp3 = new JButton("3. Object polymorphism");
jcomp4 = new JLabel("");
jcomp5 = new JLabel("In object-oriented programming, ");
jcomp6 = new JLabel("what is the term used to describe the ability of an object to contain instances of other objects?");
healthLabel3 = new JLabel("Health Points: " + healthPoints);
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel3);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(205, 145, 275, 20);
jcomp2.setBounds(205, 180, 275, 20);
jcomp3.setBounds(205, 215, 275, 20);
jcomp4.setBounds(220, 20, 235, 20);
jcomp5.setBounds(255, 27, 385, 20);
jcomp6.setBounds(80, 30, 600, 100);
healthLabel3.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp2.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel4");
}
});
jcomp1.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp3.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class FourthPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private int healthPoints = 100; // Initial health points
public FourthPanel() {
// Construct components
jcomp1 = new JButton("1. Concrete class");
jcomp2 = new JButton("2. Static class");
jcomp3 = new JButton("3. Sealed class");
jcomp4 = new JLabel("What is the term used to describe a class that is derived from an abstract class and ");
jcomp5 = new JLabel("provides implementation for all its abstract methods?");
jcomp6 = new JLabel(" ");
healthLabel4 = new JLabel("Health Points: " + healthPoints);
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel4);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(205, 145, 275, 20);
jcomp2.setBounds(205, 180, 275, 20);
jcomp3.setBounds(205, 215, 275, 20);
jcomp4.setBounds(100, 40, 985, 15);
jcomp5.setBounds(200, 60, 385, 20);
jcomp6.setBounds(250, 75, 275, 25);
healthLabel4.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp1.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel5");
}
});
jcomp2.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp3.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class FifthPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private JLabel healthLabel2;
// private int healthPoints = 100; // Initial health points
public FifthPanel() {
// Construct components
jcomp1 = new JButton("1. final");
jcomp2 = new JButton("2. abstract");
jcomp3 = new JButton("3. static");
jcomp4 = new JLabel("");
jcomp5 = new JLabel("In Java, ");
jcomp6 = new JLabel(" which keyword is used to prevent a method from being overridden in a subclass?");
healthLabel5 = new JLabel("Health Points: " + healthPoints);
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel5);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(205, 145, 275, 20);
jcomp2.setBounds(205, 180, 275, 20);
jcomp3.setBounds(205, 215, 275, 20);
jcomp4.setBounds(240, 10, 185, 15);
jcomp5.setBounds(315, 30, 385, 20);
jcomp6.setBounds(100, 55, 675, 25);
healthLabel5.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp1.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel6");
}
});
jcomp2.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp3.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class SixthPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private JLabel healthLabel2;
// private int healthPoints = 100; // Initial health points
public SixthPanel() {
// Construct components
jcomp1 = new JButton("1. Inheritance");
jcomp2 = new JButton("2. Polymorphism");
jcomp3 = new JButton("3. Encapsulation");
jcomp4 = new JLabel("");
jcomp5 = new JLabel("What is the term used to describe the ability of an object to exhibit ");
jcomp6 = new JLabel("different behaviors based on its data type? ");
healthLabel6 = new JLabel("Health Points: " + healthPoints);
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel6);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(205, 145, 275, 20);
jcomp2.setBounds(205, 180, 275, 20);
jcomp3.setBounds(205, 215, 275, 20);
jcomp4.setBounds(240, 10, 185, 15);
jcomp5.setBounds(150, 30, 685, 20);
jcomp6.setBounds(205, 45, 275, 25);
healthLabel6.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp2.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel7");
}
});
jcomp1.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp3.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class SeventhPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private JLabel healthLabel2;
// private int healthPoints = 100; // Initial health points
public SeventhPanel() {
// Construct components
jcomp1 = new JButton("1. Object instantiation");
jcomp2 = new JButton("2. Object aggregation");
jcomp3 = new JButton("3. Object composition");
jcomp4 = new JLabel("");
jcomp5 = new JLabel("What is the term used to describe the process of creating objects of a class within the same class?");
jcomp6 = new JLabel(" ");
healthLabel7 = new JLabel("Health Points: " + healthPoints);
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel7);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(205, 145, 275, 20);
jcomp2.setBounds(205, 180, 275, 20);
jcomp3.setBounds(205, 215, 275, 20);
jcomp4.setBounds(240, 10, 185, 15);
jcomp5.setBounds(80, 60, 685, 20);
jcomp6.setBounds(250, 55, 275, 25);
healthLabel7.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp3.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel8");
}
});
jcomp1.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp2.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class EighthPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private JLabel healthLabel2;
// private int healthPoints = 100; // Initial health points
public EighthPanel() {
// Construct components
jcomp1 = new JButton("1.int");
jcomp2 = new JButton("2. double");
jcomp3 = new JButton("3. class");
jcomp4 = new JLabel("");
jcomp5 = new JLabel("In Java, which of the following is NOT a primitive data type?");
jcomp6 = new JLabel(" ");
healthLabel8 = new JLabel("Health Points: " + healthPoints);
// Adjust size and set layout
setPreferredSize(new Dimension(669, 395));
setLayout(null);
// Add components
add(jcomp1);
add(jcomp2);
add(jcomp3);
add(jcomp4);
add(jcomp5);
add(jcomp6);
add(healthLabel8);
// Set component bounds (only needed by Absolute Positioning)
jcomp1.setBounds(205, 145, 275, 20);
jcomp2.setBounds(205, 180, 275, 20);
jcomp3.setBounds(205, 215, 275, 20);
jcomp4.setBounds(240, 10, 185, 15);
jcomp5.setBounds(165, 30, 385, 20);
jcomp6.setBounds(250, 55, 275, 25);
healthLabel8.setBounds(50, 360, 200, 20); // Added healthLabel position
jcomp3.addActionListener(new ActionListener() {
// Correct Answer
public void actionPerformed(ActionEvent e) {
healthPoints += 13; // Add 13 health points for the correct answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
showPanel("panel9");
}
});
jcomp2.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
jcomp1.addActionListener(new ActionListener() {
// Wrong Answer
public void actionPerformed(ActionEvent e) {
healthPoints -= 50; // Remove 30 health points for the wrong answer
healthLabel1.setText("Health Points: " + healthPoints);
healthLabel2.setText("Health Points: " + healthPoints);
healthLabel3.setText("Health Points: " + healthPoints);
healthLabel4.setText("Health Points: " + healthPoints);
healthLabel5.setText("Health Points: " + healthPoints);
healthLabel6.setText("Health Points: " + healthPoints);
healthLabel7.setText("Health Points: " + healthPoints);
healthLabel8.setText("Health Points: " + healthPoints);
healthLabel9.setText("Health Points: " + healthPoints);
if (healthPoints <= 0) {
showPanel("gameOverPanel"); // Redirect to Game Over panel
} else {
showPanel("panel1");
}
}
});
}
}
private class NinthPanel extends JPanel {
private JButton jcomp1;
private JButton jcomp2;
private JButton jcomp3;
private JLabel jcomp4;
private JLabel jcomp5;
private JLabel jcomp6;
// private int healthPoints = 100; // Initial health points
public NinthPanel() {
// Construct components
jcomp1 = new JButton("1. 200");
jcomp2 = new JButton("2. do sarkar ");