<br>
Ex. No.:1
LINE DRAWING USING DDA ALGORITHM
import java.awt.*:
import java.awt.cvent.*:
import java.applet.*;
P <Applet code=dda height=5000 width-5000> </Applct> */
public class dda extends Applet implemcnts ActionListencr
Label l1,12,13.14;
TextFicld t1.(2.t3,t4;
int x.y.xl.yl.x2.y2,dx,dy, xincr,yincr,steps;
Button b:
public void init()
{
||=new Labcl("Enter the value of x1:");
tl=new TextField(4):
12=new Label("Enter the value of yl:"):
t2-new TextField(4):
13=new Label("Enter the value of x2:");
t3=new TextField(4);
14=new Label("Enter the value of y2:");
t4=new TextField(4);
b=new Button("line");
add(|l);add(t1);
add(12);add(12);
add(13 );add(t3);
add(14);add(t4);
add(b):
b.addActionListener(this);
actionPerformed(ActionEvent ae)
public void
x1=Integer.parselnt(t1.getText());
yl=Integer.parselnt((2.getTexI();
x2=Integer.parselnt(t3.getText());
y2=Integer.parselnt(t4.getText(0):
repaint();
public void paint(Graphics g)
dx=x2-x1;
dy=y2-yl;
if(dx>dy)
steps-dx;
else
steps=dy:
xincr=dx/steps;
yincr=dy/steps;
,<br>
N=X1;
y-yl;
g.fillOval(x,y, 1,1);
g.drawString(x+ "," +y,x,y);
for(int k=1;k<steps;k++)
X=X+Xncr;
y=ytyincr;
g.fillOval(x,y,1,1);
g.drawString(x+ +y,x,y);
,<br>
5
OUTPUT
Apeet
i
dda
Aeptel
Enter hevae of 00 Enter he vaue et 2
o
+03,200
299, 09
roletstattd
Arpit
vi
dda
300 Enter the value of y2 800
Artiel
Enter he value ct P00 Enter the value of yt 600 Enter the vsiue of
2
200600 9600
Acplet staned
, <br>
Enter hvaue of 2 300 Erter the vslue of y2 600 tne
Enter h vake of t 50
9599
300 Enter the value ot y1 400 Enter the value of x2 300 Enter the value of y2 600 kne
bog.599
Ex. No.:1
LINE DRAWING USING DDA ALGORITHM
import java.awt.*:
import java.awt.cvent.*:
import java.applet.*;
P <Applet code=dda height=5000 width-5000> </Applct> */
public class dda extends Applet implemcnts ActionListencr
Label l1,12,13.14;
TextFicld t1.(2.t3,t4;
int x.y.xl.yl.x2.y2,dx,dy, xincr,yincr,steps;
Button b:
public void init()
{
||=new Labcl("Enter the value of x1:");
tl=new TextField(4):
12=new Label("Enter the value of yl:"):
t2-new TextField(4):
13=new Label("Enter the value of x2:");
t3=new TextField(4);
14=new Label("Enter the value of y2:");
t4=new TextField(4);
b=new Button("line");
add(|l);add(t1);
add(12);add(12);
add(13 );add(t3);
add(14);add(t4);
add(b):
b.addActionListener(this);
actionPerformed(ActionEvent ae)
public void
x1=Integer.parselnt(t1.getText());
yl=Integer.parselnt((2.getTexI();
x2=Integer.parselnt(t3.getText());
y2=Integer.parselnt(t4.getText(0):
repaint();
public void paint(Graphics g)
dx=x2-x1;
dy=y2-yl;
if(dx>dy)
steps-dx;
else
steps=dy:
xincr=dx/steps;
yincr=dy/steps;
,<br>
N=X1;
y-yl;
g.fillOval(x,y, 1,1);
g.drawString(x+ "," +y,x,y);
for(int k=1;k<steps;k++)
X=X+Xncr;
y=ytyincr;
g.fillOval(x,y,1,1);
g.drawString(x+ +y,x,y);
,<br>
5
OUTPUT
Apeet
i
dda
Aeptel
Enter hevae of 00 Enter he vaue et 2
o
+03,200
299, 09
roletstattd
Arpit
vi
dda
300 Enter the value of y2 800
Artiel
Enter he value ct P00 Enter the value of yt 600 Enter the vsiue of
2
200600 9600
Acplet staned
, <br>
Enter hvaue of 2 300 Erter the vslue of y2 600 tne
Enter h vake of t 50
9599
300 Enter the value ot y1 400 Enter the value of x2 300 Enter the value of y2 600 kne
bog.599