Results 41 to 45 of 45
- 03-15-2012, 02:36 PM #41
Re: create moving points with respect to time
What do you mean by "one by one"?
Is it this:
draw shape 1
wait some
draw shape 2
wait some
etc
Your code does NOT follow the design I recommended earlier:
1) Do the drawing in the paintComponent method using the Graphics object passed to the method
2) compute the positions in the Time listener method and call repaint()
- 03-15-2012, 02:54 PM #42
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: create moving points with respect to time
Thanks for ur reply. Yes I want to draw a shape, wait, draw another and wait and so on.
Actually I got different kind of output from my experiment today, where I don't have to calculate the locations. I just have to enter my result in x and y positions. So, I didnot write any method to calculate locations.
Now everything worked. but the only thing is to draw shape, wait, draw next shape, wait and so on... and after drawing the last shape, I want to erase all the shapes drawn before.
Please help. Thanks.
- 03-15-2012, 02:57 PM #43
Re: create moving points with respect to time
You need to post your code and explain what the problem is with it.
The last code you posted was wrong. It did not draw in the paintComponent method.
- 03-15-2012, 05:49 PM #44
Member
- Join Date
- Mar 2012
- Posts
- 22
- Rep Power
- 0
Re: create moving points with respect to time
Hi..
I have created instance of a class LadderContruction in my code. That class has the paintcomponent method. That paint component method draws a ladder in my JFrame. that is fine.
The code I post here draws just the shapes on this ladder that I created in previous paint component method. Everything is working fine.
and I added thread.sleep(1000)Java Code:import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*; import javax.swing.*; public class TimerRun extends JFrame implements ActionListener { /** * */ private static final long serialVersionUID = -6910867316879215818L; private JPanel container; LadderConstruction lc= new LadderConstruction(); RungCoordinates rc = new RungCoordinates(); private Timer timer1 = new Timer(2000, this); //private Timer timer2 = new Timer(1000, this); int x = rc.r5x; int y= rc.rY; int yl = rc.lY; int x1 = rc.l7x; int x2 = rc.l8x; int x3 = rc.r10x; int x4 = rc.l13x; int x5 = rc.r15x; int x6 = rc.l18x; int x7 = rc.r21x; public TimerRun() { //set initial delay to 1000 milliseconds timer1.setInitialDelay(1000); timer1.getDelay(); //timer2.setInitialDelay(2500); //initialize window container = new JPanel(); this.add(container); this.add(lc); //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(1200,1200); this.setVisible(true); //start timer timer1.start(); //timer2.start(); } /** * when timer begins this method draws rectangles from left to right */ public void actionPerformed(ActionEvent e) { Graphics g = lc.getGraphics(); g.setColor(Color.CYAN); g.drawRect(x, y, 10, 5); g.fillRect(x, y, 10, 5); // R5 rung g.drawRect(x1, yl, 10, 5); g.fillRect(x1, yl, 10, 5); // L7 rung g.setColor(Color.MAGENTA); g.drawRect(x, y, 10, 5); g.fillRect(x, y, 10, 5); // R5 2nd time g.drawRect(x2, yl, 10, 5); g.fillRect(x2, yl, 10, 5); // L8 g.drawRect(x3, y, 10, 5); g.fillRect(x3, y, 10, 5); // R10 g.setColor(Color.RED); g.drawRect(x, y, 10, 5); g.fillRect(x, y, 10, 5); // R5 3rd time g.setColor(Color.MAGENTA); g.drawRect(x3, y, 10, 5); g.fillRect(x3, y, 10, 5); // R10 2nd time g.setColor(Color.MAGENTA); g.drawRect(x2, yl, 10, 5); g.fillRect(x2, yl, 10, 5); // L8 2nd time g.setColor(Color.CYAN); g.drawRect(x4, yl, 10, 5); g.fillRect(x4, yl, 10, 5); // L13 g.setColor(Color.RED); g.drawRect(x3, y, 10, 5); g.fillRect(x3, y, 10, 5); // R10 3nd time g.setColor(Color.MAGENTA); g.drawRect(x4, yl, 10, 5); g.fillRect(x4, yl, 10, 5); // L13 2nd time g.setColor(Color.RED); g.drawRect(x4, yl, 10, 5); g.fillRect(x4, yl, 10, 5); // L13 3rd time g.setColor(Color.CYAN); g.drawRect(x5, y, 10, 5); g.fillRect(x5, y, 10, 5); // R15 rung g.setColor(Color.YELLOW); g.drawRect(x4, yl, 10, 5); g.fillRect(x4, yl, 10, 5); // L13 4th time g.setColor(Color.MAGENTA); g.drawRect(x5, y, 10, 5); g.fillRect(x5, y, 10, 5); // R15 2nd time g.setColor(Color.CYAN); g.drawRect(x6, yl, 10, 5); g.fillRect(x6, yl, 10, 5); // L18 rung g.setColor(Color.RED); g.drawRect(x5, y, 10, 5); g.fillRect(x5, y, 10, 5); // R15 3rd time g.setColor(Color.MAGENTA); g.drawRect(x6, yl, 10, 5); g.fillRect(x6, yl, 10, 5); // L18 2nd time g.setColor(Color.CYAN); g.drawRect(x7, y, 10, 5); g.fillRect(x7, y, 10, 5); // R21 rung timer1.stop(); } public static void main(String[] args){ TimerRun display = new TimerRun(); } }
after drawing each shape. So they are drawn one by one. But after finishing the drawing, I want to disappear all the shapes. For this, I need some syntax related help. Thank you.
- 03-15-2012, 06:30 PM #45
Similar Threads
-
[jFreeChart] Converting screen-points to points, which are relative to the axis
By fyaxic in forum AWT / SwingReplies: 1Last Post: 08-11-2011, 10:46 AM -
code for moving objects at same time
By Muhammad Assad in forum New To JavaReplies: 13Last Post: 06-20-2010, 05:11 PM -
Problem in rotating and moving image at the same time
By Babar in forum Java 2DReplies: 3Last Post: 06-16-2010, 10:27 PM -
given number of points(cordinates) , find max points lie on the same line ?
By Hayzam in forum New To JavaReplies: 2Last Post: 08-24-2008, 12:30 AM -
Urgent-Imp-Displaying message with respect to system time
By garinapavan in forum New To JavaReplies: 1Last Post: 08-03-2007, 02:17 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks