-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCodeCrackerInstructionsPanel.java
More file actions
135 lines (112 loc) · 4.55 KB
/
CodeCrackerInstructionsPanel.java
File metadata and controls
135 lines (112 loc) · 4.55 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
/**
* FILE: CodeCrackerInstructionsPanel.java
* AUTHORS: Clara Smith and Cali Stenson
* DATE: Dec 3 2013
* MODIFIED: Dec 3 2013
*
* CodeCrackerInstructionsPanel provides instructions on how to play the game.
*/
// import declarations
import java.util.*;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.io.File;
import java.io.IOException;
import javax.swing.filechooser.FileFilter;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
public class CodeCrackerInstructionsPanel extends JPanel {
// instance vars
private JButton caesarButton, vigButton, affineButton, hillButton, otherButton;
private ImagePanel instructionsPanel;
private BufferedImage alphabetImage;
private JLabel alphabetLabel;
// preferred sizes
private final int WIDTH = 950, HEIGHT = 750;
// constructor
public CodeCrackerInstructionsPanel () {
// sets up visuals
setLayout(new BorderLayout());
this.setBackground(Color.BLACK); // sets background color
this.setPreferredSize(new Dimension(WIDTH, HEIGHT)); // sets the size of the panel
instructionsPanel = new ImagePanel(new ImageIcon("Images/Instructions.png").getImage());
instructionsPanel.setLayout(new GridLayout(3, 4));
instructionsPanel.setOpaque(false);
// create and stylize new componenets
//button for info for caesar cipher
caesarButton = new JButton("");
caesarButton.setOpaque(false);
caesarButton.setContentAreaFilled(false);
caesarButton.setBorderPainted(false);
//button for info for caesar cipher
vigButton = new JButton("");
vigButton.setOpaque(false);
vigButton.setContentAreaFilled(false);
vigButton.setBorderPainted(false);
//button for info for caesar cipher
affineButton = new JButton("");
affineButton.setOpaque(false);
affineButton.setContentAreaFilled(false);
affineButton.setBorderPainted(false);
//button for info for caesar cipher
hillButton = new JButton("");
hillButton.setOpaque(false);
hillButton.setContentAreaFilled(false);
hillButton.setBorderPainted(false);
CodeCrackerInstructionsPanelListener listener = new CodeCrackerInstructionsPanelListener(); //creates listener
//adds listener to buttons
caesarButton.addActionListener(listener);
vigButton.addActionListener(listener);
affineButton.addActionListener(listener);
hillButton.addActionListener(listener);
// add everything to frame
//initializes 8 instances of other button
//sets invisible and then adds to frame
//this is for the purpose of allowed other four
//buttons to align with image
//these buttons have no functional purpose
for (int x = 0; x < 8; x ++) {
otherButton = new JButton("");
otherButton.setOpaque(false);
otherButton.setContentAreaFilled(false);
otherButton.setBorderPainted(false);
instructionsPanel.add(otherButton);
}
instructionsPanel.add(caesarButton);
instructionsPanel.add(vigButton);
instructionsPanel.add(affineButton);
instructionsPanel.add(hillButton);
this.add(instructionsPanel, BorderLayout.LINE_START);
}
//Listener for CodeCrackerInstructionsPanel
private class CodeCrackerInstructionsPanelListener implements ActionListener {
public void actionPerformed(ActionEvent event) {
if (event.getSource() == caesarButton || event.getSource() == vigButton
|| event.getSource() == affineButton || event.getSource() == hillButton) {
File instructions;
if (event.getSource() == caesarButton) {
instructions = new File("Content/Caesar.txt");
} else if (event.getSource() == vigButton) {
instructions = new File("Content/Vigenere.txt");
} else if (event.getSource() == affineButton) {
instructions = new File("Content/Affine.txt");
} else { // if (event.getSource() == hillButton)
instructions = new File("Content/Hill.txt");
}
try {
String content = new Scanner(instructions).useDelimiter("\\A").next();
alphabetImage = ImageIO.read(new File("Images/alphabet.png"));
alphabetLabel = new JLabel(new ImageIcon(alphabetImage));
JOptionPane.showMessageDialog(null, content);
JOptionPane.showMessageDialog(null, alphabetLabel, "Alphabet Key", JOptionPane.PLAIN_MESSAGE, null);
} catch (IOException e) {
System.out.println("**ERROR**: " + e);
}
}
}
}
}