Message Box Switch Statement

Reply

Join Date: Mar 2006
Posts: 4
Reputation: kedklok is an unknown quantity at this point 
Solved Threads: 0
kedklok kedklok is offline Offline
Newbie Poster

Message Box Switch Statement

 
0
  #1
Jul 6th, 2006
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
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 376
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Message Box Switch Statement

 
0
  #2
Jul 6th, 2006
let's see sum code please
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 4
Reputation: kedklok is an unknown quantity at this point 
Solved Threads: 0
kedklok kedklok is offline Offline
Newbie Poster

Re: Message Box Switch Statement

 
0
  #3
Jul 6th, 2006
Sent the code via private message. i basically just want the messge box to close and the login screen to remain.

thanks for replying to me.
Last edited by kedklok; Jul 6th, 2006 at 10:01 am.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 5,264
Reputation: iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold iamthwee is a splendid one to behold 
Solved Threads: 376
Featured Poster
iamthwee's Avatar
iamthwee iamthwee is offline Offline
Posting Expert

Re: Message Box Switch Statement

 
0
  #4
Jul 6th, 2006
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.
  1. public class Login
  2. {
  3. Display display = new Display ();
  4. final Shell shell = new Shell (display);
  5.  
  6. final Label welcomeLabel, label1, label2;
  7. final Button button1;
  8. final Text textField1, textField2;
  9.  
  10. public Login()
  11. {
  12.  
  13.  
  14. label1 = new Label(shell, SWT.BOLD);
  15. label1.setText("Investigator ID: ");
  16. label1.setSize(100,20); // (width, height)
  17. label1.setLocation(20,60); // (x,y) co-ordinates
  18.  
  19. textField1 = new Text(shell, SWT.BORDER | SWT.MULTI | SWT.WRAP);
  20. textField1.setSize(90,20); // (width, height)
  21. textField1.setLocation(120,60); // (x,y) co-ordinates
  22. textField1.setTextLimit(4);
  23.  
  24. textField1.addListener(SWT.KeyDown, new Listener()
  25. {
  26. public void handleEvent(Event event){}
  27. });
  28.  
  29. textField1.addListener(SWT.Traverse, new Listener()
  30. {
  31. public void handleEvent(Event event)
  32. {
  33. event.doit = true;
  34. }
  35. });
  36.  
  37. button1 = new Button(shell, SWT.BUTTON1);
  38. button1.setSize(90,30); // (width, height)
  39. button1.setLocation(220,75); // (x,y) co-ordinates
  40. button1.setText("Login");
  41. button1.addSelectionListener(login);
  42.  
  43. shell.setSize(340, 340); // (width, height)
  44. shell.setImage(img1);
  45. shell.setText("Login");
  46. shell.open ();
  47.  
  48. shell.addListener(SWT.Close, new Listener()
  49. {
  50. public void handleEvent(Event event)
  51. {
  52.  
  53. int style = SWT.APPLICATION_MODAL | SWT.YES | SWT.NO;
  54. MessageBox messageBox = new MessageBox(shell, style);
  55. messageBox.setText("Closing");
  56. messageBox.setMessage("Do You Wish to Close the Application?");
  57. //event.doit = messageBox.open() == SWT.YES;
  58.  
  59. int response = messageBox.open();
  60.  
  61. switch (response)
  62. {
  63. case SWT.YES:
  64. System.exit(0);
  65. case SWT.NO:
  66. // tried to just go back to login screen
  67.  
  68.  
  69. } // end switch
  70. } // end handle event
  71. }); // end addListener
  72.  
  73. while (!shell.isDisposed ())
  74. {
  75. if (!display.readAndDispatch ()) display.sleep();
  76. }
  77. display.dispose ();
  78. new Shell(); // call another class that opens another shell
  79.  
  80.  
  81. } // end constructor
  82.  
  83. SelectionListener login = new SelectionListener()
  84. {
  85. public void widgetSelected(SelectionEvent arg0)
  86. {
  87. String response1 = textField1.getText();
  88. String response2 = textField2.getText();
  89. if (!response1.equals("") && !response2.equals(""))
  90. {
  91. new Database(response1, response2);
  92. shell.close();
  93. }
  94.  
  95. else
  96. {
  97. MessageBox messageBox = new MessageBox(shell, SWT.ICON_WARNING);
  98. messageBox.setText("Error");
  99. messageBox.setMessage("You Must Enter Both Investigator ID & Password");
  100.  
  101. int buttonID = messageBox.open();
  102. }
  103. }
  104.  
  105. public void widgetDefaultSelected(SelectionEvent arg0)
  106. {}
  107. }; // end SelectionListener() method
*Voted best profile in the world*
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC