import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import java.applet.Applet;
import javax.swing.*;
public class Main3 extends JApplet {
//globals for user interface
private Container content;
private JPanel centerPanel; //Bottom panel that changes
private CardLayout card; //Layout for the applet
//globals for Euclidean Algorithm
private static JTextField eucl_ai;
private static JTextField eucl_bi;
private static JTextArea eucl_o;
//This will initialize all of the GUIs, even the ones not showing
public void init()
{
//Applet Settings
content = getContentPane();
setSize(800, 600);
content.setBackground(Color.GREEN);
content.setLayout(new BorderLayout());
//This is the panel that contains all the buttons
JPanel northPanel = new JPanel();
//Button for the Vigenere cipher
JButton vigenere_b = new JButton("Vigenere Cipher");
vigenere_b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
vigenere_gui();
}
});
northPanel.add(vigenere_b);
//Button for the Euclidean Algorithm
JButton eucl_b = new JButton("Euclidean");
eucl_b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
eucl_gui();
}
});
northPanel.add(eucl_b);
//Button for Reset
JButton reset_b = new JButton("Reset");
reset_b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
reset_gui();
}
});
northPanel.add(reset_b);
//Add the north panel to the applet
content.add(northPanel, BorderLayout.NORTH);
//Set the layout in the applet to cardlayout
centerPanel = new JPanel();
card = new CardLayout();
centerPanel.setLayout(card);
//Set the gui for the Euclidean Algorithm
JPanel euclPanel = new JPanel();
euclPanel.setBackground(Color.WHITE);
SpringLayout eucl_layout = new SpringLayout();
euclPanel.setLayout(eucl_layout);
//Text
JTextField eucl_1 = new JTextField();
eucl_1.setBorder(BorderFactory.createEmptyBorder());
eucl_1.setText("Extended Euclidean Algorithm");
eucl_1.setEditable(false);
eucl_1.setBackground(Color.WHITE);
eucl_layout.putConstraint(SpringLayout.WEST, eucl_1, 5, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_1, 5, SpringLayout.NORTH, content);
euclPanel.add(eucl_1);
//Text
JTextField eucl_2 = new JTextField();
eucl_2.setBorder(BorderFactory.createEmptyBorder());
eucl_2.setText("Enter a,b to find gcd(a,b)");
eucl_2.setEditable(false);
eucl_2.setBackground(Color.WHITE);
eucl_layout.putConstraint(SpringLayout.WEST, eucl_2, 5, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_2, 55, SpringLayout.NORTH, content);
euclPanel.add(eucl_2);
//Text
JTextField eucl_3 = new JTextField();
eucl_3.setBorder(BorderFactory.createEmptyBorder());
eucl_3.setText("a:");
eucl_3.setEditable(false);
eucl_3.setBackground(Color.WHITE);
eucl_layout.putConstraint(SpringLayout.WEST, eucl_3, 5, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_3, 80, SpringLayout.NORTH, content);
euclPanel.add(eucl_3);
//User Input
eucl_ai = new JTextField(3);
eucl_ai.setBorder(BorderFactory.createLineBorder(Color.BLACK));
eucl_layout.putConstraint(SpringLayout.WEST, eucl_ai, 25, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_ai, 80, SpringLayout.NORTH, content);
euclPanel.add(eucl_ai);
//Text
JTextField eucl_4 = new JTextField();
eucl_4.setBorder(BorderFactory.createEmptyBorder());
eucl_4.setText("b:");
eucl_4.setEditable(false);
eucl_4.setBackground(Color.WHITE);
eucl_layout.putConstraint(SpringLayout.WEST, eucl_4, 75, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_4, 80, SpringLayout.NORTH, content);
euclPanel.add(eucl_4);
//User Input
eucl_bi = new JTextField(3);
eucl_bi.setBorder(BorderFactory.createLineBorder(Color.BLACK));
eucl_layout.putConstraint(SpringLayout.WEST, eucl_bi, 95, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_bi, 80, SpringLayout.NORTH, content);
euclPanel.add(eucl_bi);
//Submit Button
JButton eucl_submit = new JButton("Submit");
eucl_submit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
process_eucl();
}
});
eucl_layout.putConstraint(SpringLayout.WEST, eucl_submit, 5, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_submit, 105, SpringLayout.NORTH, content);
euclPanel.add(eucl_submit);
//Text
JTextField eucl_5 = new JTextField();
eucl_5.setBorder(BorderFactory.createEmptyBorder());
eucl_5.setText("Output:");
eucl_5.setEditable(false);
eucl_5.setBackground(Color.WHITE);
eucl_layout.putConstraint(SpringLayout.WEST, eucl_5, 5, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_5, 155, SpringLayout.NORTH, content);
euclPanel.add(eucl_5);
//Output
eucl_o = new JTextArea(15,30);
eucl_o.setBorder(BorderFactory.createLineBorder(Color.BLACK));
JScrollPane eucl_o_scroll = new JScrollPane(eucl_o);
eucl_o_scroll.setPreferredSize(new Dimension(490,330));
eucl_layout.putConstraint(SpringLayout.WEST, eucl_o_scroll, 5, SpringLayout.NORTH, content);
eucl_layout.putConstraint(SpringLayout.NORTH, eucl_o_scroll, 180, SpringLayout.NORTH, content);
euclPanel.add(eucl_o_scroll);
//
centerPanel.add("eucl", euclPanel);
//Set the gui for the vigener cipher
JPanel vigenerePanel = new JPanel();
vigenerePanel.setBackground(Color.BLUE);
vigenerePanel.add(new JButton("button vigenere"));
centerPanel.add("vigenere", vigenerePanel);
//Set the gui for another panel
JPanel emptyPanel = new JPanel();
emptyPanel.setBackground(Color.WHITE);
centerPanel.add("empty", emptyPanel);
//Center components
content.add(centerPanel, BorderLayout.CENTER);
}
//This method displays the vigenere cipher in the center panel
public void vigenere_gui() {
card.show(centerPanel, "vigenere");
}
//This method displays the Euclidean in the center panel
public void eucl_gui() {
card.show(centerPanel, "eucl");
}
//This method resets the gui
public void reset_gui() {
//...
}
//
// Extended Euclidean Algorithm for integers a & b
//
public void process_eucl() {
//...
}
}