-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBoxy2.java
More file actions
59 lines (51 loc) · 1.86 KB
/
Copy pathBoxy2.java
File metadata and controls
59 lines (51 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment_10528808;
/**
*
* @author Mawutor
*/
import java.awt.*;
import javax.swing.JFrame;
/************************************************************************************
** B O X Y 2 - use function - all boxes same size **
***********************************************************************************/
class Boxy2 extends Canvas
{
public void paint( Graphics window )
{
// color x y
drawBox( window, Color.RED, 200, 300 );
drawBox( window, Color.GRAY, 100, 150 );
drawBox( window, Color.GREEN, 400, 400 );
drawBox( window, Color.CYAN, 50, 300 );
drawBox( window, Color.YELLOW, 300, 300 );
drawBox( window, Color.BLACK, 200, 300 );
drawBox( window, Color.ORANGE, 200, 400 );
drawBox( window, Color.BLUE, 150, 300 );
// draw ten more boxes -- different colors, different places
}
public void drawBox( Graphics window, Color c, int x, int y )
{
// already finished; do not modify
//this code draws a 100x100 box in color c at (x,y)
window.setColor(c);
window.fillRect(x,y,100,100);
// this code "erases" the center of the box by painting over it in white
window.setColor(Color.WHITE);
window.fillRect(x+10,y+10,80,80);
}
public static void main( String[] args )
{
Canvas canvas = new Boxy2();
JFrame win = new JFrame("Boxy2 - use function - all boxes same size");
win.setSize(800,600);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvas.setBackground(Color.CYAN);
win.add( canvas );
win.setVisible(true);
}
}