• Post Reply Bookmark Topic Watch Topic
  • New Topic

refresh textField and clear textArea when button clicked

 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all

I have 3 days holiday and i decided to write a small program with a Pokemon background to teach
my kid basic math.

My problem is textField is not updating and textArea is not clearing when clicking Button for next question.
When i clear background image then textField updating however textArea looks like cleared but when pointer focus inside
of textArea then previous answer stays there.

When background image is visible then textField shows first question when program executed also textArea keep very first thing at the beginning.

Following code produce something like this
2 + 6
3 + 2
8 + 4
.... each time click the button.


I am doing something wrong but i don't know what it is.

Appreciate any help

Regards

 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is something wrong with having the listener add itself again. That can cause no end of confusion. Remove the setElements call from the actionPerformed method. Similarly revalidate() and repaint().
There is also something wrong with only having setVisible in the invokeLater call. I think you should have new XYZFrame().setVisible().
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The reason; why listener event call it self is just i want to make it loop until close window.
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, the listener is not calling itself. It is adding itself.
 
ibrahim yener
Ranch Hand
Posts: 202
Android Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear Ritchie
do you have any suggestion? I really stuck here.

Actually, i came up with an idea such as create exact same class named like BasicMath2 and just keep swapping forms by sending parameters. But this will look real amateur and i want professional looks and approach.

Regards
 
Campbell Ritchie
Marshal
Posts: 52581
119
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Create a method which does the arithmetic and updates the display. Call that method from the action performed method.

You are going about this the wrong way. You should have an application which runs at the command line/terminal and shows you the arithmetic. Then you put a GUI on top of it. You appear to be designing the GUI first.
Why has your frame got a static field of the same type? That looks very peculiar.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!