Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

Line Translation 2D

Tue Apr 17, 2007 2:43 pm

This a line Translation using Java . which u change the postion of the line using new dx and dy.
it is so simple to understand.

java code
/*
* Translation.java
* Created on April 17, 2007, 3:32 PM
*/

import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
/**
*
*/
public class Translation extends JFrame{

private int width=400;
private int height=400;
private int x1=-100;
private int y1=-100;
private int x2=100;
private int y2=100;
private int dx=20;
private int dy=20;
public Translation() {
setTitle("Line Translation");
setSize(width,height);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
public void paint(Graphics g) {
g.fillRect(0,0,500,500);
g.setColor(Color.RED);

g.drawLine(x1+200,200-y1,x2+200,200-y2);
g.setColor(Color.GREEN);
g.drawLine(x1+200+dx,200-y1+dy,x2+200+dx,200-y2+dy);

}
public static void main(String[] args) {
// TODO code application logic here
new Translation();
}

}




Post a reply
  Related Posts  to : Line Translation 2D
 Reading a File Line by Line in php     -  
 VB.NET to JAVA translation     -  
 skymiles translation     -  
 search for coding java/jsp for translation text     -  
 Line Rotation 2D     -  
 start a new line in html     -  
 Line Styles in java     -  
 read from command line     -  
 getting a full line input     -  
 DDA Line Drawing Algorithm     -  

Topic Tags

Java Graphics