Methods Summary |
---|
void | buildUI(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.JPanel | frameItUp(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 void | init()
//Called only when this is run as an applet.
ImageIcon image = new ImageIcon(getImage(getCodeBase(),
starFile));
buildUI(getContentPane(), image);
|
public static void | main(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 void | updateLabel(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) + ").");
|