• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help!! Runnable Interface Problem!!!  RSS feed

kei hosima
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on this for long time, and I have out of idea whatelse I should do to fix my code.
Hope someone could give me some adivce.
What I'm trying to do is this:
Define non-public class named MyLabel that encapsulates a customized Label component. It should extend the Label class and implement the Runnable interface in order to be run as a thread. A MyLabel object must display text that changes its color and font at a specified interval. If an attempt is made to set a null text or an interval that is less than zero, the corresponding "set" method must throw an Exception object having an appropriate error message.
The following is the part of my code.
private MyLabel myLabel;public void init() { myLabel = new MyLabel();// getting error message. don't know what to put after MyLabel. myLabel.setFont(new Font ("Serif", Font.PLAIN, 12));
myLabel.setForeground(Color.red); myLabel.setBackground(Color.black); c.gridx=0;
c.gridheight=1; c.gridwidth=GridBagConstraints.REMAINDER;
add(myLabel, c);
public void actionPerformed(ActionEvent e) { // if statemnets......
m.put(new String(nameField.getText()),
new Employee(nameField.getText(), Double.parseDouble(payRateField.getText().trim())));
msg.setText("The employee has been added to the collection.");
}catch (Exception err){

public void checkLabel(MyLabel myLabel)throws Exception{
class MyLabel extends Label implements Runnable{
int interval;
String myLabel;
MyLabel (String myLabel, int blinkSpeed){
Thread t = new Thread (this);
public void run() {
for(int i=0; i<100; i++) {
Thread.sleep((int)(Math.random() * 1));
} catch( InterruptedException e ) { System.out.println("Interrupted Exception caught");
Color oldForeground = getForeground(); setForeground(getBackground());
public void setMsg (String newMsgLabel){ myLabel = newMsgLabel;
throw new NullPointerException();}
public void setInterval (int newInterval){ interval = newInterval;
throw new NumberFormatException();}}

myLabel doesn't do anything. It does not blink at all.
What am I doing wrong?
Sorry for this long question... and thank you for reading everything.
Please give me some adivce.
I would very very appreciate your help!
Thanks in advance.
David O'Meara
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question: how long is your thread sleeping for?
Hint: check the Math.random and Thread.sleep APIs
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!