Results 1 to 5 of 5
Thread: Moving lines using timer
- 07-06-2011, 07:58 AM #1
Member
- Join Date
- Jul 2011
- Location
- Chennai,India.
- Posts
- 3
- Rep Power
- 0
- 07-06-2011, 09:17 AM #2
In order to properly help you, we really need more specifics than that. Do you have any code yet? What exactly is it supposed to do? Things like that.
- 07-06-2011, 10:56 AM #3
Moving this thread to Java 2D ...
db
- 07-06-2011, 03:49 PM #4
Member
- Join Date
- Jul 2011
- Location
- Chennai,India.
- Posts
- 3
- Rep Power
- 0
Moving lines
I have a code.It display lines from al corner.
I want to do simple animation in it.
All lines are move slowly from all corner using timer or loops.
Thanks
import java.awt.Graphics;
import java.awt.Point;
import javax.swing.*;
public class DrawPanel extends JPanel {
Point p = new Point(1,21);
public DrawPanel()
{
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
int width=getWidth();
int height=getHeight();
int h=height/2;
int w=width/2;
int h1=h/15;
int w1=w/15;
for(int i=1;i<=15;i++)
{
w1+=85;
height-=64;
g.drawLine(0,0,w1,height);
}
for(int i=1;i<=15;i++)
{
w1-=85;
height+=64;
g.drawLine(1280,962,w1,height);
}
for(int j=1;j<=15;j++)
{
width-=85;
height-=64;
g.drawLine(1280,0,width,height);
}
for(int j=1;j<=15;j++)
{
width+=85;
height+=64;
g.drawLine(0,962,width,height);
}
}
}
import java.awt.GraphicsConfiguration;
import java.awt.Rectangle;
import java.awt.Window;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
public class DrawPanelT {
public static void main(String args[])throws Exception
{
final DrawPanel pan=new DrawPanel();
JFrame jf = new JFrame();
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.add(pan);
jf.setSize(250, 250);
jf.setVisible(true);
}
}
- 07-06-2011, 03:58 PM #5
Do you mean you want the position that a line is displayed at changed over time?All lines are move slowly from all corner
Then change the x,y used by the drawLine method
Please edit your code and wrap it in code tags to preserve its formatting. See:http://www.java-forums.org/misc.php?do=bbcode#code
Similar Threads
-
Timer And Timer Task
By Ashish_jain in forum New To JavaReplies: 3Last Post: 06-22-2011, 09:41 AM -
Cannot Add new Lines
By capjoel in forum New To JavaReplies: 3Last Post: 04-01-2011, 06:33 PM -
What do these lines mean?
By coding in forum New To JavaReplies: 5Last Post: 02-02-2011, 03:01 AM -
Stopping a Timer from Inside the timer
By krishnan in forum Java AppletsReplies: 2Last Post: 10-04-2010, 11:15 PM -
How to cancel an individual timer in spite of canceling whole timer
By Java Tip in forum java.utilReplies: 0Last Post: 04-04-2008, 02:46 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks