-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCategory_Disp.java
139 lines (123 loc) · 5.45 KB
/
Category_Disp.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
// Import Statements
import java.io.*;
import java.util.*;
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import layout.TableLayout;
import javax.swing.Timer;
/**
* This class creates and displays the Dialog box for the User to see the Category of the Upcoming Questions and
* the amount it is worth and the amount they have won.
*
* @author (Taranveer Virk && Gurbir Dhulla)
* @version (v.1 12JAN2011)
*/
public class Category_Disp extends Millionaire // name of the class
{
// Variables Declared
static ImagePanel catP;
static JDialog catDisp = new JDialog ();
static String catBG = "images/Category.jpg";
private static double size [][] = {{0.07, TableLayout.FILL, 0.07}, {0.05, 0.09, 0.005, 0.09, 0.005, 0.09, 0.005, 0.1, 0.15, 0.175, 0.0199, 0.175}};
static TransparentButton continueB = new TransparentButton ("");
static TransparentButton walkAwayB = new TransparentButton ("");
static JLabel continueL = new JLabel ("Continue");
static JLabel walkAwayL = new JLabel ("Walk Away");
static JLabel catL = new JLabel ("");
static JLabel amtL = new JLabel ("");
static JLabel bankL = new JLabel ("");
static TransparentButtonHandler handlerC = new TransparentButtonHandler ();
/**
* This method is used create the Dialog and display it on the Screen
*
* @param cat String that contains the Category of the Next Upcoming Question
* @param amt String Containing the Amount the Next Question is Worth
* @param bank String containing the Amount the user has won.
*/
public static void disp (String cat, String amt, String bank) throws IOException
{
{
// Adding Buttons to ButtonHandler
continueB.addActionListener (handlerC);
walkAwayB.addActionListener (handlerC);
// Setting properties of Main Menu Panel
catP = new ImagePanel(new ImageIcon(catBG).getImage());
catP.setLayout (new TableLayout (size));
catP.setOpaque (false);
catP.setVisible (true);
// Setting Font Properties of Labels - Font, Font Size, Font Style, Color.
catL.setText ("Category: " + cat);
amtL.setText ("Amount: " + amt);
bankL.setText ("Bank: " + bank);
continueL.setFont (new Font("Serif", Font.BOLD, 20));
continueL.setForeground (Color.WHITE);
walkAwayL.setFont (new Font("Serif", Font.BOLD, 20));
walkAwayL.setForeground (Color.WHITE);
catL.setFont (new Font("Serif", Font.BOLD, 20));
catL.setForeground (Color.WHITE);
amtL.setFont (new Font("Serif", Font.BOLD, 20));
amtL.setForeground (Color.WHITE);
bankL.setFont (new Font("Serif", Font.BOLD, 20));
bankL.setForeground (Color.WHITE);
// Adding Components (Buttons and Labels) to ImagePanel
catP.add (catL, "1, 1, c, c");
catP.add (amtL, "1, 3, c, c");
catP.add (bankL, "1, 7, c, c");
catP.add (continueB, "1, 9");
catP.add (continueL, "1, 9, c, c");
catP.add (walkAwayB, "1, 11");
catP.add (walkAwayL, "1, 11, c, c");
}
/*
* Setting Up the Dialog and Displaying It
*/
{
catDisp.setUndecorated(true); // Hides the Top Bar
catDisp.setContentPane (catP); // Adding Panel to Dialog
catDisp.pack(); // Packs the Dialog
catDisp.validate(); // Validates the Dialog
catDisp.setModal (true);
catDisp.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); // Disables the Close Button
catDisp.setLocationRelativeTo(null); // Centers Panel on Screen
catDisp.setVisible(true); // Makes Dialog Visible
catDisp.setResizable (false); // Disables the Maximize Button :)
}
}
/**
* This class handles the events by the Buttons. Executes the Appropriate Code based on the Button clicked
*/
private static class TransparentButtonHandler implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
if (event.getSource () == continueB) // Continue Button
{
if (q <= 4)
timeRemaining = 15;
else if (q > 4 && q <= 9)
timeRemaining = 30;
else if (q > 9 && q < 14)
timeRemaining = 45;
else if (q == 14)
timeRemaining = timeBanked;
time.setText(String.valueOf(timeRemaining));
timer.start();
catDisp.dispose();
}
else if (event.getSource () == walkAwayB) // Walk Away Button
{
user = 0;
playPan.setVisible (false);
winningL.setText (amount [q]);
winningBG = "images/Winning_" + bg + ".jpg";
winningP.update (new ImageIcon (winningBG).getImage());
winningP.updateUI();
winningP.setVisible (true);
winningMP3.play();
catDisp.dispose();
}
}
}
}