• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Listeners in SWT

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

i was wondering if someone can help me. i'm new to swt, and i am trying to work with two listeners. I have a login screen that a user enters their username and password and then clicks login button. when they click login their is a SelectionListener that will envoke a login method. i also have a listener on the shell that if the user clicks the close (X) button then the entire application just exits. the problem i'm having is that when the user clicks login it is actually exiting the application when it shouldn't. i have added some code at the end. Any help would be greatly appreciated.

Thanks in advanced

k

 
Marshal
Posts: 80612
467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most of these classes are unfamiliar to me, but I think you have added a Listener to your Shell with the possibility of calling System.exit(0). That will of course close your entire app.
Was that what you intended?
 
K Terr
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Thanks for replying. yeah if they hit the X button in the top right hand corner then i want the application to close. if the hit the login button i want the next screen to appear. i think its because i put a listener on the shell but i dont know a way around this.

thanks again

k
 
Campbell Ritchie
Marshal
Posts: 80612
467
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The more usual way to close the app on clicking the "X" at the top right is to set the properties of the enclosing JFrame. I presume you are familiar with the three things you have to do when setting up a JFrame?There are several alternatives for setBounds, eg setSize (I don't know about setPreferredSize).

The default close operation for a JFrame is "HIDE_ON_CLOSE," so you usually change it to EXIT_ON_CLOSE. That of course obviates any need for a closing listener, unless you have a button or menu item marked "Close," or "Exit."

And try adding all your Listeners to the buttons; if you add the Listeners to other components you end up with a somethingOrOtherPerformed(SomeEventOrOther e){} method with a long list of if and else if blocks in.

I have my own ideas, and fulminate regularly about ActionListeners on these boards, for example here. Add a Listener to each of your buttons; if the Listener has lots to do, just put a method call in its actionPerformed() method which deals with its action.
 
reply
    Bookmark Topic Watch Topic
  • New Topic