blob: be572397543e971ea40610004e1102f7bc478e9c (
plain)
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
60
61
62
63
64
65
66
67
68
69
|
/* Listing2902.java */
import java.awt.*;
import java.awt.event.*;
class ComponentRepaintAdapter
extends ComponentAdapter
{
public void componentMoved(ComponentEvent event)
{
event.getComponent().repaint();
}
public void componentResized(ComponentEvent event)
{
event.getComponent().repaint();
}
}
class BirdsEyeFrame
extends Frame
{
public BirdsEyeFrame()
{
super("BirdsEyeFrame");
addWindowListener(new WindowClosingAdapter(true));
addComponentListener(new ComponentRepaintAdapter());
setBackground(Color.lightGray);
}
public void paint(Graphics g)
{
Dimension screensize = getToolkit().getScreenSize();
Dimension framesize = getSize();
double qx = framesize.width / (double)screensize.width;
double qy = framesize.height / (double)screensize.height;
g.setColor(Color.white);
g.fillRect(
(int)(qx * getLocation().x),
(int)(qy * getLocation().y),
(int)(qx * framesize.width),
(int)(qy * framesize.height)
);
g.setColor(Color.darkGray);
g.fillRect(
(int)(qx * getLocation().x),
(int)(qy * getLocation().y),
(int)(qx * framesize.width),
(int)(qy * getInsets().top)
);
g.drawRect(
(int)(qx * getLocation().x),
(int)(qy * getLocation().y),
(int)(qx * framesize.width),
(int)(qy * framesize.height)
);
}
}
public class Listing2902
{
public static void main(String[] args)
{
BirdsEyeFrame wnd = new BirdsEyeFrame();
wnd.setSize(300,200);
wnd.setLocation(200,100);
wnd.setVisible(true);
}
}
|