| [Prior]
[Top] [Next]
4.
An graph application with an image in the background
The
mechanism while having an image in your background
In some cases, maybe you want to load an image for background reference
when your application startup, you can easily accomplish it wih
JFLayer
right now!
The mechanism is just use JFLayer
as a multi-layer solution, to load an image in the background layer,
and draw shapes on the other layers. So easy.
Sample
codes of this issue.
................
//Action: create a
draw panel
//Desc: A DrawPane object packaged a vertical ruler, a horizontal
ruler and a drawing canvas
DrawPane panel =new DrawPane();
//set drawing
Sample2.setDrawing(panel);
//Action: get the draw
canvas which is inside of a DrawPane object.
//Desc: A DrawCanvas object is used to draw all of the shapes
DrawCanvas canvas =panel.getDrawCanvas();
//Action: get
the page object which is insde of a DrawCanvas object.
//Desc: A JFPage object is used to store all of the shapes
JFPage page =canvas.getDrawPage();
//set a background
image
Sample2.setBackground(canvas,page);
................
................
/**
* Set a background image in layer1, then
* insert a new layer(layer2) at layer index0 for drawing
*/
public static void setBackground(DrawCanvas canvas,JFPage
page){
//-------set
background image in layer1------------
JFImage image =createImage1(canvas); //method
1
//JFImage image =createImage2(canvas); //method
2
//add
this image to current layer(layer1 and index=0)
page.getCurrentLayer().getShapeList().add(image);
//insert
a new layer at index0, the set current layer to this layer
JFLayer layer =new JFLayer();
page.insertLayer(layer,0);
//now, you can
start your drawing on this new layer,
// and with an image in your background layer.
}
Screenshot
of this sample.
Ok, please notice the setBackground method above, all the preparations
have been done in this method. And now you can take a look its screenshot
here.

To
get full source code of this sample.
You can download the full sample
source code package here. Then open the file at sample2/Sample2.java
for detail informations.
[Prior]
[Top] [Next]
|