new to java help in changepassword..
guys help me in changepassword.. i don't know how to replace the defualt value in the LogInForm.java the strpass1 = "mon" i want to change it when the user change the password..
here's my code..
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class LogInForm extends JFrame{
JTextField txtuser;
JButton login,cancel;
JLabel username,password;
JPasswordField txtpass;
String struser1 = "mon";
String strpass1 = "mon";
public LogInForm(){
super("LogInForm");
setSize(300,150);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
jp.setLayout(null);
login = new JButton("Login");
cancel = new JButton("Cancel");
username = new JLabel("UserName");
password = new JLabel("Password");
txtuser = new JTextField(16);
txtpass = new JPasswordField(16);
username.setBounds(15,15,150,20);
password.setBounds(15,45,150,20);
txtuser.setBounds(100,15,170,20);
txtpass.setBounds(100,45,170,20);
login.setBounds(30,75,100,20);
cancel.setBounds(150,75,100,20);
jp.add(login);
jp.add(cancel);
jp.add(username);
jp.add(txtuser);
jp.add(password);
jp.add(txtpass);
getContentPane().add(jp);
//actionlistener
login.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
String user = txtuser.getText();
String pass = txtpass.getText();
if(user.equals(struser1) && pass.equals(strpass1)){
//JOptionPane.showMessageDialog(null, "Welcome");
WelcomeScreen ws = new WelcomeScreen();
ws.setVisible(true);
//ws.username.setText("WELCOME "+user.toUpperCase());
dispose();
}else{
JOptionPane.showMessageDialog(null, "Wrong username/password");
txtuser.setText("");
txtpass.setText("");
}
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
System.exit(0);
}
});
}
public void setStruser(String struser) {
this.struser1 = struser;
}
public void setStrpass(String strpass) {
this.struser1 = strpass;
}
public String getStruser() {
return struser1;
}
public String getStrpass() {
return strpass1;
}
public static void main(String[]args){
LogInForm lif = new LogInForm();
lif.setVisible(true);
}
}
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import java.util.Random;
import javax.swing.*;
public class ChangePassword extends JFrame{
JLabel username,oldpass,pass,pass2,img,ttw;
JTextField txtuser,capcha;
JPasswordField txtoldpass,txtpass,txtpass2;
JButton changepass,cancel;
ArrayList<ImageIcon> al;
ImageIcon [] imgico = new ImageIcon[10];
JLabel[]imglbl = new JLabel[10];
String[]imgstr = {"img1.jpg","img2.jpg","img3.jpg","img4.jpg","img5 .jpg","img6.jpg","img7.jpg","img8.jpg","img9.jpg", "img10.jpg",};
String[]capc = {"Sdthel WAS","rypiedyn III","relic iqalia","Was yntore","can ioerint","goes pprovb","ofnirly ockage.","Heltipa buildings","himself oorltua","already stepowi"};
int next;
Random ran;
ChangePassword(){
super("ChangePassword");
setSize(300,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
jp.setLayout(null);
username = new JLabel("Username");
oldpass = new JLabel("Old Password");
pass = new JLabel("New Password");
pass2 = new JLabel("Repeat Password");
ttw = new JLabel("Type The word");
txtuser = new JTextField(16);
capcha = new JTextField();
txtoldpass = new JPasswordField(16);
txtpass = new JPasswordField(16);
txtpass2 = new JPasswordField(16);
changepass = new JButton("Change");
cancel = new JButton("Cancel");
//image
for(int i=0;i<imgico.length;i++){
imgico[i] = new ImageIcon(getClass().getResource(imgstr[i]));
}
for(int j=0;j<imgico.length;j++){
imglbl[j] = new JLabel(imgico[j]);
}
ran = new Random();
next = ran.nextInt(imgico.length);
img = new JLabel(imgico[next]);
//image
username.setBounds(15, 15, 150, 20);
txtuser.setBounds(120,15,150,20);
oldpass.setBounds(15,45,150,20);
txtoldpass.setBounds(120,45,150,20);
pass.setBounds(15,75,150,20);
txtpass.setBounds(120,75,150,20);
pass2.setBounds(15,105,150,20);
txtpass2.setBounds(120,105,150,20);
img.setBounds(15,115,250,100);
ttw.setBounds(15,200,150,20);
capcha.setBounds(120,200,150,20);
changepass.setBounds(45,230,100,20);
cancel.setBounds(160,230,100,20);
jp.add(capcha);
jp.add(ttw);
jp.add(img);
jp.add(username);
jp.add(oldpass);
jp.add(pass);
jp.add(pass2);
jp.add(txtuser);
jp.add(txtoldpass);
jp.add(txtpass);
jp.add(txtpass2);
jp.add(changepass);
jp.add(cancel);
getContentPane().add(jp);
changepass.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
// if(img.getIcon().equals(iimg1.getIcon()) && capcha.getText().equals("Sdthel WAS")){
// JOptionPane.showMessageDialog(null, "Wahahaha");
// }
for(int k=0;k<imgico.length;k++){
if(img.getIcon().equals(imglbl[k].getIcon())){
if(!(capcha.getText().equals("") || txtoldpass.getText().equals("") || txtpass.getText().equals("") ||txtpass2.getText().equals("") ||txtuser.getText().equals(""))){
if(capcha.getText().equals(capc[k])){
if(txtoldpass.getText().equals("mon")){
if(txtpass.getText().equals(txtpass2.getText())){
if(txtuser.getText().equals("mon")){
LogInForm lif = new LogInForm();
//lif.setStrpass(txtpass.getText());
lif.strpass1 = txtpass.getText();
JOptionPane.showMessageDialog(null, "SUCCESS!! password has been change");
WelcomeScreen ws = new WelcomeScreen();
ws.setVisible(true);
dispose();
}
else{
JOptionPane.showMessageDialog(null, "Wrong username");
capcha.setText("");
next = ran.nextInt(imgico.length);
img.setIcon(imgico[next]);
k = imgico.length;
}
}
else{
JOptionPane.showMessageDialog(null, "Password Mismatch");
capcha.setText("");
next = ran.nextInt(imgico.length);
img.setIcon(imgico[next]);
k = imgico.length;
}
}
else{
JOptionPane.showMessageDialog(null, "Wrong old pass");
capcha.setText("");
next = ran.nextInt(imgico.length);
img.setIcon(imgico[next]);
k = imgico.length;
}
}
else{
JOptionPane.showMessageDialog(null, "invalid Captcha");
capcha.setText("");
next = ran.nextInt(imgico.length);
//img = new JLabel(imgico[next]);
img.setIcon(imgico[next]);
k = imgico.length;
}
}else{
JOptionPane.showMessageDialog(null, "invalid Captcha");
k = imgico.length;
}
}
}
// next = ran.nextInt(imgico.length);
// img.setIcon(imgico[next]);
}
});
cancel.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
WelcomeScreen ws = new WelcomeScreen();
ws.setVisible(true);
dispose();
}
});
}
}
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class WelcomeScreen extends JFrame{
JTextField txtuser;
JButton changepass,logout;
JLabel username,password;
JPasswordField txtpass,newpass;
public WelcomeScreen(){
super("Welcome");
setSize(370,110);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
jp.setLayout(null);
LogInForm lif = new LogInForm();
username = new JLabel("WELCOME ");
changepass = new JButton("ChangePassword");
logout = new JButton("LogOut");
//left to right, top to bottom,haba nya,height nya..
username.setBounds(150, 10, 100, 20);
changepass.setBounds(20,30,150,20);
logout.setBounds(200, 30, 150, 20);
jp.add(username);
jp.add(changepass);
jp.add(logout);
getContentPane().add(jp);
logout.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
LogInForm lif = new LogInForm();
lif.setVisible(true);
dispose();
}
});
changepass.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//throw new UnsupportedOperationException("Not supported yet.");
ChangePassword cp = new ChangePassword();
cp.setVisible(true);
dispose();
}
});
}
}
Re: new to java help in changepassword..