-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathResetFrame.java
More file actions
executable file
·105 lines (85 loc) · 3.04 KB
/
ResetFrame.java
File metadata and controls
executable file
·105 lines (85 loc) · 3.04 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
/**Class for window that opens when the user clicks on the reset button in the menu bar.
* This window pops up to ensure that the user wants to clear the data.*/
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class ResetFrame extends JFrame {
//fields to hold the panels
private JPanel resetPanel;
private JPanel noPanel;
private JPanel centerPanel;
private JPanel headerPanel;
//field to hold the data object that will be passed into the constructor
private OverallVote voteData;
//constants that are used to set the size of the window
private final int WINDOW_WIDTH=300;
private final int WINDOW_HEIGHT=100;
/**Constructor that will create the window.
* @param n the OverallVote object that holds all of the voting data*/
public ResetFrame(OverallVote n)
{
voteData = n;
//set the title and the size of the window
setTitle("Reset");
setSize(WINDOW_WIDTH,WINDOW_HEIGHT);
//create the JPanels
resetPanel = new JPanel();
noPanel = new JPanel();
centerPanel = new JPanel();
headerPanel = new JPanel();
//set the layout of the content pane and the JPanels
setLayout(new BorderLayout());
centerPanel.setLayout(new FlowLayout());
//create buttons to show on the screen and register with a listener class
JButton item;
item = new JButton("Yes");
item.addActionListener(new ButtonListener());
resetPanel.add(item);
item = new JButton("No");
item.addActionListener(new ButtonListener());
noPanel.add(item);
//create text to add to the top of the window and add to headerPanel object
JLabel item1 = new JLabel("Are you want to reset the program?");
headerPanel.add(item1);
//add the panels to appropriate panels and content panes
centerPanel.add(resetPanel);
centerPanel.add(noPanel);
add(headerPanel,BorderLayout.NORTH);
add(centerPanel,BorderLayout.CENTER);
//remove the decorations from the window so the user has to click one of the buttons
setUndecorated(true);
//set the window to visible
setVisible(true);
}
/**Private inner class that is registered to the buttons in the window*/
private class ButtonListener implements ActionListener
{
/**Method that must be overriden to respond to the events fired by the program
* @param e the actionEvent object that is fired*/
public void actionPerformed(ActionEvent e)
{
//if statements to determine which button fired the event
if(e.getActionCommand().equals("Yes"))
{
//reset the data in the OverallVote object
voteData = new OverallVote();
//change saved variable to false, because data was changed
voteData.changeSaved(false);
//send the program back to the home screen and close the current screen
new HomeFrame(voteData);
dispose();
}
else if(e.getActionCommand().equals("No"))
{
//send the program back to the home screen and close the current screen
new HomeFrame(voteData);
dispose();
}
else
{
JOptionPane.showMessageDialog(null, "Problem with program. Terminating program.");
System.exit(0);
}
}
}
}