everything is working fine except Encryption button.
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class encryption extends JPanel implements ActionListener {
char [] str= {'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' };
char [] str1={'1','2','3','4','5','6','7','8','9','0','!','@','#','$','%','^','&','*','(','_','_','+','=',',','.','?'};
char [] a= new char [50];
char [] b= new char [50];
JLabel pt, et,dt;
String k="";
String l="";
JTextField pf,ef,df;
JButton encbutt, clebutt,decbutt,exibutt;
public encryption(){
pt=new JLabel("Plain Text");
et=new JLabel("Encrypted Text");
dt=new JLabel("Decrypted Text");
pf= new JTextField(20);
ef= new JTextField(20);
df= new JTextField(20);
encbutt= new JButton("Encryption");
clebutt= new JButton("Clear");
decbutt= new JButton("Decryption");
exibutt= new JButton("Exit");
ef.setEditable(false);
df.setEditable(false);
decbutt.setEnabled(false);
setLayout(null);
add(pt);
add(et);
add(dt);
add(pf);
add(ef);
add(df);
add(encbutt);
add(clebutt);
add(decbutt);
add(exibutt);
pt.setBounds(20, 20, 200,30);
et.setBounds(20,80,200,30);
dt.setBounds(20,140, 200,30);
pf.setBounds(220,20,200,30);
ef.setBounds(220,80,200,30);
df.setBounds(220,140,200,30);
encbutt.setBounds(30,200,160,30);
clebutt.setBounds(30,240,160,30);
decbutt.setBounds(240,200,160,30);
exibutt.setBounds(240,240,160,30);
decbutt.addActionListener(this);
clebutt.addActionListener(this);
exibutt.addActionListener(this);
}
public void actionPerformed(ActionEvent ae)
{
String action=ae.getActionCommand();
if(ae.equals("Encryption"))
{
k=pf.getText().toString().toLowerCase();
if(k.equals(""))
{
pf.setFocusable(true);
JOptionPane.showMessageDialog(this, "Please Enter Any text !", "Warning", JOptionPane.WARNING_MESSAGE);
}
else
{
decbutt.setEnabled(true);
encbutt.setEnabled(false);
a=k.toCharArray();
for(int i=0;i<k.length();i++)
{
for(int j=0;j<26;j++)
{
if(a[i]==str[j])
{
a[i]=str1[j];
}
}
}
for(int i=0;i<k.length();i++)
{
l=l+a[i] ;
}
ef.setText(l);
// JOptionPane.showMessageDialog(bencrypt,l.toString(),"Message",JOptionPane.INFORMATION_MESSAGE);
}
}
else if(action.equals("Decryption"))
{
String x=ef.getText().toString();
String y="";
if(x.equals(""))
{
JOptionPane.showMessageDialog(this,"No Encrypted Message","Warning",JOptionPane.WARNING_MESSAGE);
}
else
{
b=x.toCharArray();
//JOptionPane.showMessageDialog(this,k.toString(),"Warning",JOptionPane.WARNING_MESSAGE);
for(int i=0;i<x.length();i++)
{
for(int j=0;j<26;j++)
{
if(b[i]==str1[j])
{
b[i]=str[j];
j=26;
}
}
}
for( int i=0;i<x.length();i++)
{
y=y+b[i];
}
df.setText(y);
y="";
}
}
else if(action.equals("Clear"))
{
pf.setText("");
ef.setText("");
df.setText("");
pf.setFocusable(true);
decbutt.setEnabled(false);
encbutt.setEnabled(true);
}
else if(action.equals("Exit"))
{
System.exit(0);
}
}
public static void main(String[] args) {
JFrame n=new JFrame();
n.getContentPane().add(new encryption());
n.setSize(440,310);
n.setVisible(true);
n.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}