[3959] in java-interest
Re: menu item callbacks
daemon@ATHENA.MIT.EDU (Gary Aitken)
Tue Dec 5 18:12:52 1995
Date: Tue, 5 Dec 1995 10:39:36 -0700
From: garya@village.org (Gary Aitken)
To: "R. Mark Volkmann"<m224873@svmstr01.mdc.com>,
java-interest@java.Eng.Sun.COM
>Could someone please send me a couple of lines of code or direct me to the
>documentation that describes how to specify the function that should be
>invoked when a particular menu item is picked (a callback function in Motif).
You're probably bumping against the lack of function pointers in java.
Since you can't specify a pointer to a function / member function, the
easiest way to do what you want requires a different subclass of Button
for each callback. The event handler will get an ACTION_EVENT when the
button is clicked.
import java.awt.*;
public class ButtonTest {
public static void main( String argv[] ) {
Frame main;
MyButton button;
main = new Frame( "Button Event Test" );
main.show();
main.resize( 300, 200 );
main.setLayout( new FlowLayout() );
button = new MyButton( );
main.add(button);
button.show();
main.layout();
};
}
class MyButton extends Button {
public MyButton() {
super( "MyButton" );
}
public boolean handleEvent( // Attempt to process an event
Event evt ) { // An event to process
// Local Variables
boolean evt_handled; // true if the event has been handled
evt_handled = false;
switch (evt.id) {
case(Event.ACTION_EVENT):
System.out.println( "Button Activate" );
break;
default:
evt_handled = super.handleEvent( evt );
break;
}
return( evt_handled );
}
}
Gary Aitken garya@village.org
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com