Hello, I am getting a stack overflow error on line 30(frame = new JFrame("BlinkLabel") And I dont know why, everything looks fine to me. I think it is something simple, but I just can't see it. Any help is very appreciated =].
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.KeyEvent;
import java.awt.Color;
public class BlinkingLabel extends JLabel
{
//instance variables to store foreground and background color
private Color backGroundC;
private Color foreGroundC;
private JPanel panel1;
BlinkingLabel myBlinkingLabel;
JFrame frame;
private int blinkRate = 1000; //ms
public BlinkingLabel(String s)
{
//super(s);
backGroundC=Color.BLACK;
foreGroundC=Color.GRAY;
frame = new JFrame("BlinkLabel");
myBlinkingLabel = new BlinkingLabel("I'm blinking!");
panel1= new JPanel();
panel1.add(myBlinkingLabel);
frame.add(panel1);
//frame.getContentPane().setLayout(new java.awt.FlowLayout());
//frame.getContentPane().add(myBlinkingLabel);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
setOpaque(true);
new TimerThread().start();
}
private class TimerThread extends Thread
{
public void run()
{
try
{
while(!isInterrupted())
{
BlinkingLabel.super.setForeground(foreGroundC);
setForeground(foreGroundC);
sleep(blinkRate);
BlinkingLabel.super.setForeground(backGroundC);
}
}
catch(InterruptedException ie)
{
System.out.println("timer interrupted");
}
}
}
public void setBackground(Color c)
{
backGroundC=c; //updates my instance variable, used in timer
super.setBackground(c); //actually changes the background color of the JLabel
}
public void setForeground(Color c)
{
foreGroundC=c;
super.setForeground(c);
}
public static void main(String[] args)
{
//java.awt.EventQueue.invokeLater(new Runnable()
//{
//public void run()
{
new BlinkingLabel("");
//createGUI();
}
//});
}
}