Hai all,
i use swt framework. i create to form using swt in eclipse. in my first form i have a button. when the button is clicked, i want the second form is show and the first form is disposed. can you help me please??.
First Class
public class Swtapp {
private Shell shell;
SecondForm form;
public Swtapp(Display display) {
shell = new Shell(display);
shell.setText("Button");
initUI();
shell.setSize(250, 200);
shell.setLocation(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
public void initUI() {
Button quit = new Button(shell, SWT.PUSH);
quit.setText("Quit");
quit.setBounds(50, 50, 80, 30);
quit.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
form.display.sleep();
shell.getDisplay().dispose();
//System.exit(0);
}
});
}
public static void main(String[] args) {
Display display = new Display();
new Swtapp(display);
display.dispose();
}
}
second class
public class SecondForm {
public Shell shell;
public static Display display;
public SecondForm()
{
}
public SecondForm(Display display) {
shell = new Shell(display);
shell.setText("Button");
shell.setSize(250, 200);
shell.setLocation(300, 300);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch()) {
display.sleep();
}
}
}
public static void main(String[] args)
{
display = new Display();
new SecondForm(display);
}
}