public class GUI extends Main2 implements ActionListener
{
JFrame FrameTest = new JFrame();
JFrame FrameforInput = new JFrame();
JFrame FrameforChoice = new JFrame();
JButton Atbash = new JButton("Atbash");
JButton CaesarShift = new JButton("Caesar Shift");
JButton ROT13 = new JButton("ROT13");
JButton Vigenere = new JButton("Vigenere");
JButton Return = new JButton("Return");
JTextField Input;
JTextField Output;
JTextField Input2;
private Enigma panel1;
JPanel outFieldPane= new JPanel();
JPanel InputPanel = new JPanel();
JButton submitButton = new JButton("Submit");
boolean buttonRemove;
JLabel KeyLabel = new JLabel("Key:", SwingConstants.RIGHT);
public static String plaintext, str, ciphertext, text;
void initializeGui()
{
buttonRemove = false;
//Create the FrameforChoice
FrameforChoice.setSize(1250,2000);
FrameforChoice.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FrameforChoice.setLayout(new FlowLayout());
//Create the FrameforInput
FrameforInput.setSize(1000,1000);
FrameforInput.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
FrameforInput.setLayout(new BorderLayout());
//Add buttons for the FrameforChoice
FrameforChoice.add(Atbash);
FrameforChoice.add(CaesarShift);
FrameforChoice.add(ROT13);
FrameforChoice.add(Vigenere);
//Add ActionListener to Buttons
Atbash.addActionListener(this);
CaesarShift.addActionListener(this);
ROT13.addActionListener(this);
Vigenere.addActionListener(this);
//Build the TextBoxes
Input2 = new JTextField(250);
Input = new JTextField(250);
Input.setEditable(true);
Input2.setEditable(true);
Output = new JTextField(ciphertext,250);
//Add the panel for the input
InputPanel.setLayout(new GridLayout(1,2));
InputPanel.add(new JLabel("Input:",SwingConstants.RIGHT));
InputPanel.add(Input);
Input.addActionListener(this);
FrameforInput.add(InputPanel,BorderLayout.NORTH);
//Add the panel for the submit data button
submitButton.addActionListener(this);
InputPanel.add(submitButton);
//Add the panel for the output
outFieldPane.setLayout(new GridLayout(1,2));
outFieldPane.add(new JLabel("Output:",SwingConstants.RIGHT));
outFieldPane.add(Output);
FrameforInput.add(outFieldPane,BorderLayout.SOUTH);
//Return button for FrameforInput and add an AvtionListener
outFieldPane.add(Return);
Return.addActionListener(this);
//Set Visibility of certain things
FrameforChoice.setVisible(true);
FrameforInput.setVisible(false);
//Adding the Enigma image
panel1 = new Enigma();
panel1.setSize(1000,800);
FrameforInput.add(panel1);
import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.lang.Object; import javax.swing.*;
public class GUI extends Main2 implements ActionListener { JFrame FrameTest = new JFrame(); JFrame FrameforInput = new JFrame(); JFrame FrameforChoice = new JFrame(); JButton Atbash = new JButton("Atbash"); JButton CaesarShift = new JButton("Caesar Shift"); JButton ROT13 = new JButton("ROT13"); JButton Vigenere = new JButton("Vigenere"); JButton Return = new JButton("Return"); JTextField Input; JTextField Output; JTextField Input2; private Enigma panel1; JPanel outFieldPane= new JPanel(); JPanel InputPanel = new JPanel(); JButton submitButton = new JButton("Submit"); boolean buttonRemove; JLabel KeyLabel = new JLabel("Key:", SwingConstants.RIGHT); public static String plaintext, str, ciphertext, text; void initializeGui() { buttonRemove = false; //Create the FrameforChoice FrameforChoice.setSize(1250,2000); FrameforChoice.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); FrameforChoice.setLayout(new FlowLayout());
} public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("Atbash")) { FrameforChoice.setVisible(false); FrameforInput.setVisible(true); if(e.getActionCommand().equals("Submit")) { plaintext = Input.getText(); ciphertext = atbash(plaintext); Output.setText(ciphertext);
} } else if(e.getActionCommand().equals("Caesar Shift")) { buttonRemove = true; FrameforChoice.setVisible(false); InputPanel.add(KeyLabel); InputPanel.add(Input2); InputPanel.remove(submitButton); InputPanel.add(submitButton); FrameforInput.setVisible(true); if(e.getActionCommand().equals("Submit")) { plaintext = Input.getText(); text = Input2.getText(); key = Integer.parseInt(text); ciphertext = caesar(plaintext, key); Output.setText(ciphertext);
} } else if(e.getActionCommand().equals("ROT13")) { FrameforChoice.setVisible(false); FrameforInput.setVisible(true); if(e.getActionCommand().equals("Submit")) { plaintext = Input.getText(); ciphertext = ROT13(plaintext); Output.setText(ciphertext); } } else if(e.getActionCommand().equals("Vigenere")) { buttonRemove = true; FrameforChoice.setVisible(false); InputPanel.add(KeyLabel); InputPanel.add(Input2); InputPanel.remove(submitButton); InputPanel.add(submitButton); FrameforInput.setVisible(true); if(e.getActionCommand().equals("Submit")) { plaintext = Input.getText(); text = Input2.getText(); Key = text; ciphertext = vigenere(plaintext, Key); Output.setText(ciphertext); } } else if(e.getActionCommand().equals("Return")) { FrameforChoice.setVisible(true); FrameforInput.setVisible(false); Input.setText(""); Output.setText(""); if (buttonRemove) { InputPanel.remove(Input2); buttonRemove = false; } } } public static void main(String[] args) { GUI GUI = new GUI(); GUI.initializeGui(); } }