Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Buttons events dispatched twice
Hi!

Into my main class I Create JDialogs, and I use JDialog.DISPOSE_ON_CLOSE as
defaultCloseOperation and setVisible(true) in order to show it. When I run
my application for first time, and clicking on menu item I create a
JDialog, so, I can use Toolbar buttons with no problems, actionPerformed is
executed normally, just once, everything works OK. I close my Dialog and re-
entering for second time begin problems. Toolbar buttons actionPerformed
are executed twice, what happen?, this problem I noted, happens exactly
when JDialog are loaded (created with new) for second time or more times.
It is not supposed closing JDialog, will dispose every component content
into it?, I tried using windowClosing event doing super.dispose(); and
this.dispose(); but nothing at all. Is like closing JDialog it leave it
hidden but not destroyed even using DISPOSE_ON_CLOSE. It is just only thing
I guess actionPerformed on button events be dispatched twice, I don't know!

I use jdk1.5.0_02 (update 2)

Thanks

Report this thread to moderator Post Follow-up to this message
Old Post
Aldemar Cuartas Carvajal via webservertalk.com
04-20-05 01:58 AM


Re: Buttons events dispatched twice
In your actionPerformed, do you check to see if the button is the
source of the event?


Report this thread to moderator Post Follow-up to this message
Old Post
klynn47@comcast.net
04-20-05 01:58 AM


Re: Buttons events dispatched twice
I'm adding JButtons on toolbar by for loop like this:

for (int i = 0; .....; i++) {
JButton myButton = new JButton(..);
myButton.addActionListener(this);
myButton.addActionCommand(String.Format("%d", i));
...
}

So you can Note I use actionCommand as Button ID. and...

public void actionPerformed(...e) {
if (((JButton)e.getSource).getActionCommand.equals("0") {
<instructions>
}
if (((JButton)e.getSource).getActionCommand.equals("1") {
<instructions>
}

..
}

when JDialog loas for first time (created using new) actionPerformed
dispatched well and instructions are executed OK. BUt exiting from JDialog
and re-entering againg actionPerformed are dispatched twice so,
instructions are executed twice.

Report this thread to moderator Post Follow-up to this message
Old Post
Aldemar Cuartas Carvajal via webservertalk.com
04-20-05 01:58 AM


Re: Buttons events dispatched twice
Does your class have any static members?
If your JButtons are stored static class members, this could result in
the problem you are describing.


Report this thread to moderator Post Follow-up to this message
Old Post
sanjay manohar
04-20-05 01:58 AM


Re: Buttons events dispatched twice
No!

How I said buttons are dynamically created like as: JButton myButton = new
JButton(); no static member.

I just tried on windowClosing - JDialog, setVisible(false); and dispose();
but nothing happen, trying to destroy whatever dialog visible and hidden
could have.

Report this thread to moderator Post Follow-up to this message
Old Post
Aldemar Cuartas Carvajal via webservertalk.com
04-20-05 09:00 AM


Re: Buttons events dispatched twice
Aldemar Cuartas Carvajal via webservertalk.com wrote:

> Hi!
>
> Into my main class I Create JDialogs, and I use JDialog.DISPOSE_ON_CLOSE
as
> defaultCloseOperation and setVisible(true) in order to show it. When I run
> my application for first time, and clicking on menu item I create a
> JDialog, so, I can use Toolbar buttons with no problems, actionPerformed
is
> executed normally, just once, everything works OK. I close my Dialog and
re-
> entering for second time begin problems. Toolbar buttons actionPerformed
> are executed twice, what happen?, this problem I noted, happens exactly
> when JDialog are loaded (created with new) for second time or more times.
> It is not supposed closing JDialog, will dispose every component content
> into it?, I tried using windowClosing event doing super.dispose(); and
> this.dispose(); but nothing at all. Is like closing JDialog it leave it
> hidden but not destroyed even using DISPOSE_ON_CLOSE. It is just only
thing
> I guess actionPerformed on button events be dispatched twice, I don't
know!
>
> I use jdk1.5.0_02 (update 2)
>
> Thanks

Are you adding an additional actionListener, so that two actions are
performed for the one event?

--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail :    nmw@ion.le.ac.uk
Phone :     +44 (0)116 2523548, Fax : +44 (0)116 2523555

Report this thread to moderator Post Follow-up to this message
Old Post
Nigel Wade
04-20-05 01:58 PM


Re: Buttons events dispatched twice
Note that, although all Objects (eg windows and frames) are disposed on
closing, the Classes are not always. This would mean that any
information stored in static variables would remain in memory.
Are you creating the window in a static member variable? like this

class MyApp{
static JFrame myFrame = new MyFrame();
public static void main(String[] s){
myFrame.setVisible(true);
}
}

if so, your frame object may persist across different instatiations of
the app.

You could try using System.exit() when the application is closed. if it
is a static problem, this might fix it.


Report this thread to moderator Post Follow-up to this message
Old Post
sanjay manohar
04-23-05 01:58 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Java Help archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:18 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.