Java Reference
In-Depth Information
15.
DirectionPanel dirPanel =
new
DirectionPanel(posModel,
this
);
16.
this
.getContentPane().add(dirPanel,BorderLayout.SOUTH);
17.
}
18.
19.
}
File:
its/ResizeJumpDisplay/ResizeJumpPanel.java
1.
package
its.ResizeJumpDisplay;
2.
3.
import
java.awt.Color;
4.
import
java.awt.Graphics;
5.
import
javax.swing.JPanel;
6.
7.
public class
ResizeJumpPanel
extends
JPanel{
8.
9.
10.
private
PositionModel posModel;
11.
12.
public
ResizeJumpPanel(PositionModel pm){
13.
posModel = pm;
14.
this
.setBackground(Color.yellow);
15.
}
16.
17.
public void
paintComponent(Graphics g)
18.
{
19.
super
.paintComponent(g);
20.
//
get the current dimensions of the panel in pixels
21.
int
currentWidth =
this
.getWidth();
22.
int
currentHeight =
this
.getHeight();
23.
24.
//
compute the current size of a step in pixels
25.
int
hStepInPixels = currentWidth/posModel.getNoOfSteps();
26.
int
vStepInPixels = currentHeight/posModel.getNoOfSteps();
27.
28.
//
compute the pixel positions of the
29.
//
upper left corner of the black rectangle
30.
//
and its width and height
.
31.
int
upperLeftX = posModel.getXInSteps() * hStepInPixels;
32.
int
upperLeftY = posModel.getYInSteps() * vStepInPixels;
33.
int
blackWidth = hStepInPixels * posModel.getBlackSizeInSteps();
34.
int
blackHeight= vStepInPixels * posModel.getBlackSizeInSteps();
35.
36.
//
set colour to black
37.
g.setColor(Color.black);
38.
Search WWH ::
Custom Search