Results 1 to 13 of 13
- 08-14-2011, 10:54 PM #1
My Run Method Does Not Work Witn Changing JLabel Images From The Other Class?
I guess the title says most of it. What I am trying to do is changing a JLabels icon to another using only another classes public stuff. (Both images, JLabels). In order to do this I am using this piece of code (Note, this is in a class which implements Runnable, so this is into the run(); method):
Java Code:Thread.sleep(1000); Engine Eng = new Engine(); Eng.Grid[1][1].setIcon(Eng.Sprite[0])
Last edited by Alerhau; 08-14-2011 at 11:56 PM.
- 08-14-2011, 11:54 PM #2
I really need quick help.
Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 08-15-2011, 12:29 AM #3
What are your errors? I am guessing that the Engine class is one of your own design, no?
My API:Java Code:cat > a.out || cat > main.class
- 08-15-2011, 01:41 AM #4
Are you using the GUI's thread to do it? Or on your own thread? Have you told the GUI it has new stuff to show?
You are creating a new Engine object. Is there an old one still around that you are looking at expecting it to be changed vs the new one where the changes are being made.
Perhaps a small program (SSCCE) that shows the problem
- 08-15-2011, 10:32 AM #5What are your errors? I am guessing that the Engine class is one of your own design, no?
Are you using the GUI's thread to do it? Or on your own thread? Have you told the GUI it has new stuff to show?
You are creating a new Engine object. Is there an old one still around that you are looking at expecting it to be changed vs the new one where the changes are being made.Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 08-15-2011, 02:26 PM #6Is there an old one still around that you are looking at expecting it to be changed vs the new one where the changes are being made.
Has one been created and is being shown when your posted code is executed which creates a new one.
Otherwise make a small program (SSCCE) that compiles and executes and shows the problem.
- 08-15-2011, 10:25 PM #7How many different places in your code do you create an Engine object?
Has one been created and is being shown when your posted code is executed which creates a new one.Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 08-15-2011, 10:32 PM #8
Can you explain what "is not working" means?
What should the result of the setIcon method call be?
Java Code:Eng.Grid[1][1].setIcon(Eng.Sprite[0])
Why isn't it done in the Eng class's constructor?
Java Code:Grid[1][1].setIcon(Sprite[0]);
- 08-15-2011, 10:59 PM #9
I want this to work because I need Java to change one icon each second that goes, I also need the movement of my game to work at the same time.
So that I can both move my character around on the Grid & change icons every at the same time.
If I just call the Thread.sleep() into the main class (Engine) Everything in the class will sleep.
If there any way to do it into my main class with just making some stuff to sleep at the side of my movement?Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 08-15-2011, 11:08 PM #10
Use a Timer to do something every time period.
It is almost impossible to suggest what to change in your code after seeing 3 lines of code.
If you could make a SSCCE to demonstrate the problem we could make better suggestions.
- 08-16-2011, 11:11 AM #11
How would I make the Timer? Does the timer update, do something every time period? Like every 10 seconds it changes a JLabel icon?
Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 08-16-2011, 11:25 AM #12
Got it to work! Thanks!
Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
- 08-16-2011, 11:25 AM #13
Thanks for all help, the timer worked awsomely amazing!
Currently Developing a Game Called Loaie, You Can Download It From "The Loaie Website".
Similar Threads
-
Modifying JLabel within separate class
By the_rider9 in forum New To JavaReplies: 6Last Post: 07-06-2011, 07:07 PM -
Updating a JLabel from another class.
By Fumomo in forum AWT / SwingReplies: 6Last Post: 05-04-2011, 05:31 PM -
Showing an image with JLabel and ImageIcon - so simple but doesnt work!
By enerj in forum New To JavaReplies: 5Last Post: 12-04-2010, 01:30 AM -
How to resize images to fit JLabel?
By Krooger in forum New To JavaReplies: 3Last Post: 11-24-2010, 02:22 PM -
Changing images by clicking arrow buttons. help?
By ashton in forum New To JavaReplies: 3Last Post: 02-08-2009, 12:29 PM
Bookmarks