import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ShiftedCipher extends JFrame{
static JTextField encryptcode;
static JTextField decryptcode;
static JTextArea encryptArea;
JScrollPane sp_encryptArea;
static JTextArea decryptArea;
JScrollPane sp_decryptArea;
JLabel encryptLabel;
JLabel encryptedLabel;
JLabel decryptLabel;
JLabel decryptedLabel;
static JComboBox select;
static JButton submitButton;
static JTextField key;
JLabel keyLabel;
static String selected="";
public ShiftedCipher() {
ShiftedCipherLayout customLayout = new ShiftedCipherLayout();
getContentPane().setFont(new Font("Helvetica", Font.PLAIN, 12));
getContentPane().setLayout(customLayout);
encryptcode = new JTextField("");
getContentPane().add(encryptcode);
decryptcode = new JTextField("");
getContentPane().add(decryptcode);
encryptArea = new JTextArea("Encrypted code will appear here.");
sp_encryptArea = new JScrollPane(encryptArea);
getContentPane().add(sp_encryptArea);
decryptArea = new JTextArea("Decrypted code will appear here.");
sp_decryptArea = new JScrollPane(decryptArea);
getContentPane().add(sp_decryptArea);
encryptLabel = new JLabel("Text to be encrypted:");
getContentPane().add(encryptLabel);
encryptedLabel = new JLabel("Encrypted Text:");
getContentPane().add(encryptedLabel);
decryptLabel = new JLabel("Text to be decrypted:");
getContentPane().add(decryptLabel);
decryptedLabel = new JLabel("Decrypted Text:");
getContentPane().add(decryptedLabel);
select = new JComboBox();
select.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
selected=(String)select.getSelectedItem();
if (selected.equals("Encrypt")){
decryptcode.setEditable(false);
encryptcode.setEditable(true);
}
else if (selected.equals("Decrypt")){
encryptcode.setEditable(false);
decryptcode.setEditable(true);
}
else if (selected.equals("Select")){
encryptcode.setEditable(false);
decryptcode.setEditable(false);
}
}
});
select.addItem("Select");
select.addItem("Encrypt");
select.addItem("Decrypt");
encryptArea.setEditable(false);
decryptArea.setEditable(false);
getContentPane().add(select);
submitButton = new JButton("Encode/Decode");
getContentPane().add(submitButton);
key = new JTextField("0");
getContentPane().add(key);
keyLabel = new JLabel("Key:");
getContentPane().add(keyLabel);
setSize(getPreferredSize());
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}
class ShiftedCipherLayout implements LayoutManager {
public ShiftedCipherLayout() {
}
public void addLayoutComponent(String name, Component comp) {
}
public void removeLayoutComponent(Component comp) {
}
public Dimension preferredLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
Insets insets = parent.getInsets();
dim.width = 1213 + insets.left + insets.right;
dim.height = 691 + insets.top + insets.bottom;
return dim;
}
public Dimension minimumLayoutSize(Container parent) {
Dimension dim = new Dimension(0, 0);
return dim;
}
public void layoutContainer(Container parent) {
Insets insets = parent.getInsets();
Component c;
c = parent.getComponent(0);
if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+56,472,40);}
c = parent.getComponent(1);
if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+296,472,40);}
c = parent.getComponent(2);
if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+112,472,136);}
c = parent.getComponent(3);
if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+352,472,120);}
c = parent.getComponent(4);
if (c.isVisible()) {c.setBounds(insets.left+48,insets.top+56,208,40);}
c = parent.getComponent(5);
if (c.isVisible()) {c.setBounds(insets.left+48,insets.top+112,208,40);}
c = parent.getComponent(6);
if (c.isVisible()) {c.setBounds(insets.left+56,insets.top+296,200,32);}
c = parent.getComponent(7);
if (c.isVisible()) {c.setBounds(insets.left+56,insets.top+360,200,24);}
c = parent.getComponent(8);
if (c.isVisible()) {c.setBounds(insets.left+776,insets.top+56,160,32);}
c = parent.getComponent(9);
if (c.isVisible()) {c.setBounds(insets.left+776,insets.top+112,160,24);}
c = parent.getComponent(10);
if (c.isVisible()) {c.setBounds(insets.left+264,insets.top+488,72,24);}
c = parent.getComponent(11);
if (c.isVisible()) {c.setBounds(insets.left+184,insets.top+488,72,24);}
}
}