wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes please can someone help me password my Java program! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "please can someone help me password my Java program!" Watch "please can someone help me password my Java program!" New topic
Author

please can someone help me password my Java program!

Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
Hi all. Iv made an personal organiser application in netbeans and Id like to password it for extra marks. Iv been using my textbook and written the following code, which compiles fine, but i dont know how to use it. What id like it to do is ask for a username and password when the program is first run, it dosent really matter if it isnt the right password as long as it looks like it works! Heres the code iv done so far. If anyone could help id be really greatful!


public class TestApp implements ActionListener {
JTextField textField;

public void actionPerformed(ActionEvent e) {
JButton button = (JButton)e.getSource();
String ac = button.getActionCommand();
if(ac.equals("log in"))
System.out.println("logging in..." + textField.getText());

}

private JPanel getContent() {
textField = new JTextField(12);
JButton logIn = new JButton("log in");
logIn.setActionCommand("log in");
logIn.addActionListener(this);
JPanel p = new JPanel();
p.add(new JLabel("name:"));
p.add(textField);
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("sign in", JLabel.CENTER), "North");
panel.add(p, "Center");
p = new JPanel();
p.add(logIn);
panel.add(p, "South");
return panel;


}
}
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41106
    
  45
What you could do is to have a little dialog that is shown when the application starts up, before the main GUI is created. In it you'd have two fields, username and password (or just password if that's sufficient for your purposes), and a "Login" button. Once the button is pressed, the password is checked, and if it's OK, the application continues to start up. If it's not OK, the dialog remains in place, and the main GUI isn't shown; or the application quits altogether.


Ping & DNS - my free Android networking tools app
Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
Yea that sounds good, but how can i do it?
thanks
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Howard owen:
Yea that sounds good, but how can i do it?
thanks

I think Ulf laid out the steps pretty well. Give it a try, and we'll help you with the details if you get stuck.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
Hi, im sorry im still at a loss. The code i made was from my java cookbook, its all there and it builds and compiles fine, i just cant get it to pop up. Please can someone help!!
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by Howard owen:
Hi, im sorry im still at a loss. The code i made was from my java cookbook, its all there and it builds and compiles fine, i just cant get it to pop up. Please can someone help!!

Can you show us that code?
Howard owen
Greenhorn

Joined: Aug 21, 2007
Posts: 8
It was in my first post,

public class TestApp implements ActionListener {
JTextField textField;

public void actionPerformed(ActionEvent e) {
JButton button = (JButton)e.getSource();
String ac = button.getActionCommand();
if(ac.equals("log in"))
System.out.println("logging in..." + textField.getText());

}

private JPanel getContent() {
textField = new JTextField(12);
JButton logIn = new JButton("log in");
logIn.setActionCommand("log in");
logIn.addActionListener(this);
JPanel p = new JPanel();
p.add(new JLabel("name:"));
p.add(textField);
JPanel panel = new JPanel(new BorderLayout());
panel.add(new JLabel("sign in", JLabel.CENTER), "North");
panel.add(p, "Center");
p = new JPanel();
p.add(logIn);
panel.add(p, "South");
return panel;


}
}
Katrina Owen
Sheriff

Joined: Nov 03, 2006
Posts: 1357
    
  17
What does your main method look like?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please can someone help me password my Java program!
 
Similar Threads
Scrollbar for jtable
JPanel on JScrollBar possible?
Help with a simple login Gui
I got runtime error
Why are my JFrames closing?