|
Re: Widget is disposed (newb edition) [message #1053700 is a reply to message #1040510] |
Tue, 07 May 2013 09:53 |
Vijay Raj Messages: 608 Registered: July 2009 |
Senior Member |
|
|
you have create the dialog again when you click on the checkme button.
the dialog is closed(disposed,hence all children also disposed) every time you click on ok.
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.widgets.Label;
public class PalindromeCheck {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Display display = new Display();
final Shell shell = new Shell(display);
shell.setText("Palindrome check");
shell.setSize(255,150);
shell.setMinimumSize(255,150);
shell.open();
final Button checkme = new Button(shell,SWT.PUSH);
checkme.setText("Check string");
checkme.setBounds(55,50,140,60);
final Text checkit = new Text(shell,SWT.SHADOW_IN);
checkit.setBounds(10,10,230,30);
Listener checkmelistener = new Listener() {
public void handleEvent(Event event) {
boolean answer=true;
String check = checkit.getText();
for (int j=0; j <= ((check.length() - 1) - j); j++) {
String a = Character.toString(check.charAt(j));
String b = Character.toString(check.charAt((check.length() - 1) - j));
if (a.compareToIgnoreCase(b) != 0) {
answer=false; break;
}
}
final Shell dialog = new Shell(shell,SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
dialog.setSize(250,100); dialog.setMinimumSize(250,100);
final Label result = new Label(dialog,SWT.NONE);
result.setBounds(10,10,230,30);
final Button ok = new Button(dialog,SWT.PUSH);
ok.setBounds(105,35,35,30);
ok.setText("OK");
Listener dialoglistener = new Listener() {
public void handleEvent(Event event) {
dialog.close();
}
};
ok.addListener(SWT.Selection,dialoglistener);
dialog.open();
result.setText((answer) ? "The string is a palindrome indeed!" : "The string is not a palindrome!");
}
};
checkme.addListener(SWT.Selection,checkmelistener);
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) display.sleep();
}
display.dispose();
}
}
---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
|
|
|
Powered by
FUDForum. Page generated in 0.02778 seconds