home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 1998 October
/
PCWorld_1998-10_cd.bin
/
software
/
prehled
/
inprise
/
JRUNTIME.Z
/
OkCancelBean.java
< prev
next >
Wrap
Text File
|
1998-05-08
|
3KB
|
115 lines
// This snippet creates a bean with ok, cancel, and help buttons
// The listener responds to a single action event and checks the event
// object to determine which button was pressed.
// Additional behavior for each button can be added if desired,
// for example: the help button can launch help without firing an action
// event
//
// <File=OkCancelBean.java>
//Title:
//Version:
//Copyright:
//Author:
//Company:
//Description:
//<PACKAGE>
import java.awt.*;
import java.awt.event.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
import borland.jbcl.view.*;
import borland.jbcl.util.BlackBox;
public class OkCancelBean extends BeanPanel implements BlackBox{
// Use these constants in the event listener.
public final static String OK_EVENT = "OkEvent";
public final static String CANCEL_EVENT = "CancelEvent";
public final static String HELP_EVENT = "HelpEvent";
private BorderLayout borderLayout1 = new BorderLayout();
private Panel panel1 = new Panel();
private FlowLayout flowLayout1 = new FlowLayout();
private Button ok = new Button();
private Button cancel = new Button();
private Button help = new Button();
public OkCancelBean() {
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
private void jbInit() throws Exception{
ok.setLabel(" OK ");
ok.addActionListener(new OkCancelBean_ok_actionAdapter(this));
cancel.setLabel("Cancel");
cancel.addActionListener(new OkCancelBean_cancel_actionAdapter(this));
help.setLabel(" Help ");
help.addActionListener(new OkCancelBean_help_actionAdapter(this));
panel1.setLayout(flowLayout1);
this.setLayout(borderLayout1);
this.add(panel1, BorderLayout.CENTER);
panel1.add(ok, null);
panel1.add(cancel, null);
panel1.add(help, null);
}
// The action listener for this bean should check the ActionEvent
// to determine which button was pressed.
// The Help button could be handled entirely inside this bean
// if desired.
void ok_actionPerformed(ActionEvent e) {
//Args: event source,event ID, event command
processActionEvent(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,OK_EVENT));
}
void cancel_actionPerformed(ActionEvent e) {
processActionEvent(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,CANCEL_EVENT));
}
void help_actionPerformed(ActionEvent e) {
processActionEvent(new ActionEvent(this,ActionEvent.ACTION_PERFORMED,HELP_EVENT));
}
}
class OkCancelBean_ok_actionAdapter implements java.awt.event.ActionListener {
OkCancelBean adaptee;
OkCancelBean_ok_actionAdapter(OkCancelBean adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.ok_actionPerformed(e);
}
}
class OkCancelBean_cancel_actionAdapter implements java.awt.event.ActionListener {
OkCancelBean adaptee;
OkCancelBean_cancel_actionAdapter(OkCancelBean adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.cancel_actionPerformed(e);
}
}
class OkCancelBean_help_actionAdapter implements java.awt.event.ActionListener {
OkCancelBean adaptee;
OkCancelBean_help_actionAdapter(OkCancelBean adaptee) {
this.adaptee = adaptee;
}
public void actionPerformed(ActionEvent e) {
adaptee.help_actionPerformed(e);
}
}