• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

multithreading issue

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I cant get my banner text to show up in my applet only the calculator shows up..so do i need to add a label and display the rotating text in the labels, instead of using the drawString(). if so, how do i do this?

here is my code:

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.applet.*;

/*
*
<applet code="SimpleBanner" width=350 height=100>
</applet>
*/

public class SimpleBanner extends Applet implements Runnable {
String msg = " Say YES to Multi-threading ";
Thread t = null;
Thread threadCal = null;
int state;
boolean stopFlag;
Calc c = new Calc();
Panel p1 = new Panel();
Panel p2 = new Panel();

/*In the SimpleBanner class, add a label and display
the rotating text in the labels, instead of using the drawString().*/






// Set colors and initialize thread.
public void init() {

setLayout(new GridLayout(2, 1));
setBackground(Color.yellow);
setForeground(Color.black);
add(p1);

c.init();
p2.setBackground(Color.pink);
p2.setLayout(new GridLayout(1,1));
add(p2);
p2.add(c);




}

// Start thread
public void start() {
t = new Thread(this);
threadCal = new Thread();
stopFlag = false;
t.start();
threadCal.start();
}

// Entry point for the thread that runs the banner.
public void run() {
char ch;

// Display banner
for( ; ; ) {
try {
repaint();
Thread.sleep(250);
ch = msg.charAt(0);
msg = msg.substring(1, msg.length());
msg += ch;
if(stopFlag)
break;
} catch(InterruptedException e) {}
}
}

// Pause the banner.
public void stop() {
stopFlag = true;
t = null;
}

// Display the banner.
public void paint(Graphics g) {
g.drawString(msg, 20, 30);
}
} //public class SimpleBanner extends Applet implements Runnable {
 
Poop goes in a willow feeder. Wipe with this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic