import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.Random;
public class Encrypt extends JFrame
{
private String dCountry; //string to hold the destination country
private String encryptText; //string to hold text for encryption
private String encryptedText;
private char temp;
private char[] Alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
private char[] Encryption = {'Z', 'Y', 'X' ,'W' , 'V', 'U', 'T', 'S', 'R', 'Q', 'P', 'O',
'N', 'M', 'L', 'K', 'J', 'I', 'H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'};
private JPanel panel;
private JLabel messageLabel, countryLabel;
private JTextField input, cInput;
private JButton encryption;
private int c = 0;
public void Interface()
{
setTitle("Secret");
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
buildInterface();
add(panel);
setVisible(true);
}
private void buildInterface()
{
messageLabel = new JLabel("Enter Code to be encrypted");
countryLabel = new JLabel("Enter Destination Country");
input = new JTextField(25);
cInput = new JTextField(5);
encryption = new JButton("Encrypt");
panel = new JPanel();
panel.add(messageLabel);
panel.add(input);
panel.add(countryLabel);
panel.add(cInput);
panel.add(encryption);
encryption.addActionListener(new buttonlistener());
}
private class buttonlistener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == encryption)
{
encryptText = input.getText();
encryptText = encryptText.toUpperCase();
c = encryptText.length();
for(int i = 0; i < 26; i++)
{
if (encryptText.charAt(0) == Alphabet[i])
{
temp = Encryption[i];
encryptText.replace(encryptText.charAt(0), temp);
}
}
System.out.println(temp);
System.out.println(encryptText);
}
if (e.getSource() == encryption)
{
dCountry = cInput.getText();
dCountry = dCountry.toUpperCase();
if(dCountry.equals("FR"))
{
dCountry = "France";
}
else if(dCountry.equals("GB"))
{
dCountry = "Great Briton";
}
else if(dCountry.equals("CA"))
{
dCountry = "Canada";
}
else if(dCountry.equals("JA"))
{
dCountry = "Japan";
}
else if(dCountry.equals("RU"))
{
dCountry = "Russia";
}
else if(dCountry.equals("GE"))
{
dCountry = "Germany";
}
else if(dCountry.equals("AU"))
{
dCountry = "Australia";
}
else if(dCountry.equals("MX"))
{
dCountry = "Mexico";
}
}
if(e.getSource() == encryption)
{
JOptionPane.showMessageDialog(null,"To: " + dCountry + "\n" + encryptText);
}
}
}
}