File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Swing / AWT / SWT and the fly likes JButton on multiple instances of applet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JButton on multiple instances of applet" Watch "JButton on multiple instances of applet" New topic

JButton on multiple instances of applet

Alfred Harre
Ranch Hand

Joined: Apr 29, 2004
Posts: 73
I have an applet that uses JFrame and JFrame has JButton on it.
when I start multiple instances of this Frame, JButtons work only on the last frame/window and become inactive on any precding window.
Any ideas and help is greatly appreciated.
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
It sounds like you're trying to reuse an instance variable in class scope, like this:

Here each listener is registered on only one (the last) button.
Try it with button as a local variable, ie, make a separate JButton for each call from launch. Then each button has its own listener. Like this:
I agree. Here's the link:
subject: JButton on multiple instances of applet
It's not a secret anymore!