public class ThreadedSwing extends JFrame {
static boolean useThreads = false;
static boolean KILL = false;
public ThreadedSwing() {
ThreadedJButton button;
if (System.getProperty("KILL") != null)
KILL = true;
setTitle("ThreadedSwing");
JPanel topPanel = new JPanel();
getContentPane().add(topPanel);
ThreadButtonListener tbl = new ThreadButtonListener();
NumericButtonListener nbl = new NumericButtonListener();
button = new ThreadedJButton("Non-Threaded");
topPanel.add(button);
button.addActionListener(tbl);
for (int i = 1; i < 5; i++) {
button = new ThreadedJButton(""+i);
topPanel.add(button);
button.addActionListener(nbl);
}
}
public static void main(String args[]) {
ThreadedSwing mainFrame = new ThreadedSwing();
mainFrame.pack();
mainFrame.setVisible(true);
// Killer MUST be in another thread.
if (KILL)
new Thread(new Killer(120)).start();
}
}
//
ThreadedSwing/NumericButtonListener.java
/*
This classes listens only for button pushes on the numbered buttons.
*/
import
java.applet.*;
import
java.awt.*;
import
java.awt.event.*;
import
com.sun.java.swing.*;
import
Extensions.*;
public class NumericButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent event) {
ThreadedJButton currentButton =
(ThreadedJButton)event.getSource();
System.out.println("Pressed " + currentButton);
currentButton.setEnabled(false);
System.out.println(currentButton + " disabled.");
Search WWH :
Custom Search
Previous Page
Multithreaded Programming with JAVA - Topic Index
Next Page
Multithreaded Programming with JAVA - Bookmarks
Home