Results 1 to 2 of 2
  1. #1
    Chick786 is offline Member
    Join Date
    Apr 2010
    Rep Power

    Exclamation JPasswordField question..

    OK - This bit baffled me..

    private static class JPassword implements ActionListener {
    String password = "pass"; //string containing the password
    private void main() {
    //create frame
    JFrame frame = new JFrame("Password");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
    JButton B1 = new JButton("Check Balance");

    JLabel label3 = new JLabel("Enter Pin");
    JPanel panel = new JPanel();

    JPasswordField pass = new JPasswordField(5);
    pass.setEchoChar('*'); //actionlistener

    panel.add(label3, BorderLayout.WEST);
    panel.add(pass, BorderLayout.WEST);


    public void actionPerformed(ActionEvent e){
    JPasswordField input = (JPasswordField) e.getSource();
    char[] passy = input.getPassword();
    String p = new String(passy);
    if (p.equals(password)){
    JOptionPane.showMessageDialog(null, "Correct");
    JOptionPane.showMessageDialog(null, "Incorrect");


    Have the above code.. works.. I've created a button... with an Action Listener... How do I join these two?? Is it done in the code above or in a seperate code?

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Blog Entries
    Rep Power


    I'm surprised that your code works. You're adding things to a JFrame after setting it to visible, and you're not adding the JButton at all. I suggest you hit the Sun Swing tutorials as it will show you the right way to do this.

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. Any workarounds for JPasswordField in JDialog bug?
    By dtmansy in forum Advanced Java
    Replies: 5
    Last Post: 02-23-2010, 11:56 PM
  3. Ask about JPasswordfield
    By yonghan in forum AWT / Swing
    Replies: 7
    Last Post: 09-14-2008, 11:54 AM
  4. a question
    By slytheman in forum Java Servlet
    Replies: 0
    Last Post: 03-12-2008, 04:11 AM
  5. JNI question
    By javaplus in forum New To Java
    Replies: 0
    Last Post: 12-24-2007, 10:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts