Results 1 to 3 of 3
Thread: password/voting ID
- 11-12-2009, 08:16 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 15
- Rep Power
- 0
password/voting ID
hello,
i am writing a program where someone enters their "password" into a gui and then can vote for some people. So far the voting part is working but the password is not. For the password, the user enters any number(s) and the program should store it into an array. After that, they can vote. When someone votes again they enter a new password and that password is entered as the second term of the array. If you enter the same password then an error message should show up. Heres my code:
pretty much everything is ok except everything after the action listenerJava Code:import javax.swing.*; // Required library import java.awt.*; // Required library import java.awt.event.*; // Required library import javax.swing.JOptionPane; public class HW9_2 extends JFrame { private JTextField tField = new JTextField("Enter Password"); // Create a text field private JLabel labelWithtField = new JLabel(""); private JButton my1Button = new JButton("Login"); // Create a new button private JLabel label1WithText = new JLabel(); private JButton my2Button = new JButton("Mickey Mouse"); // Create a new button private JLabel label2WithText = new JLabel(); private JButton my3Button = new JButton("Donald Duck"); // Create a new button private JLabel label3WithText = new JLabel(); private int status = 1; private double mm = 0; private double dd = 0; private int i = 0; private int c = 0; // Constructor public HW9_2() { setLayout(new GridLayout(2, 2, 0, 0)); // Define layout as a grid add(tField); add(labelWithtField); add(my1Button); // Make button appear in window add(label1WithText); add(my2Button); // Make button appear in window add(label2WithText); add(my3Button); // Make button appear in window add(label3WithText); my1Button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { double[] listlogin; // Declare the array listlogin = new double[100]; //String tField = tField.getText(); // Get the text in the TextField String str = tField.getText(); double login = Double.parseDouble(str); if (status == 1) { listlogin[c] = login; c++; } for (int i = 1; i < listlogin.length; i++) { // Process array with loop if (listlogin[c] == listlogin[i]) { JOptionPane.showMessageDialog(null, "ERROR"); } } }});
thanks for your help
- 11-13-2009, 11:21 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
1.) The array containing the passwords must not be created in the action listener because it handles multiple actions. It must be an instance variable of the class and the actionPerformed can check against it and add to it.
2.) If the array of passwords is not persisted then running the program again will always use a new array of passwords since all the program's data will go away when the application is closed.
- 11-13-2009, 11:33 AM #3
Similar Threads
-
Password asking
By Kruptein in forum New To JavaReplies: 23Last Post: 08-18-2009, 09:28 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum New To JavaReplies: 2Last Post: 11-14-2008, 07:53 PM -
how to check password for 3 times enterd wrong password
By sk.mahaboobbhasha@gmail.c in forum Java ServletReplies: 0Last Post: 11-14-2008, 01:22 PM -
How to check password of a jsp/html with the password of Database(mysql) #1
By sk.mahaboobbhasha@gmail.c in forum Java ServletReplies: 2Last Post: 11-14-2008, 01:11 PM -
How to get password in SWT
By Java Tip in forum SWTReplies: 0Last Post: 07-02-2008, 08:04 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks