Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package java2d;
- import java.awt.*;
- import java.awt.geom.*;
- import javax.swing.JFrame;
- public class DDA extends JFrame {
- public static void main(String[] args) {
- JFrame frame = new JFrame();
- DDA z = new DDA();
- z.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- z.setVisible(true);
- z.setTitle("Java 2D program");
- z.setSize(1024,768);
- }
- public void paint (Graphics g)
- {
- Graphics2D g2d = (Graphics2D) g;
- double dx,dy,steps,x1,x2,y1,y2;
- double x3,y3,xinc,yinc;
- x1=110; y1= 150 ; x2 = 500; y2 = 140;
- dx = x2-x1;
- dy = y2-y1;
- if(Math.abs(dx) > Math.abs(dy))
- {
- steps = Math.abs(dx);
- }
- else
- steps = Math.abs(dy);
- xinc = (float)dx/steps;
- yinc = (float)dy/steps;
- x3 = x1; y3 = y1;
- drawPoint(x3,y3,g2d);
- for(int i = 1; i<steps;i++)
- {
- x3 = x3+xinc;
- y3 = y3 + yinc;
- drawPoint((int)(x3+0.5),(int) (y3+0.5),g2d );
- }
- }
- public static void drawPoint(double x , double y,Graphics2D g2d)
- {
- Line2D.Double line = new Line2D.Double(x, y, x, y);
- g2d.setColor(Color.red);
- g2d.draw(line);
- }
- }
Add Comment
Please, Sign In to add comment