-
Notifications
You must be signed in to change notification settings - Fork 5
Sample 005
Michael Karneim edited this page May 9, 2018
·
1 revision
package wiki.snippets;
import java.awt.FlowLayout;
import javax.swing.JFrame;
import org.beanfabrics.model.ExecutionMethod;
import org.beanfabrics.model.OperationPM;
import org.beanfabrics.swing.BnButton;
/**
* Sample for using a BnButton
*/
public class Sample005 {
public static void main(String[] args) {
// create a button
BnButton btn = new BnButton();
btn.setText("Please click me!");
// the BnButton is a View on an IOperationPM object.
// let's create a model
OperationPM op = new OperationPM();
// define what to do when the operation is invoked
op.addExecutionMethod( new ExecutionMethod() {
public void execute() throws Throwable {
System.out.println("You clicked me!");
}
});
// bind the button to the model directly
btn.setPresentationModel(op);
// show the button inside a frame
JFrame frame = new JFrame("Using BnButton");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout( new FlowLayout());
frame.add(btn);
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}