Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.help > #2260
| Newsgroups | comp.lang.java.help |
|---|---|
| Date | 2012-11-15 07:06 -0800 |
| Message-ID | <b18cadc9-199f-4900-9f44-b25ec90acbd4@googlegroups.com> (permalink) |
| Subject | Please help me kill this java thread..... code example |
| From | kedward777@gmail.com |
I am using a JVM for a mobile device based on java 1.4, ~old I know, but it is what I must use.
I am creating a simple swing application with a gui and a barcode laser scanner api. I place the swing gui thread in the AWT-EventQueue, and then I place barcode scanner code in a worker thread to feed the gui scanned item codes. Problem is, that when I click exit on the gui, ONLY the gui shuts down. I can't seem to kill the worker thread. Have a look:
public class Main extends javax.swing.JFrame implements ActionListener, ScannerListener, ItemListener, KeyListener {
Scanner scanner;
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Main().setVisible(true);
}
});
}
public Main() {
//display GUI - a simple field to display the item number when the
// barcode scanner trigger is pressed, and a exit button to close the app
initComponents();
// launch the scanner code to feed the gui scanned items
worker = new Runnable()
{
public void run()
{
try
{
//a while loop to scan and wait
launchScanner();
}
catch (Exception e) { }
};
scannerThread = new Thread(worker);
scannerThread.start();
}
private void shutdown(java.awt.event.ActionEvent evt) {
//this will shutdown the gui when the exit button is pressed. BUT how do I kill the scanner thread?
System.exit(0);
}
Back to comp.lang.java.help | Previous | Next — Next in thread | Find similar | Unroll thread
Please help me kill this java thread..... code example kedward777@gmail.com - 2012-11-15 07:06 -0800
Re: Please help me kill this java thread..... code example kedward777@gmail.com - 2012-11-15 07:09 -0800
Re: Please help me kill this java thread..... code example Knute Johnson <nospam@knutejohnson.com> - 2012-11-15 08:42 -0800
Re: Please help me kill this java thread..... code example Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-15 11:49 -0500
Re: Please help me kill this java thread..... code example kedward777@gmail.com - 2012-11-15 10:16 -0800
Re: Please help me kill this java thread..... code example Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-15 13:33 -0500
Re: Please help me kill this java thread..... code example kedward777@gmail.com - 2012-11-15 10:56 -0800
Re: Please help me kill this java thread..... code example Eric Sosman <esosman@comcast-dot-net.invalid> - 2012-11-15 14:21 -0500
Re: Please help me kill this java thread..... code example Roedy Green <see_website@mindprod.com.invalid> - 2012-11-15 13:37 -0800
csiph-web