D.Tech Academic
Deep Singh
Pages
Core Java
Web App
Spring
Hibernate
Kotlin
Android
Python
Flutter
Spring Boot
HomePage in java swing using encryption and decryption
HomePage.java
import java.awt.BorderLayout; import java.awt.Color; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JDesktopPane; import javax.swing.JFrame; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; public class HomePage { public HomePage() { try { LookAndFeelInfo lf[]=UIManager.getInstalledLookAndFeels(); UIManager.setLookAndFeel(lf[1].getClassName()); }catch (Exception e) { // TODO: handle exception } initComponents(); } private void initComponents() { JFrame f=new JFrame("Title"); f.setIconImage(Toolkit.getDefaultToolkit().getImage("C:\\Users\\DEEP\\Desktop\\rr.jpg")); f.setSize(500,500); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JMenuBar mb=new JMenuBar(); JMenu m1=new JMenu("File"); JMenuItem mi1=new JMenuItem("New"); JMenuItem mi2=new JMenuItem("Open"); JMenuItem mi3=new JMenuItem("Save"); JMenuItem mi4=new JMenuItem("Exit"); m1.add(mi1); m1.add(mi2); m1.add(mi3); m1.add(mi4); JMenu m2=new JMenu("View"); JMenu m3=new JMenu("Format"); JMenu m4=new JMenu("Edit"); JMenu m5=new JMenu("Help"); JDesktopPane dp=new JDesktopPane(); //dp.setBackground(Color.red); mb.add(m1); mb.add(m2); mb.add(m3); mb.add(m4); mb.add(m5); f.add(dp); f.add(BorderLayout.NORTH,mb); f.setVisible(true); mi1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { NewTask nt=new NewTask(); dp.add(nt); nt.setVisible(true); } }); mi2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { OpenTask nt=new OpenTask(); dp.add(nt); nt.setVisible(true); } }); } public static void main(String[] args) { new HomePage(); } }
NewTask.java
import javax.swing.JInternalFrame; public class NewTask extends JInternalFrame{ public NewTask() { initComponents(); } private void initComponents(){ setTitle("Open New Account"); setSize(300,300); setClosable(true); setIconifiable(true); } }
OpenTask.java
import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.security.Key; import javax.crypto.Cipher; import javax.crypto.spec.SecretKeySpec; import javax.swing.JButton; import javax.swing.JInternalFrame; import javax.swing.JLabel; import javax.swing.JTextField; public class OpenTask extends JInternalFrame{ private String key = "Bar12345Bar12345"; Key k; private Cipher c; public OpenTask() { initComponents(); } private void initComponents(){ setTitle("Open File"); setSize(350,300); setClosable(true); setLayout(null); setIconifiable(true); JLabel l1=new JLabel("Enter Text"); l1.setBounds(20,30,100,30); JTextField t1=new JTextField(); t1.setBounds(130,30,100,30); JButton b1=new JButton("enc"); b1.setBounds(240,30,70,30); JLabel l2=new JLabel("Result "); l2.setBounds(20,100,150,30); JTextField t2=new JTextField(); t2.setBounds(130,200,100,30); JButton b2=new JButton("dec"); b2.setBounds(240,200,70,30); add(l1); add(t1); add(b1); add(l2); add(t2); add(b2); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String enctext=t1.getText(); try { k = new SecretKeySpec(key.getBytes(), "AES"); c = Cipher.getInstance("AES"); c.init(Cipher.ENCRYPT_MODE, k); byte b[] = c.doFinal(enctext.getBytes()); String mycontext=new String(b); l2.setText(mycontext); }catch (Exception e1) { System.out.println(e1); } } }); b2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String text=l2.getText(); try{ c.init(Cipher.DECRYPT_MODE,k); byte b1[]=c.doFinal(text.getBytes()); t2.setText(new String(b1)); }catch (Exception e1) { System.out.println(e1); } } }); } }
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment