Ask Experts Questions for FREE Help!
Ask    ||    Answer
 
Advanced  
 

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Internet & the Web   »   Java Threads

 
Thread Tools Search this Thread Display Modes
Question
 
 
#1  
Old Sep 14, 2003, 10:12 PM
poeta_boy
New Member
poeta_boy is offline
 
Join Date: Sep 2003
Location:
Posts: 1
poeta_boy See this member's comment history on his/her Profile page.
Send a message via ICQ to 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

Reply With Quote
 
     


Your Answer
Email me when someone replies to my answer
Join Login





Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

 
Similar Sponsors


Thread Tools
Show Printable Version Show Printable Version
Email this Page Email this Page

Similar Threads
threads
(2 replies)
threads
(7 replies)
Old threads
(17 replies)
Threads won't seal
(4 replies)
closing threads
(48 replies)

Search this Thread

Advanced Search

Bookmarks

Sponsors



Copyright ©2003 - 2009, Ask Me Help Desk.
All times are GMT -8. The time now is 03:54 PM.