import java.awt.*; import java.awt.event.*; import borland.jbcl.control.*; import borland.jbcl.layout.*; import omat.adapter.*; public class SaieFrame extends DecoratedFrame { BorderLayout borderLayout = new BorderLayout(); XYLayout xYLayout2 = new XYLayout(); BevelPanel bevelPanel = new BevelPanel(); Button button = new Button(); final int BUTTON = 1, LABEL = 2; final int SAIKEITA = 20; final int KIERROKSIA = 1000000; Label[] label = new Label[SAIKEITA]; cLaskuri[] laskuri = new cLaskuri[SAIKEITA]; //Construct the frame public SaieFrame() { try { jbInit(); } catch (Exception e) { e.printStackTrace(); } } //Component initialization public void jbInit() throws Exception{ int i; this.setLayout(borderLayout); this.setSize(new Dimension(160, 500)); this.setTitle("SaieFrame"); button.setFont(new Font("Dialog", 0, 10)); button.setLabel("Käynnistä"); button.addMouseListener(new ActionAdapter(MouseEvent.MOUSE_CLICKED,this, "button_mouseClicked",button)); bevelPanel.setLayout(xYLayout2); this.add(bevelPanel, BorderLayout.CENTER); bevelPanel.add(button, new XYConstraints(70, 21, 71, 26)); for (i = 0; i < SAIKEITA; i++) { label[i] = new Label("0"); label[i].setFont(new Font("Dialog", 0, 10)); bevelPanel.add(label[i], new XYConstraints(10, 10 + i*20, 50, 20)); } } public void button_mouseClicked(Object o, Object event) { for (int i = 0; i < SAIKEITA; i++) { if (laskuri[i] != null ) if ( laskuri[i].isAlive() ) continue; laskuri[i] = new cLaskuri(label[i],KIERROKSIA); laskuri[i].start(); laskuri[i].setPriority(laskuri[i].MIN_PRIORITY); label[i].addMouseListener(new ActionAdapter(MouseEvent.MOUSE_CLICKED,this, "label_mouseClicked",laskuri[i])); } } public void label_mouseClicked(Object o, Object event) { ((cLaskuri) o).lopeta(); } } class cLaskuri extends Thread { Label Text; final int PAIVITYS = 5000; int n; int raja; boolean loppuu = false; cLaskuri(Label Text, int raja) { this.Text = Text; this.raja = raja; n = 0; } void lopeta() { loppuu = true; } public void run() { String mes = ""; while ( n < raja ) { if ( loppuu ) { mes = "T"; break; } count(); } Text.setText("" + n + mes); } void count() { if ( ++n % PAIVITYS == 0 ) Text.setText("" + n); } }