Java Change Password GUI Application, Study notes of Java Programming

The java code for a changepassword application, which allows users to update their passwords through a graphical user interface (gui). The application uses swing components, jdbc for database connection, and joptionpane for displaying messages. The code includes creating a jframe, adding labels, text fields, and buttons, handling user input, and connecting to a database to validate and update passwords.

Typology: Study notes

2017/2018

Uploaded on 03/05/2018

deep-kaur
deep-kaur 🇮🇳

1 document

1 / 8

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CHANGE PASSWORD DA CODE IN JAVA
001 import java.awt.*;
002 import java.awt.event.*;
003 import javax.swing.*;
004 import javax.swing.event.*;
005 import java.sql.*;
006 import javax.imageio.ImageIO;
007 import java.awt.image.BufferedImage;
008 import java.awt.Dimension;
009 import java.io.IOException;
010
011 public class ChangePassword extends JFrame implements ActionListener
012 {
013
014 JFrame jf;
015 JButton btnUpdate,btnCancel,btnBack;
016 JLabel lbl1,lblPass,lblNewPass,lblConfirmPass,lbluser;
017 JPasswordField txtPass,txtNewPass,txtConfirmPass;
018 JTextField txtuser;
019 Statement stmt;
020 PreparedStatement ps;
021 Connection conn;
022 ResultSet rs;
023 JPanel pan2;
024
025 public ChangePassword()
pf3
pf4
pf5
pf8

Partial preview of the text

Download Java Change Password GUI Application and more Study notes Java Programming in PDF only on Docsity!

CHANGE PASSWORD DA CODE IN JAVA

001 import java.awt.; 002 import java.awt.event.; 003 import javax.swing.; (^004) import javax.swing.event.; 005 import java.sql.*; 006 import javax.imageio.ImageIO; (^007) import java.awt.image.BufferedImage; (^008) import java.awt.Dimension; 009 import java.io.IOException; 010 011 public class ChangePassword extends JFrame implements ActionListener 012 { 013 014 JFrame jf; 015016 JButton btnUpdate,btnCancel,btnBack;JLabel lbl1,lblPass,lblNewPass,lblConfirmPass,lbluser; 017018 JPasswordField txtPass,txtNewPass,txtConfirmPass;JTextField txtuser; 019020 Statement stmt;PreparedStatement ps; 021022 Connection conn;ResultSet rs; 023024 JPanel pan2;

(^025) public ChangePassword()

027028 Container cp = getContentPane();setSize(450,450);

029030 setLayout(null);setLayout(null);

031032 setTitle("LOGIN TO LIBRARY");cp.setLayout(null);

(^033) JLabel jl = new JLabel("",new ImageIcon(""),JLabel.LEFT); 034 jl.setSize(450,450); 035036 jl.setLocation(0,0);cp.add(jl);

037 (^038) lbl1=new JLabel("Change Password");

039040 lbl1.setLocation(150,40);lbl1.setSize(300,50);

(^041) lbl1.setFont(new Font("Times New Roman", Font.BOLD, 20 )); 042 jl.add(lbl1); 043 (^044) lbluser = new JLabel("Username");

045046 lbluser.setSize(100,50);lbluser.setLocation(40,100);

(^047) lbluser.setFont(new Font("Times New Roman", Font.BOLD, 16 )); 048 jl.add(lbluser); 049 (^050) txtuser = new JTextField(20);

051052 txtuser.setSize(200,25);txtuser.setLocation(220,110);

053054 jl.add(txtuser);

(^083) txtConfirmPass = new JPasswordField(20); 084 txtConfirmPass.setSize(200,25); 085086 txtConfirmPass.setLocation(220,290);jl.add(txtConfirmPass);

087 (^088) btnUpdate = new JButton("Upadate");

089090 btnUpdate.setSize(85,25);btnUpdate.setLocation(80,350);

091 092 btnUpdate.addActionListener(this); 093094 jl.add(btnUpdate);

(^095) btnBack = new JButton("Back"); 096 btnBack.setSize(80,25); 097098 btnBack.setLocation(173,350);

099100 btnBack.addActionListener(this);jl.add(btnBack);

101 102

(^103) btnCancel = new JButton("Clear"); 104 btnCancel.setSize(80,25); 105106 btnCancel.setLocation(260,350);

107108 btnCancel.addActionListener(this);jl.add(btnCancel);

109 110 try 111 {

112 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); (^113114) stmt=conn.createStatement();conn=DriverManager.getConnection("Jdbc:Odbc:Library","","");

(^115116) catch(Exception e)}

117118 {}

(^119120) setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);setVisible(true);

121122 }

(^123) public void actionPerformed(ActionEvent ae) 124 { 125126 if(ae.getSource()== btnUpdate){

127128 try{

129130 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");conn=DriverManager.getConnection("Jdbc:Odbc:Library","","");

131132 String p1 = "";String pk="";

133134 // String p = txtuser.getText();String p2 = txtPass.getText();

135136 String p3 = txtNewPass.getText();String p4 = txtConfirmPass.getText();

(^137) ="+txtuser.getText());rs=stmt.executeQuery("select * from Password where username 138

139140 while(rs.next()){

171172 }catch(Exception e)

173174 {

175176 }

(^177178) if(ae.getSource()== btnCancel)}

179180 { txtPass.setText("");

181182 txtuser.setText("");txtNewPass.setText("");

(^183184) } txtConfirmPass.setText("");

185186 if(ae.getSource() == btnBack){

187188 this.dispose();

(^189190) } }

(^191) public static void main(String args[]) 192 { (^193) JFrame frm = new ChangePassword(); 194 frm.setSize(450,450); 195196 frm.setLocation(100,90);BufferedImage image = null;

(^197) try {

(^198) ("Usericon.png")); image = ImageIO.read(frm.getClass().getResource

(^199) } catch (IOException e) { 200 e.printStackTrace(); (^201202) frm.setIconImage(image);}

203204 frm.setVisible(true);frm.show();

(^205) 206 } }

207 208

209