Java Reference
In-Depth Information
g.fillRect(10, 10, 50, 50);
g.setColor(Color.WHITE);
g.fillOval(10, 10, 50, 50);
3.
The problem is that the parameters for the
drawRect
and
drawLine
methods have
different meanings. In
drawRect
, the parameters are
(x, y, width, height)
;
in
drawLine
, they are
(x1, y1, x2, y2)
. To fix the problem, the third and
fourth parameters passed to
drawRect
should be changed to
40
and
20
so that the
rectangle's bottom-left corner will be at (50, 40). The following code fixes the
problem:
DrawingPanel panel = new DrawingPanel(200, 100);
Graphics g = panel.getGraphics();
g.drawRect(10, 20, 40, 20);
g.drawLine(10, 20, 50, 40);
4.
The
Draw7
program draws a series of progressively smaller black circles, each
with its right and bottom edges touching the right and bottom corners of the win-
dow. Its output looks like this:
Chapter 4
1.
(a)
z % 2 != 0
(b)
z <= Math.sqrt(y)
(c)
y > 0
(d)
x % 2 != y % 2
(e)
y % z == 0
(f)
z != 0
(g)
Math.abs(y) > Math.abs(z)
(h)
(x >= 0) == (z < 0)
(i)
y % 10 == y
(j)
z >= 0
(k)
x % 2 == 0
(l)
Math.abs(x - y) < Math.abs(z - y)
Search WWH ::
Custom Search