Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  d
Language: JAVA
Code:
import java.util.*;
import java.awt.*;
import javax.swing.*;

public class dda
 {

    public static void main(String[] args) {
   
    DrawFrame app=new DrawFrame();
    app.setVisible(true);
         
          
    }
    
    
}
class DrawFrame extends JFrame
{ double x1,x2,y1,y2,dx,dy,l,x,y,I,tx,ty;
DrawFrame()
     {
          setSize(800,800);
          setTitle("Drawing");
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     Scanner sc=new Scanner(System.in);
    System.out.println("enter value of x1");
     x1=sc.nextFloat();
     System.out.println("enter value of x2");
     x2=sc.nextFloat();
     System.out.println("enter value of y1");
    y1=sc.nextFloat();
      System.out.println("enter value of y2");
      y2=sc.nextFloat();
       dy=(y2-y1);
       dx=x2-x1;
           
     }
          public void paint(Graphics g)
     {
          myline(g);
     }
     void myline(Graphics g)
     {
     
       g.setColor(Color.red);
          if(dx>=dy)
          {
               l=dx;
          }
          else
          {
               l=dy;
          }
          tx=dx/l;
          ty=dy/l;
          x=x1;
          y=y1;
          

          for(int j=1;j<=l;j++)
          {
          
          
               
               x=x+tx;
               y=y+ty;
               g.drawLine((int)x,(int)y,0,0);
          }
          
          }
     }
     
Comments: