• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please can someone help me password my Java program!

 
Howard owen
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Pie
Posts: 42966
73
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Howard owen
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yea that sounds good, but how can i do it?
thanks
 
marc weber
Sheriff
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Howard owen
Greenhorn
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11343
Java Mac Safari
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 1367
18
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What does your main method look like?
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic