Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 am creating an applet that has to have a text banner and calc.class also..the calculator shows up but the text from the string msg doesn't show up ..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();








// 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 {
 
This is my favorite tiny ad:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic