Answered step by step
Verified Expert Solution
Link Copied!

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 )
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
image text in transcribed
---------------
and this is my output :
image text in transcribed
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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

Have to Do: Monitor the plan.

Answered: 1 week ago

Question

Have to Do: Embed the mission in the work.

Answered: 1 week ago