Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Java , i need help with my code , i think the problem is in the ( for loop ) this is my code: package
Java , i need help with my code , i think the problem is in the ( for loop ) Output: Exercise. Modify the method in above example to draw dashed line. void DDA Draw DashedLine(double X1, double Y1,double X2, double Ya, Graphies > Lab 18 A ENG 6 0 3
this is my code:
package aa;
import java.awt.*;
import javax.swing.*;
class GraphicsCanvas extends JPanel
{
@Override
public void paintComponent(Graphics g)
{
super.paintComponent(g);
g.setColor(Color.red);
DDA_DrawDashedLine(100,100,750,450,g) ;
}
void DDA_DrawDashedLine(double X1, double Y1,double X2, double Y2, Graphics g)
{
double diff_x = X2-X1;
double diff_y= Y2-Y1;
double steps;
if(diff_x> diff_y)
steps = Math.abs(diff_x);
else
steps = Math.abs(diff_y);
double x_increment = diff_x/steps;
double y_increment = diff_y/steps;
double pointX = X1;
double pointY = Y1;
g.drawOval((int)pointX,(int)pointY, 1, 1);
for(int i=0 ; i
{
pointX = pointX + x_increment;
pointY = pointY + y_increment;
g.drawOval((int)pointX,(int)pointY,1,1);
}
}
}
public class aa extends JFrame
{
aa ()
{
initUI();
}
void initUI()
{
add(new GraphicsCanvas());
setTitle(" Graphics Lab 1B");
setSize(1000,1000);
}
public static void main(String[] args)
{
aa obj_graphics = new aa ();
obj_graphics.setVisible(true);
}
}
----------------
and this is the question
---------------
and this is my output :
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started