Java Reference
In-Depth Information
Example 14−3: YesNoPanel.java (continued)
{
// Create the components for this panel
setLayout(new BorderLayout(15, 15));
// Put the message label in the middle of the window.
message = new MultiLineLabel(messageText, 20, 20, alignment);
add(message, BorderLayout.CENTER);
// Create a panel for the Panel buttons and put it at the bottom
// of the Panel. Specify a FlowLayout layout manager for it.
Panel buttonbox = new Panel();
buttonbox.setLayout(new FlowLayout(FlowLayout.CENTER, 25, 15));
add(buttonbox, BorderLayout.SOUTH);
// Create each specified button, specifying the action listener
// and action command for each, and adding them to the buttonbox
yes = new Button();
// Create buttons
no = new Button();
cancel = new Button();
// Add the buttons to the button box
buttonbox.add(yes);
buttonbox.add(no);
buttonbox.add(cancel);
// Register listeners for each button
yes.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireEvent(new AnswerEvent(YesNoPanel.this,
AnswerEvent.YES));
}
});
no.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireEvent(new AnswerEvent(YesNoPanel.this,
AnswerEvent.NO));
}
});
cancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
fireEvent(new AnswerEvent(YesNoPanel.this,
AnswerEvent.CANCEL));
}
});
// Now call property setter methods to set the message and button
// components to contain the right text
setMessageText(messageText);
setAlignment(alignment);
setYesLabel(yesLabel);
setNoLabel(noLabel);
setCancelLabel(cancelLabel);
}
// Methods to query all of the bean properties.
public String getMessageText() { return messageText; }
public Alignment getAlignment() { return alignment; }
public String getYesLabel() { return yesLabel; }
Search WWH ::




Custom Search