🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.lenguajes.java
Article #29431

Re: Una de Threads

#29431
From: Eustaquio Mart�n
Date: Wed, 03 Dec 1997 00:00
97 lines
2883 bytes
Incre�ble pero cierto, resulta que ayer no me funcionaba y hoy si, no lo
entiendo (�duendecillos...?).
No obstante por cortes�a, aqu� tienes el c�digo:

package untitled3;
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import borland.jbcl.layout.*;
import borland.jbcl.control.*;
public class Applet1 extends Applet {
  XYLayout xYLayout1 = new XYLayout();
  boolean isStandalone = false;
  Button button1 = new Button();
  Label label1 = new Label();
  boolean andando=true;
  int z;
  Label label2 = new Label();
  contador cont1;
  contador cont2;

  public String getParameter(String key, String def) {
    return isStandalone ? System.getProperty(key, def) :
      (getParameter(key) != null ? getParameter(key) : def);
  }

  public Applet1() {
  }
  public void init() {
    try { jbInit(); } catch (Exception e) { e.printStackTrace(); }
  }
  public void jbInit() throws Exception{
    xYLayout1.setWidth(400);
    xYLayout1.setHeight(300);
    button1.setLabel("Parar");
    button1.addMouseListener(new Applet1_button1_mouseAdapter(this));
    this.setLayout(xYLayout1);
    this.add(button1, new XYConstraints(143, 228, -1, -1));
    this.add(label1, new XYConstraints(146, 192, 63, -1));
    this.add(label2, new XYConstraints(112, 132, 140, -1));
   cont1= new contador(this,label1);
   cont2= new contador(this,label2);
  }

  public void start(){
   cont1.start();
   cont2.start();
  }

  public String[][] getParameterInfo() {
    return null;
  }

  void button1_mouseClicked(MouseEvent e) {
    if (andando){
     cont1.suspend();
      button1.setLabel("Reanudar");
    }else{
     cont1.resume();
      button1.setLabel("Parar");
    }
    andando=!andando;
  }
}


class contador extends Thread{
 Applet1 padre;
  int x=0;
  Label etiqueta;

  public void contador(Applet1 padre,Label etiqueta){
   this.padre=padre;
    this.etiqueta=etiqueta;
  }

 public void run(){
    for (x=0;x<1000000;x++){
     etiqueta.setText(Integer.toString(x));
      padre.repaint();
    }
  }
}


class Applet1_button1_mouseAdapter extends java.awt.event.MouseAdapter {
  Applet1 adaptee;

  Applet1_button1_mouseAdapter(Applet1 adaptee) {
    this.adaptee = adaptee;
  }

  public void mouseClicked(MouseEvent e) {
    adaptee.button1_mouseClicked(e);
  }
}
Technical Details
Message-ID: <663net$3sv$1@talia.mad.ibernet.es>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <660r7l$33$1@talia.mad.ibernet.es> <34842D41.D83F8A11@ran.es>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1116f3,2d4bf9d106d03a9
X-Google-Attributes: gid1116f3,public
From: "Eustaquio Mart�n" <eustma@softcom.es>
Subject: Re: Una de Threads
Date: 1997/12/03
Message-ID: <663net$3sv$1@talia.mad.ibernet.es>
X-Deja-AN: 294844349
References: <660r7l$33$1@talia.mad.ibernet.es> <34842D41.D83F8A11@ran.es>
X-MimeOLE: Produced By Microsoft MimeOLE V4.71.1712.3
Organization: Unisource Espana NEWS SERVER
Newsgroups: es.comp.lenguajes.java