FileDocCategorySizeDatePackage
StrokeAndFill.javaAPI DocExample8046Tue Dec 12 19:00:00 GMT 2000None

StrokeAndFill

public class StrokeAndFill extends JApplet implements ItemListener

Fields Summary
JLabel
primLabel
JLabel
lineLabel
JLabel
paintLabel
JLabel
strokeLabel
ShapePanel
display
static JComboBox
primitive
static JComboBox
line
static JComboBox
paint
static JComboBox
stroke
int
index
public static boolean
no2D
Constructors Summary
Methods Summary
public voidinit()


       
        GridBagLayout layOut = new GridBagLayout();
        getContentPane().setLayout(layOut);
        GridBagConstraints c = new GridBagConstraints();

        c.weightx = 1.0;
        c.fill = GridBagConstraints.BOTH;
        primLabel = new JLabel();
        primLabel.setText("Primitive");
        Font newFont = getFont().deriveFont(1);
        primLabel.setFont(newFont);
        primLabel.setHorizontalAlignment(JLabel.CENTER);
        layOut.setConstraints(primLabel, c);
        getContentPane().add(primLabel);

        lineLabel = new JLabel();
        lineLabel.setText("Lines");
        lineLabel.setFont(newFont);
        lineLabel.setHorizontalAlignment(JLabel.CENTER);
        layOut.setConstraints(lineLabel, c);
        getContentPane().add(lineLabel);

        c.gridwidth = GridBagConstraints.RELATIVE;
        paintLabel = new JLabel();
        paintLabel.setText("Paints");
        paintLabel.setFont(newFont);
        paintLabel.setHorizontalAlignment(JLabel.CENTER);
        layOut.setConstraints(paintLabel, c);
        getContentPane().add(paintLabel);

        c.gridwidth = GridBagConstraints.REMAINDER;
        strokeLabel = new JLabel();
        strokeLabel.setText("Rendering");
        strokeLabel.setFont(newFont);
        strokeLabel.setHorizontalAlignment(JLabel.CENTER);
        layOut.setConstraints(strokeLabel, c);
        getContentPane().add(strokeLabel);

        GridBagConstraints ls = new GridBagConstraints();
        ls.weightx = 1.0;
        ls.fill = GridBagConstraints.BOTH;
        primitive = new JComboBox( new Object []{
                                   "rectangle",
                                   "ellipse",
                                   "text"});
        primitive.addItemListener(this);
        newFont = newFont.deriveFont(0, 14.0f);
        primitive.setFont(newFont);
        layOut.setConstraints(primitive, ls);
        getContentPane().add(primitive);

        line = new JComboBox( new Object []{
                              "thin",
                              "thick",
                              "dashed"});
        line.addItemListener(this);
        line.setFont(newFont);
        layOut.setConstraints(line, ls);
        getContentPane().add(line);

        ls.gridwidth = GridBagConstraints.RELATIVE;
        paint = new JComboBox( new Object[]{
                               "solid",
                               "gradient",
                               "polka"});
        paint.addItemListener(this);
        paint.setFont(newFont);
        layOut.setConstraints(paint, ls);
        getContentPane().add(paint);

        ls.gridwidth = GridBagConstraints.REMAINDER;
        stroke = new JComboBox( new Object[]{
                                "Stroke",
                                "Fill",
                                "Stroke & Fill"});
        stroke.addItemListener(this);
        stroke.setFont(newFont);
        layOut.setConstraints(stroke, ls);
        getContentPane().add(stroke);

        GridBagConstraints sC = new GridBagConstraints();
        sC.fill = GridBagConstraints.BOTH;
        sC.weightx = 1.0;
        sC.weighty = 1.0;
        sC.gridwidth = GridBagConstraints.REMAINDER;
        display = new ShapePanel();
        layOut.setConstraints(display, sC);
        display.setBackground(Color.white);
        getContentPane().add(display);

        validate();

    
public voiditemStateChanged(java.awt.event.ItemEvent e)

        display.renderShape();
    
public static voidmain(java.lang.String[] argv)

        if ( argv.length > 0 && argv[0].equals( "-no2d" ) ) {
	    StrokeAndFill.no2D = true;
	}
	      
        JFrame frame = new JFrame( "StrokeAndFill" );
	frame.addWindowListener( new WindowAdapter(){
	    public void windowClosing( WindowEvent e ){
	        System.exit( 0 );
	    }
	});

	JApplet applet = new StrokeAndFill();
	frame.getContentPane().add( BorderLayout.CENTER, applet );

	applet.init();

	frame.setSize( 450, 250 );
	frame.show();