Answered step by step
Verified Expert Solution
Question
1 Approved Answer
public class DashLine { public static void main ( String [ ] args ) { new FrDashLine ( ) ; } } class FrDashLine extends
public class DashLine
public static void mainString argsnew FrDashLine;
class FrDashLine extends Frame
CvDashLine cv new CvDashLine;
FrDashLine
superDashed lines";
addWindowListener
new WindowAdapter
public void windowClosingWindowEvent eSystemexit;
;
setSize;
addCenter cv;
setCursorCursorgetPredefinedCursorCursorCROSSHAIRCURSOR;
show;
class CvDashLine extends Canvas
int xA yA xB yB;
int np ;
CvDashLine
addMouseListener
new MouseAdapter
public void mousePressedMouseEvent evt
int X evt.getX Y evt.getY;
if np np ;
np;
if np xA X; yA Y; else xB X; yB Y;
repaint;
;
public void paintGraphics g
if np return;
gdrawRectxA yA xB xA yB yA;
int xP xA xB yP yA yB
xQ xA xB yQ yA yB;
Lines.dashedLineg xP yP xQ yP;
Lines.dashedLineg xQ yP xQ yQ;
Lines.dashedLineg xQ yQ xP yQ;
Lines.dashedLineg xP yQ xP yP;
Lines.dashedLineg xA yA xP yP;
Lines.dashedLineg xB yA xQ yP;
Lines.dashedLineg xB yB xQ yQ;
Lines.dashedLineg xA yB xP yQ;
class Lines
static void dashedLineGraphics g int xA int yA int xB int yB
int dashLength
float u xB xA u yB yA
L floatMathsqrtu u u u;
int n Math.roundLdashLength ;
float h u n h u n ;
for int i; i
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