You are on page 1of 4

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

package lab54_thread3;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import static java.lang.Thread.sleep;

/**

* @author COMPU

*/

class Contador extends Thread{

private int inicio, fin; //valor inicial y final del contador

private String nombre; // nombre de la hebra

public Contador(int desde, int hasta, String id){

inicio=desde;

fin=hasta;

nombre=id;

public void run(){

System.out.println(nombre+"comienza...");

for(int i=inicio; i<=fin; i++){

System.out.print(nombre+"dice:"+i+".");

try{sleep(10); //deteiene la aplicacion una centesima de segundo


} catch(InterruptedException e){

e.printStackTrace();

System.out.println(nombre+"termina.");

public class Lab54_Thread3 {

/**

* @param args the command line arguments

*/

public static void main(String[] args) {

// TODO code application logic here

pantalla Ventana=new pantalla();

Ventana.setVisible(true);

Ventana.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

class pantalla extends JFrame{

public pantalla(){

setTitle("Vamos a Iniciar las dos Hebras");

setBounds(100,100,370,700);

Contenedor milamina=new Contenedor();

add(milamina);

}
class Contenedor extends JPanel implements ActionListener{

JLabel elemento1=new JLabel(" Vamos a Iniciar las dos hebras ");

JButton boton1=new JButton(" HEBRAS INICIALIZADAS ");

JButton boton2=new JButton(" HEBRA A ");

JButton boton3=new JButton(" HEBRA B ");

JButton boton4=new JButton(" EL PROGRAMA PRINCIPAL HA CONCLUIDO ");

JTextField Dato1=new JTextField(20);

JTextArea dato2=new JTextArea(20,20);

public Contenedor(){

add(elemento1);

add(boton1);

add(boton2);

add(boton3);

add(dato2);

add(boton4);

boton1.addActionListener(this);

boton2.addActionListener(this);

boton3.addActionListener(this);

boton4.addActionListener(this);

public void actionPerformed(ActionEvent e) {

if(e.getSource().equals(boton4)) {

System.exit(0);
}

if(e.getSource().equals(boton2)) {

add(dato2);

private void contadorA() {

int inicio = 0, fin = 10;

System.out.println("Hebra A comienza...");

for(int i=inicio; i<=fin; i++){

System.out.print("\nHebra A dice:"+i+".");

}}

You might also like