Sunday, 30 November 2014

Caesar Applet Demo in Java

import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class CaesarApplet extends Applet implements ActionListener
{
    Label enterText;
    TextField text;

    Label enterKey;
    TextField key;

    Button encrypt;
    Button decrypt;

    Label result_text;
    Label result;

    public void init()
    {
            enterText = new Label("Enter Text: ");
            text = new TextField(25);
            enterKey = new Label("Enter key: ");
            key = new TextField(25);
            encrypt = new Button("Encrypt Text");
            decrypt = new Button("Decrypt Text");
            result_text = new Label("Resultant Text: ");
            result = new Label();

            add(enterText);
            add(text);
            add(enterKey);
            add(key);

            add(encrypt);
            encrypt.addActionListener(this);
            add(decrypt);
            decrypt.addActionListener(this);

            add(result_text);
            add(result);
    }

    public void actionPerformed(ActionEvent ae)
    {
        if(ae.getSource() == encrypt)
        {
            String pt = text.getText();
            String k = key.getText();
            int encrypt_key = Integer.parseInt(k);

            String res = encrypt(pt,encrypt_key);
            result.setText(res);
        }
        else if(ae.getSource() == decrypt)
        {
            String ct = text.getText();
            String k = key.getText();
            int decrypt_key = Integer.parseInt(k);

            String res = decrypt(ct,decrypt_key);
            result.setText(res);
        }
    }

    static public String encrypt(String pt,int encrypt_key)
    {
        char c;
        int num,i;

        StringBuffer sb = new StringBuffer(pt);
        int len = sb.length();

        for(i=0;i

Output:







5 comments:

  1. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Java developer learn from Java Training in Chennai. or learn thru Java Online Training in India . Nowadays Java has tons of job opportunities on various vertical industry.

    ReplyDelete
  2. Hmm, it seems like your site ate my first comment (it was extremely long) so I guess I’ll just sum it up what I had written and say, I’m thoroughly enjoying your blog. I as well as an aspiring blog writer, but I’m still new to the whole thing. Do you have any recommendations for newbie blog writers? I’d appreciate it.
    Advanced AWS Training in Bangalore | Best Amazon Web Services Training Institute in Bangalore
    Advanced AWS Training Institute in Pune | Best Amazon Web Services Training Institute in Pune
    Advanced AWS Online Training Institute in india | Best Online AWS Certification Course in india
    AWS training in bangalore | Best aws training in bangalore

    ReplyDelete
  3. Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's. 
    microsoft azure training in bangalore
    rpa training in bangalore
    best rpa training in bangalore
    rpa online training

    ReplyDelete
  4. Awesome..You have clearly explained …Its very useful for me to know about new things..Keep on blogging..
    Best Devops online Training
    Online DevOps Certification Course - Gangboard

    ReplyDelete