Results 1 to 9 of 9
Thread: Help with JButtons...
- 01-26-2009, 08:22 AM #1
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
Help with JButtons...
Hi guys... can I ask a question?
Why is it that a JButton only works once??
I have a problem with my program... It works this way:
Imagine this. In front of you, there is a small GUI that has a textfield for the user to input his name.. Now, you type in your name and then, BOOOM!!! your picture pops up on the corner... (well, ofcourse your picture is built-in into the program..). BUT BUT bUT... Your friend wants to see his face, he takes your seat and types his name in the textfield, but when he clicked on the button, nothing happens...
This is my sample statement:
is there a way to keep the button working continuously?? coz it only works once.. do i need to have a do{}while(); or something like that? Do you still need to have a looping statement around the button's "ActionPerformed" code??Java Code:if(name.equals("john")){ jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swingPack/joham.jpg"))); }else if(name.equals("Smiley")){ jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swingPack/smiley.jpg"))); } }
Thank you in advance...
- 01-26-2009, 08:52 AM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Ok, you have if-else condition in the above. What happen if you call it with different parameters several times?
- 01-26-2009, 09:02 AM #3
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
woah! you got me there!
woah! you got me there! :D
uhm.. honestly, the term parameter is not that clear to me... please clarify it.. i really need your help.. please define it in a 'newbie term'... tnx
- 01-26-2009, 09:17 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
I'm talking about this.
Java Code:name.equals("john")
- 01-26-2009, 09:20 AM #5
Member
- Join Date
- Jan 2009
- Posts
- 10
- Rep Power
- 0
send me the action of the Jbutton
- 01-26-2009, 09:24 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 01-26-2009, 09:34 AM #7
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
well...
here's the action:
(should've placed the first lines.. haha:D sorry 'bout that..)
Java Code:private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { String name = nameField.getText(); String age = ageField.getText(); if(name.equals("john")){ jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swingPack/joham.jpg"))); }else if(name.equals("Smiley")){ jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/swingPack/smiley.jpg"))); }
- 01-26-2009, 09:36 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
As the other thread explain you have to think about a way to repaint the component with new stuff you want to have on that.
- 01-26-2009, 09:38 AM #9
Member
- Join Date
- Jan 2009
- Posts
- 31
- Rep Power
- 0
what a stupid move!!!!!!!
:eek:]
don't worry guys! I'm ok! i'm ok! tnx for the replies though...
I'm so stupid!!! take a close look at the ...}else{... line, i typed in
Smiley... with a capital 'S'!! i was just typing 'smiley' all the time... That letter 's' is the one... Sorry for this guyz.. that's why smiley's face doesn't show up.. stupid me...:D
Similar Threads
-
JButtons
By jadaleus in forum Advanced JavaReplies: 4Last Post: 10-17-2008, 02:49 AM -
2D Array of JButtons
By stevemcc in forum AWT / SwingReplies: 1Last Post: 02-16-2008, 11:42 PM -
JButtons
By fgasimzade in forum SWT / JFaceReplies: 1Last Post: 12-25-2007, 05:39 AM -
how to change the appearance of jbuttons
By katie in forum AWT / SwingReplies: 1Last Post: 08-06-2007, 10:26 PM -
disabling JButtons after win in TicTacToe
By noisepoet in forum New To JavaReplies: 1Last Post: 05-18-2007, 11:01 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks