• Post Reply Bookmark Topic Watch Topic
  • New Topic

Password Fields  RSS feed

 
Amber Townsend
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I am not a programmer, but my boyfriend is. I'm trying to make a really simple short program I can send to him for his birthday in a few days (he's abroad until September, so I can't actually give him anything), which I thought would be a nice personal way of sending a happy birthday message So I really am a beginner!

I've been googling to see if there's anything on the internet to help me, but everything I find is in programming-technical-terms-garble that I really can't follow.

I'm doing ok and most of the program seems to work, but I can't figure out how to make a password submit. I can type in the password field, and I think I've set it up correctly, but nothing happens when I press enter. Can anyone help me out? I've put the relevant bits of code below.

I downloaded and am working in NetBeansIDE 7.3.1. The thing I really don't understand is there's no red squiggly lines under anything, so all the password code makes sense, but doesn't... work.

If anyone could tell me where I'm going wrong/what I need to add in that'd be great.

Any ideas?
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amber Townsend wrote:If anyone could tell me where I'm going wrong/what I need to add in that'd be great.

I suspect that's your problem right there; unless you're using an IDE (like NetBeans) to write your code for you.

The method is called actionPerformed, so the correct signature is:
public void actionPerformed(java.awt.event.ActionEvent evt) ...

You don't name it for the class.

BTW, if you're not a programmer, trying to write program that takes a password is pretty bold. I applaud you, but don't expect to get it right first time.

Winston
 
Amber Townsend
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You beautiful man, thank you for replying so quickly!

I've changed that bit to what you suggested, but still nothing's happening when I press enter :/
Have I not linked it up to making a new dialog visible or something ?

And thank you- it is a bit ambitious, but I thought I should add in something that wasn't just a button making a new frame visible or not visible :|
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch. How sweet of you to send a "program" to your bf.

Anyway let me guess, your isPasswordCorrect() method always return false?

Assume your correct password is "hi" in char array, you need a way to check this against the input char array. And return this checking.



There's lots of way to check array content, Arrays.equals() is just one approach.

Hope this helps.
 
Amber Townsend
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Fantastic, thank you very much!
I've changed that in my code, but the enter key still isn't submitting the password, so a new dialog isn't opening do you know why this might be?
Here's the code now:


 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you adding the action listener to the button? The actionPerformed(ActionEvent evt) method is supposed to be overridden.

 
Amber Townsend
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this what you mean? Because this seems to have caused a lot of red squigglies to appear under sections of the code




Sorry if I'm being dense!
 
Amber Townsend
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hmm. Also all my previous commands i.e.




Stop working if I put in your suggested code- it says it can't find the symbols suddenly? D:
 
K. Tsang
Bartender
Posts: 3648
16
Firefox Browser Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well basically the actionPerformed() method and its relevant/called methods (eg isPasswordCorrect()) should be in a class of its own (separate file or as an inner class).

Don't try to incorporate my or other people's code suggestion for the sake of it. Because we don't know your entire source.

Feel free to PM me if you get stuck.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!