Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

16 replies to this topic
#13
Posted 24 November 2011 - 11:26 PM
What does the actionPerformed(ActionEvent e) method look like?
#14
Posted 25 November 2011 - 06:37 AM
Ok, excuses me for incomplete information. So let me explain the whole idea. I have one class that has an ArrayList and keep a record (history) of every pattern that user made by making moves. I have a GUI class that extends JFrame and the only work there is receiving a pattern each time and update its view and a third class that extends ActionPerformed and when a button clicked doing a different job. For example, if click a square on the board, modifying the current state in order to looks like the user's choice, and store this new pattern in the ArrayList. Now I'm stuck on a point that a button (Replay) when pressed, should start from the very first pattern in the ArrayList and every 1 sec I want to move to the next(update the GUI) until reach the latest pattern. Here for a reason my update not working properly on the GUI (but if print out the patterns on "console" working perfect) stuck at the beginning, and not show some patterns. My question is how to fix this, where to create new Thread ? In the ActionPerformed class where Replay button executed, or in JFrame class where GUI ceated?
Please help
Thank you
Please help
Thank you
"Programming is like **. One mistake and you have to support it for the rest of your life."
-Michael Sinz
#15
Posted 25 November 2011 - 06:59 AM
toto_7 you think you could post the classes. There could be other issues. It's a bit difficult sometimes, to see the big picture from all these code snippets and explanations.
#16
Posted 25 November 2011 - 08:36 AM
Well, the fact that your GUI doesn't update means you're doing stuff in the actionperformed which you shouldn't be doing there. So again, Post the actionPerformed code please.
#17
Posted 27 November 2011 - 03:15 AM
Sorry guys, away from my machine for a while. Ok, here is my code in ActionPerformed for "Replay" button:
As you can see, modified my previous code a little. I don't know if now is worst or not but the result is, NO REPLAY. Checked and I'm sure that each pattern from the list is going to GUI for initialization but for a reason, GUI has always the "shape" of the very last pattern. How to change my code in order to work?
Thank you
public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals("replay")){ if(view.replay.getIcon().toString().equals(replay.toString())){//If Icon is REPLAY while(!view.listOfUndos.isEmpty()){//if user made some undo moves++; int size = view.listOfUndos.size(); String lastUndo = view.listOfUndos.get(size-1); view.listOfMoves.add(lastUndo);//Bring them back to list of moves view.listOfUndos.remove(size-1);//remove them } view.replay.setIcon(stop);//Change the Icon to STOP(Also now my program not changing Icon) SwingUtilities.invokeLater(Replay);//Do the Replay } else view.replay.setIcon(stop); } } Runnable Replay = new Runnable(){ public void run() { for(int i=0; i<model.userStates.size(); i++){//For the size of list of Patterns(History) synchronized(model){//Notify the other class(Contains method to notify the GUI and update it with new pattern) model.currentState = model.userStates.get(i);//Make the current equal to i model.notify();//Notify the model class } try { Thread.sleep(1000); } catch (InterruptedException e) {} } } };
As you can see, modified my previous code a little. I don't know if now is worst or not but the result is, NO REPLAY. Checked and I'm sure that each pattern from the list is going to GUI for initialization but for a reason, GUI has always the "shape" of the very last pattern. How to change my code in order to work?
Thank you
"Programming is like **. One mistake and you have to support it for the rest of your life."
-Michael SinzAlso tagged with one or more of these keywords: using thread
Tutorial Forums →
Java Tutorials →
Burning candles Java applet using threadsStarted by Nyfer, 13 Oct 2011 ![]() |
|
![]() |
||
Language Forums →
Java →
Java - Countdown using Thread problemStarted by Serialcek, 15 Feb 2011 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Displaying progressbar using threading in win 32 applicaition!Started by rakeshsr, 27 Apr 2010 ![]() |
|
![]() |
||
Language Forums →
C and C++ →
Shared Memory implementation using thread ( C on AIX)Started by kumars, 18 Jun 2008 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download