Results 1 to 4 of 4
Thread: trouble animating
- 11-30-2010, 03:20 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 38
- Rep Power
- 0
trouble animating
myThing is a rectangle, which I want to see move horizontally a bit. But this doesn't happen; the rectangle just flickers a bit in its original position, which is where it stays put.
Would appreciate any help; thanks.
Java Code:public class MovingThing extends JFrame { ... private Thing myThing = new Thing(); ... public void paint(Graphics g) { super.paint(g); myThing.paint(g); } private class TryThisButtonWatcher implements ActionListener { ActionListener moveHorizontally = new ActionListener() { public void actionPerformed(ActionEvent a) { for (int i=0; i<10; i++) { myThing.setParams(100+5*i,300,100,50); repaint(); } } }; Timer myTimer = new Timer(1000, moveHorizontally); public void actionPerformed(ActionEvent a) { myTimer.start(); } } // end of: private class TryThisButtonWatcher implements ActionListener ... ... } public class Thing extends JComponent { private int one, two, three, four; public Thing() { } public void paint(Graphics g) { super.paint(g); g.drawRect(one, two, three, four); } public void setParams(int a, int b, int c, int d) { one = a; two = b; three = c; four = d; } } // end of: public class Thing extends JComponent
-
For me at least there are too many details unknown here. You should try to create a very small compilable and runnable program that demonstrates your problem. It won't need a JButton, just a JPanel to do your drawing in (you should paint in the JPanel's paintComponent method, never the JFrame's paint method). In short, an SSCCE.
Luck!
-
- 11-30-2010, 03:22 PM #4
Member
- Join Date
- Nov 2010
- Posts
- 38
- Rep Power
- 0
Similar Threads
-
Trouble with paintComponent()
By ShirlyPunk in forum AWT / SwingReplies: 17Last Post: 03-13-2010, 04:27 PM -
GUI Trouble
By rvgsd in forum New To JavaReplies: 2Last Post: 03-07-2010, 12:10 AM -
Here comes trouble... :-)
By sargehendricks in forum IntroductionsReplies: 1Last Post: 04-23-2009, 03:18 PM -
trouble with actionPerformed
By diggitydoggz in forum New To JavaReplies: 2Last Post: 12-26-2008, 02:18 AM -
having some trouble
By Unknown1369 in forum New To JavaReplies: 13Last Post: 07-21-2008, 11:52 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks