Ask Experts Questions for FREE Help !
Ask
    poeta_boy's Avatar
    poeta_boy Posts: 0, Reputation: 1
    New Member
     
    #1

    Sep 14, 2003, 10:12 PM
    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

Check out some similar questions!

Threads [ 7 Answers ]

I'm an electrician and everyone says that electrical conduit threads are a straight thread, Our code says a 3/4" taper per ft which I have been told is the same as plumbing threads and that our electrical couplings are a straight thread, does any one know if plumbing threads are 3/4" taper. Thanks...

Threads won't seal [ 4 Answers ]

I've replaced the faucet (whole kit and caboodle - valve body, faucets, everything) in the tub/shower of one of my bathrooms. The only things that aren't new are the pipe running to the showerhead and the water lines running to the faucet body. I'm having a ****ens of a time getting the water...


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.