| | |
Message Box Switch Statement
![]() |
•
•
Join Date: Mar 2006
Posts: 4
Reputation:
Solved Threads: 0
Hi,
i am using swt with java and am having a problem with a message box. when i run my program a login shell appears. when a user clicks the close button (X) in top right hand corner of the login shell they are asked if they really want to exit. when they click yes the application exits which is what i want to happen, but when they click no i just want the login shell to remain, however it keeps closing and open the shell that should open upon successful login.
can anyone please help me.
thanks in advanced,
k
i am using swt with java and am having a problem with a message box. when i run my program a login shell appears. when a user clicks the close button (X) in top right hand corner of the login shell they are asked if they really want to exit. when they click yes the application exits which is what i want to happen, but when they click no i just want the login shell to remain, however it keeps closing and open the shell that should open upon successful login.
can anyone please help me.
thanks in advanced,
k
I don't have the swt (standard widget toolkit) which normally comes with the eclipse ide. So I cannot help here. I've posted the code so others may.
It seems like you may be missing a few braces as well.
It seems like you may be missing a few braces as well.
Java Syntax (Toggle Plain Text)
public class Login { Display display = new Display (); final Shell shell = new Shell (display); final Label welcomeLabel, label1, label2; final Button button1; final Text textField1, textField2; public Login() { label1 = new Label(shell, SWT.BOLD); label1.setText("Investigator ID: "); label1.setSize(100,20); // (width, height) label1.setLocation(20,60); // (x,y) co-ordinates textField1 = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP); textField1.setSize(90,20); // (width, height) textField1.setLocation(120,60); // (x,y) co-ordinates textField1.setTextLimit(4); textField1.addListener(SWT.KeyDown, new Listener() { public void handleEvent(Event event){} }); textField1.addListener(SWT.Traverse, new Listener() { public void handleEvent(Event event) { event.doit = true; } }); button1 = new Button(shell, SWT.BUTTON1); button1.setSize(90,30); // (width, height) button1.setLocation(220,75); // (x,y) co-ordinates button1.setText("Login"); button1.addSelectionListener(login); shell.setSize(340, 340); // (width, height) shell.setImage(img1); shell.setText("Login"); shell.open (); shell.addListener(SWT.Close, new Listener() { public void handleEvent(Event event) { int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO; MessageBox messageBox = new MessageBox(shell, style); messageBox.setText("Closing"); messageBox.setMessage("Do You Wish to Close the Application?"); //event.doit = messageBox.open() == SWT.YES; int response = messageBox.open(); switch (response) { case SWT.YES: System.exit(0); case SWT.NO: // tried to just go back to login screen } // end switch } // end handle event }); // end addListener while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep(); } display.dispose (); new Shell(); // call another class that opens another shell } // end constructor SelectionListener login = new SelectionListener() { public void widgetSelected(SelectionEvent arg0) { String response1 = textField1.getText(); String response2 = textField2.getText(); if (!response1.equals("") && !response2.equals("")) { new Database(response1, response2); shell.close(); } else { MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING); messageBox.setText("Error"); messageBox.setMessage("You Must Enter Both Investigator ID & Password"); int buttonID = messageBox.open(); } } public void widgetDefaultSelected(SelectionEvent arg0) {} }; // end SelectionListener() method
*Voted best profile in the world*
![]() |
Similar Threads
- Switch Statement (Java)
- Problems with switch statement (C++)
- repeating the whole program after pressing Yes button in the confirmation message box (Java)
Other Threads in the Java Forum
- Previous Thread: Please hepl me !
- Next Thread: Wat is method compareTo?
| Thread Tools | Search this Thread |
2dgraphics @param account affinetransform android api apple applet application arc arguments array automation banking binary binarytree bluetooth chatprogramusingobjects class client code color compare component count database derby design detection eclipse eclipsedevelopment encryption error fractal game givemetehcodez graphics gridlayout gui guitesting helpwithhomework homework html if_statement image integer j2me java java.xls javadesktopapplications javaprojects jlabel jni jpanel jtextfield julia keytool keyword linux list macintosh method methods midlethttpconnection mobile monitoring netbeans nullpointerexception object open-source pong problem producer program projectideas property reference replaysolutions ria rim scanner server set size sms sourcelabs splash sql sqlite swing terminal testautomation threads transforms tree ui unicode validation web windows






