Ask Me Help Desk

Ask Me Help Desk (https://www.askmehelpdesk.com/forum.php)
-   Internet & the Web (https://www.askmehelpdesk.com/forumdisplay.php?f=177)
-   -   Java Threads (https://www.askmehelpdesk.com/showthread.php?t=4483)

  • Sep 14, 2003, 10:12 PM
    poeta_boy
    Java Threads
    Hello I have this program. Reloj class displays an Applet with a clock in it. Prueba class tries to invoke it but it just won't work. Can you help?



    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import java.text.*;

    public class Reloj extends Applet implements Runnable
    {
    Thread t;
    FontMetrics ft;
    int ancho, alto;

    public void init()
    {
    t = new Thread(this, "Reloj");
    Font font = new Font("Times New Roman", Font.BOLD, 36);
    setFont(font);
    ft = getFontMetrics(font);
    ancho = getBounds().width;
    alto = getBounds().height;
    t.start();
    }//init()

    public void run()
    {
    try
    {
    while (true)
    {
    //Graphics g = getGraphics();
    //paint(g);
    repaint();
    Thread.sleep(100);
    }
    }

    catch(InterruptedException ie){}
    }

    public void paint(Graphics g)
    {
    int fancho = 50 ;
    String hora = "";
    hora = DateFormat.getTimeInstance().format(new Date());
    int x = (ancho - fancho)/2;
    int y = (alto/2);
    g.drawString(hora, x, y);
    }
    }
    /****************************************/
    DIFFERENT FILE SAME DIR
    /***************************************/

    import java.awt.*;

    public class Prueba extends Frame
    {
    Reloj a;
    Prueba()
    {
    a = new Reloj();
    add(a);
    setSize(600,600);
    setVisible(true);
    //t.start();
    }
    public static void main(String args[])
    {
    Prueba a = new Prueba();
    }
    }

    /************************************/

    WHat I need to do is create a new thread (clock) and invoke it. The thing is that I need to create 3 threads (a clock, a drawing changing colors and a banner with my name) and then invoke them all in one main program. All threads at the same time, sharing the CPU. I have the clock, the drawing but I still need the banner... any ideas how to do it? Thanks a Lot

    Alejandro

  • All times are GMT -7. The time now is 12:03 AM.