FileDocCategorySizeDatePackage
SelectionDemo.javaAPI DocExample6691Tue Dec 12 18:59:06 GMT 2000None

SelectionDemo

public class SelectionDemo extends JApplet

Fields Summary
JLabel
label
static String
starFile
Constructors Summary
Methods Summary
voidbuildUI(java.awt.Container container, javax.swing.ImageIcon image)

        container.setLayout(new BoxLayout(container,
                                          BoxLayout.Y_AXIS));

        JPanel framedArea = frameItUp(new SelectionArea(image, this));
        container.add(framedArea);

        label = new JLabel("Drag within the framed area.");
        container.add(label);

        //Align the left edges of the components.
        framedArea.setAlignmentX(LEFT_ALIGNMENT);
        label.setAlignmentX(LEFT_ALIGNMENT); //redundant
    
javax.swing.JPanelframeItUp(java.awt.Component insides)

        Border raisedBevel, loweredBevel, compound;
        raisedBevel = BorderFactory.createRaisedBevelBorder();
        loweredBevel = BorderFactory.createLoweredBevelBorder();
        compound = BorderFactory.createCompoundBorder
                        (raisedBevel, loweredBevel);

        JPanel framedArea = new JPanel();
        framedArea.setBorder(compound);
        framedArea.setLayout(new GridLayout(1,0));
        framedArea.add(insides);

        return framedArea;
    
public voidinit()


    //Called only when this is run as an applet.
       
        ImageIcon image = new ImageIcon(getImage(getCodeBase(),
                                                 starFile));
        buildUI(getContentPane(), image);
    
public static voidmain(java.lang.String[] args)

        JFrame f = new JFrame("SelectionDemo");
        f.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        SelectionDemo controller = new SelectionDemo();
        controller.buildUI(f.getContentPane(),
                           new ImageIcon(starFile));
        f.pack();
        f.setVisible(true);
    
public voidupdateLabel(java.awt.Rectangle rect)

        int width = rect.width;
        int height = rect.height;

        //Make the coordinates look OK if a dimension is 0.
        if (width == 0) {
            width = 1;
        }
        if (height == 0) {
            height = 1;
        }

        label.setText("Rectangle goes from ("
                      + rect.x + ", " + rect.y + ") to ("
                      + (rect.x + width - 1) + ", "
                      + (rect.y + height - 1) + ").");