Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

multithreading issue

 
R. Aw
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 {
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic