Hi
I got several Threads:
one to Listen the Joystick input and fire an event when a significant change was detected, works very good with jinput.
the other one is a swing jFrame shown for several seconds when a event was fired.
The basic was my app does is listen to the joystick -> execute a action and displays a JFrame what happend.
I dont wanna that 2 JFrames show up at the same time, when a new JFrame should be opened the older one should dispose before the new one shows up.
...
while(queue.getNextEvent(event)) {
StringBuffer buffer = new StringBuffer();
Component comp = event.getComponent();
JoyStickAction.action(comp, event.getValue());
}
...
the joystick listener executing the action class
...
if(display_window) {
new DisplayInfo("title", window_text, 250, 50, 1000).start();
}
...
at the end of the action class
DisplayInfo is the class that opens the JFrame I wanna close when already a instance was createt
import javax.swing.*;
import java.awt.*;
public class DisplayInfo extends Thread {
//title and text
String title;
String text;
//size in pixels
int width = 400;
int height = 100;
//time to display in ms
int time = 3000;
//class infos
static int instances = 0;
static DisplayInfo instance;
public DisplayInfo(String title, String text, int width, int height, int time) {
if(instances>0) {
instance.stopInstance();
}
++instances;
instance = this;
this.title = title;
this.text = text;
this.width = width;
this.height = height;
this.time = time;
}
public void run() {
//Create and set up the window.
JFrame frame = new JFrame(title);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setUndecorated(true); //removes the borders
//add text to the frame
JLabel label = new JLabel(instances+" - "+text, JLabel.CENTER);
label.setForeground(new Color(0xBB, 0xBB, 0xBB));
frame.getContentPane().add(label);
//set size
frame.setSize(width, height);
//get screen size
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension screenSize = toolkit.getScreenSize();
//Calculate the frame location
int x = (screenSize.width - frame.getWidth()) / 2;
int y = ((screenSize.height - frame.getHeight()) / 3) * 2;
//color
frame.getContentPane().setBackground(new Color(0x33, 0x33, 0x33));
//Display the window.
frame.setLocation(x ,y);
frame.setVisible(true);
//wait
try {
Thread.currentThread().sleep(time);
} catch(InterruptedException ie) { }
//close
frame.dispose();
}
public void stopInstance() {
--instances;
this.stop();
}
}
I already tested something with instance counting and trying to close the old one but that wont work.
Probably the the thread wont be passed by reference to “instance”?
It’s the way I would do it in PHP 
How could I get it work?
Hopefully you understand what I wanna say…

