Question: The following code attempts to draw a black rectangle from (10, 20) to (50, 40) with a line across its diagonal: DrawingPanel panel = new

The following code attempts to draw a black rectangle from (10, 20) to (50, 40) with a line across its diagonal:

DrawingPanel panel = new DrawingPanel(200, 100);

Graphics g = panel.getGraphics();

g.drawRect(10, 20, 50, 40);

g.drawLine(10, 20, 50, 40);

However, the graphical output looks like Figure 3G.20 instead. What must be changed for it to look as intended?

Drawing Panel

Drawing Panel

Step by Step Solution

3.45 Rating (164 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The problem is that the parameters for the drawRect and drawLine methods have different meanings ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!