home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1998 July & August
/
Pcwk78a98.iso
/
Micrsoft
/
SAMPLES
/
VJ6SAMPL.EXE
/
BindPubs
/
CaptionedEdit.java
< prev
next >
Wrap
Text File
|
1998-02-24
|
2KB
|
64 lines
/* Copyright (C) Microsoft Corporation, 1996-1998. All rights reserved.
This source code is intended only as a supplement to Microsoft
Visual J++ 6.0. See this product's on-line documentation for detailed
information regarding Microsoft code samples.
*/
import wfc.ui.*;
import wfc.core.*;
/**CaptionedEdit is an edit box with a label underneath
*/
class CaptionedEdit extends Edit{
private String caption;
private Label label = new Label();
/**default constructor sets up callbacks for label management
*/
public CaptionedEdit(){
//define a size for the label
label.setSize(60, 20);
Label label = this.label;
label.setAlignment(HorizontalAlignment.CENTER);
//set the label to move with the edit
addOnMove(new EventHandler(this.moveCaption));
//set the label's size by the edit's
addOnResize(new EventHandler(this.resizeCaption));
}
/**public void setCaption(String caption) sets the caption of the edit box
*/
public void setCaption(String caption){
//retrieve the current location of the edit
Point location = getLocation();
//place a label with the caption below it -- if there's a parent, add the label to it
label.setText(caption);
label.setLocation(location.x, location.y + getSize().y + 2);
Control parent = getParent();
if(parent!=null)
parent.add(label);
setLocation(getLocation());
}
/**public String getCaption() returns the edit's caption
*/
public String getCaption(){
return caption;
}
/**private void moveCaption(Object sender, Event event) moves the caption with the edit
*/
private void moveCaption(Object sender, Event event) {
Point location = getLocation();
label.setLocation(location.x, location.y + getSize().y + 2);
Control parent = getParent();
//if the control got a parent since the last time it was located, add the caption to the parent
if(parent!=null && !(parent.contains(label)))
parent.add(label);
}
/**private void resizeCaption(Object sender, Event event) ensures the label fits under the caption
*/
private void resizeCaption(Object sender, Event event) {
label.setSize(getSize().x, label.getSize().y);
}
}