Results 1 to 8 of 8
  1. #1
    yonghan is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default Ask about JPasswordfield

    Hi all,i'm using netbeans with ubuntu.I got a problem,i use a jtextfield and a jpaswordfield,when i run the program,jtextfield is ok,but whne i want to edit the jpasswordfield,it can't be edited,unless i've click a button displaying messages,then the jpasswordfield can be edited..What should i do?Thanks a lot..

  2. #2
    serjant's Avatar
    serjant is offline Senior Member
    Join Date
    Jun 2008
    Location
    Ukraine,Zaporozhye
    Posts
    487
    Rep Power
    7

    Default

    Can you provide the cod please,actually it should be this way:
    Java Code:
    JPasswordField passwordField = new JPasswordField(10);
    passwordField.addActionListener(this);
    you can try this demo JNLP application with JPasswordField
    PasswordDemo
    and the code for it is:
    PasswordDemo.java
    Last edited by serjant; 09-11-2008 at 04:46 PM.

  3. #3
    yonghan is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default i use netbeans

    I use netbeans,i didn't edit the code for the jpasswordfield..When i delete the jtextfield,the jpasswordfield can be edited immediately.

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    My recommendation, and you're not going to like it: avoid using NetBeans to generate your Swing code and code it by hand. It's not hard to do, and in the process, you'll learn much more about Swing.

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Fubarable View Post
    My recommendation, and you're not going to like it: avoid using NetBeans to generate your Swing code and code it by hand. It's not hard to do, and in the process, you'll learn much more about Swing.
    This is really nice advice for newbies, on swing specially. When you have better idea on such things better to move with Java IDE.

    Back to the original question, can you post a code segment to see what you have exactly done. I hope it's not clear what you have done for most of the members.

  6. #6
    yonghan is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default Here are the codes..I did'nt edit anything else for the jpasswordfield..

    I'm confused..Last night i try,there's no problem..I can directly edit the password,but just now it doesn't works again..

    private void btCancelActionPerformed(java.awt.event.ActionEvent evt)
    {
    System.exit(0);
    }

    private void btLoginActionPerformed(java.awt.event.ActionEvent evt)
    {
    try
    {char[] pwd = txtPwd.getPassword();
    StringBuffer str = new StringBuffer();for (int i=0;i<pwd.length;i++)
    {
    str.append(pwd[i]);
    }
    MessageDigest md = MessageDigest.getInstance("MD5");
    md.update(str.toString().getBytes(),0,str.length() );
    String pass = new BigInteger(1,md.digest()).toString(16);
    javax.persistence.Query query=ent.createQuery("select d from DataUser d where d.usrname=:name and d.pwd= :pwd");
    query.setParameter("name",txtUser.getText());
    query.setParameter("pwd", pass);
    DataUser d =(DataUser) query.getSingleResult();
    this.setVisible(false);this.dispose();new MainFrm().setVisible(true);
    }
    catch (Exception exception)
    {
    JOptionPane.showMessageDialog(null, exception.getMessage());
    }
    }

  7. #7
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,458
    Rep Power
    25

    Default

    ,it can't be edited,unless i've click a button
    private void btLoginActionPerformed(java.awt.event.ActionEvent evt)
    {
    Your code in the above method appears to be called when a button is pressed. You don't show the addActionListener() call but the method name and args make it look like an actionListener. So its only called when the button is pressed.
    What do you want to change?

  8. #8
    yonghan is offline Member
    Join Date
    Aug 2008
    Posts
    7
    Rep Power
    0

    Default I don't want to change anything

    I don't want to change anything Norm..It just that i don't know why that the jpasswordfield that i put in the login form using netbeans are unabled to be edited on the runtime,unless i click the login button first,then back to edit the jpasswordfield....I'm using ubuntu,does it concern with it?Thansk a lot..

Posting Permissions

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