Getting started with a simple circle

01:	public class TutorialExample1 extends Applet {
02:	
03:		public void init () {
04:			setBackground(Color.lightGray);
05:
06:			FigureStyle style = new FigureStyle();
07:			style.foreground = Color.yellow;
08:			style.background = Color.blue;
09:			style.brushSize = 1;
10:
11:			Glyph horizontalBox = LayoutKit.hbox();
12:
13:			horizontalBox.append(
14:			    LayoutKit.margin(
15:			            FigureKit.circle(FigureMode.Fill, style, 0, 0, 40),
16:			            16
17:			    )
18:			);
19:	
20:			SgraphicsAdapter adapter = new SgraphicsAdapter(horizontalBox);
21:
22:			setLayout(new BorderLayout());
23:			add("Center", adapter);
24:		}
25:	}

There are three parts to every sgraphics applet:

  1. Creation of a glyph tree (lines 6-18).
  2. Creation of a SgraphicsAdapter (line 20).
  3. AWT setup (lines 22-23).

The LayoutKit is used to make a horizontal box (line 11). A horizontal box (hbox) is a container that tiles glyphs along the horizontal axis by packing them from left to right, and aligning them vertically. The hbox contains a margin (line 14) of size 16 that creates 16 pixels of space around the circle that is contained in the margin. The circle (line 14), like the hbox, is obtained from a kit: FigureKit.

All figures are configured with a FigureStyle object. FigureStyle sets the color and brushsize of a figure. In this example (lines 6-9) the foreground is set to yellow, the background is set to blue, and the brush size is set to 1; however, in this case the brush size does not matter because the figure mode is Fill, which draws a solid circle.

The hbox is placed in the viewer (line 20) and the viewer is placed in the applet (line 23).

Notice the blue square around the circle. The blue area is the background and the yellow circle is the foreground.


Beginning of example
Next

For comments or questions contact Mike Jones (Mike.Jones@mass.com)