@Ishaan94 and @apoorvk
import javax.swing.*; import java.awt.*; import java.awt.event.*; public class JPasswordEvent implements ActionListener,WindowListener { JFrame f,f2; JLabel label; JPasswordField pField; JButton b,b2; public JPasswordEvent(JFrame pa) { f2= pa; f = new JFrame("Introducing JPasswordField"); f.setSize(400, 400); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setLocationRelativeTo(null); label = new JLabel("Enter your Password"); pField = new JPasswordField(20); pField.setEchoChar('*'); pField.addActionListener(this); b = new JButton("GO BACK"); b2= new JButton("ENTER"); Container c = f.getContentPane(); FlowLayout flow = new FlowLayout(); c.setLayout(flow); b.addActionListener(this); b2.addActionListener(this); f.addWindowListener(this); f.add(label); f.add(pField); f.add(b2); f.add(b); f.setVisible(true); } /*public static void main(String args[]) { new JPasswordEvent(); }*/ public void actionPerformed(ActionEvent event) { if(event.getSource()==b){ if(f2 != null) { f2.setVisible(true); f.dispose(); } else {JOptionPane.showMessageDialog(null, "No Main Frame exists.");}} if(event.getSource()==b2){ char[] password = pField.getPassword(); String pass = String.valueOf(password); if(pass.equals("annas21")){ JOptionPane.showMessageDialog(null, "Authorization aproved!"); f.dispose(); new RegistrationForm(f2); } else JOptionPane.showMessageDialog(null, "Invalid password !");}} public void windowClosing(WindowEvent x) { if(f2 != null) { f2.setVisible(true); f.dispose(); } else System.exit(1); } public void windowOpened(WindowEvent x){}; public void windowClosed(WindowEvent x){}; public void windowActivated(WindowEvent x){}; public void windowDeactivated(WindowEvent x){}; public void windowDeiconified(WindowEvent x) {}; public void windowIconified(WindowEvent x){}; }
Wow...im just beginning java...havent got to gui
thanks actually i m in 4th semester of software engineering
oh...ive just done 2nd sem..electronics
nice dude :)
Join our real-time social learning platform and learn together with your friends!