Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help with adding letters

 
Lovro Posaric
Greenhorn
Posts: 11
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
I need help with my application...
I've made application with JComboBox, few buttons...I've filled jComboBox with arraylist...I want to add letter by letter to jLabel...I have done this:

but it doesn't reset letters counter(brojSlovaInfinitiv)...to 0 when word in jComboBox is changed...

Thanks & sorry for bad english..!
 
Tony Docherty
Bartender
Posts: 2969
59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From the description and code posted it's a bit hard to give a definitive answer as I'm not entirely sure what you are trying to achieve or how you have gone about it but you probably need to add a selection listener to your combo box and in the listener check if the selection has changed and if so reset your counter.
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OP, as Tony said you should post more detailed description of the problem you are facing and in this case SSCCE that we can go through. It is difficult to get the problem in deep, even for me who understand those variable names.

Edit: I see from your posts that you use NetBeans for your GUI applications extensively. But, what I've noticed is that you leave components with default names that NetBeans gives (e.g. jLabel1, jPanel1, jButton1, ...). I would suggest you modify it each time you add a component to your GUI. The reason is simple - your code will be more readable (even to yourself) and easier to maintain later.
 
Lovro Posaric
Greenhorn
Posts: 11
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi!
Sorry for late answer..I wasn't able to answer beacause I wasn't at my computer...
Here is the code..(deleted part of arrays..)


brojSlova* are conuters how many letters are added to jlabel...
And I used netbeans only to add ActionListener for every button itself...
So I want to when some verb(item from jComboBox1) is changed to restart letter counter(eg. brojSlovaInfinitiv)...
I haven't modified names of most of labels(I renamed only ones what I use(change their text)), there are just few buttons so I didn't rename them...
I hope you understand what I want to do..

L
Thanks!
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you please give some test data for those String arrays you are declaring at lines 18-22? I still can't get really into this application, and it seems interesting to me.
From your first post, you said:
but it doesn't reset letters counter(brojSlovaInfinitiv)...to 0 when word in jComboBox is changed...

You don't have any listener for your combo box, so you can't know when the value is changed. You can resolve this by adding a listener to it:
 
Lovro Posaric
Greenhorn
Posts: 11
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh...thanks...
As you see from listener: it checks if text from jTextField equals word from arraylist...so you can add whatever word you want..

THANKS AGAIN!
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh, I see it now.
Well, everything you need to add is in that listener I mentioned in my previous post. Reset that variable you were talking about in your original post, set those labels in the bottom to empty string after the value in combo box is changed and it should work properly.

Greetings from neighbourhood!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic