0% found this document useful (0 votes)
4 views3 pages

Op Imp

This document explains a Java program that creates a Graphical User Interface (GUI) for encrypting and decrypting text using various cipher techniques. It details the components of the program, including libraries, class definitions, GUI elements like text fields and buttons, and the layout of the interface. The program allows users to select a cipher method and input necessary information for encryption or decryption.

Uploaded by

adityapandji1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Op Imp

This document explains a Java program that creates a Graphical User Interface (GUI) for encrypting and decrypting text using various cipher techniques. It details the components of the program, including libraries, class definitions, GUI elements like text fields and buttons, and the layout of the interface. The program allows users to select a cipher method and input necessary information for encryption or decryption.

Uploaded by

adityapandji1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

I'll explain this code step by step in a way a 13-year-old can understand.

Understanding the Code:

This Java program creates a Graphical User Interface (GUI) for encrypting and decrypting text
using different cipher techniques.

1. Importing Required Libraries


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

 javax.swing.*: Allows us to create GUI components like windows, buttons, text fields,
and labels.
 java.awt.*: Used for designing the layout of the GUI.
 java.awt.event.*: Helps us detect button clicks and other user actions.

2. Defining the CipherGUI Class


public class CipherGUI

 This creates a new class called CipherGUI. A class is like a blueprint that defines how
something behaves in Java.

3. Declaring GUI Components


private JFrame frame;
private JTextField passwordField, keyField;
private JTextArea outputArea;
private JComboBox cipherBox;
private JRadioButton encryptButton, decryptButton;

 JFrame frame: The main window of the application.


 JTextField passwordField: A text box for the user to enter a password (or message).
 JTextField keyField: A text box for entering a key (used in some ciphers).
 JTextArea outputArea: A larger text box for displaying the result.
 JComboBox cipherBox: A dropdown menu where the user selects the encryption
method.
 JRadioButton encryptButton, decryptButton: Buttons to choose between
encryption or decryption.

4. Creating the GUI


public CipherGUI() {
frame = new JFrame("Cipher Encryption & Decryption");
frame.setSize(500, 400);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new FlowLayout());

 new JFrame("Cipher Encryption & Decryption"): Creates a window with a title.


 frame.setSize(500, 400): Sets the window size to 500 pixels wide and 400 pixels tall.
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE): Ensures the program
closes when the window is closed.
 frame.setLayout(new FlowLayout()): Arranges components in a simple left-to-right
layout.

5. Adding Cipher Selection


frame.add(new JLabel("Choose Cipher Technique:"));
String[] ciphers = {"Caesar", "Vernam", "Playfair", "Vigenere"};
cipherBox = new JComboBox<>(ciphers);
frame.add(cipherBox);

 JLabel is used to show text on the screen.


 cipherBox is a dropdown menu where the user selects a cipher type.

6. Adding Encryption & Decryption Buttons


encryptButton = new JRadioButton("Encrypt", true);
decryptButton = new JRadioButton("Decrypt");
ButtonGroup actionGroup = new ButtonGroup();
actionGroup.add(encryptButton);
actionGroup.add(decryptButton);
frame.add(encryptButton);
frame.add(decryptButton);

 Radio buttons allow the user to select either Encrypt or Decrypt.


 ButtonGroup ensures that only one of them can be selected at a time.
7. Adding Input Fields
frame.add(new JLabel("Enter Password:"));
passwordField = new JTextField(20);
frame.add(passwordField);

frame.add(new JLabel("Enter Key (Only for Vernam, Playfair, Vigenere):"));


keyField = new JTextField(20);
frame.add(keyField);

 A

You might also like