Hello
Im making a program where i have to make something with lights and borderlayout.
I have 3 classes.
1: Light
2: Partylights
3: Frame, the main-class
I want to make a arraylist in de partylights class, where the arraylist will be filled with objects comin out of the Light class. The problem is that there wont draw something in the layout. I placed my code of the class under.
I want to make a line of lights who can blink and have 4 different colors. How do i fill this arrayList and how can i accomplish that the light will be drawn?
Light:
PartyLights:Code:package Lights;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Light extends JPanel implements ActionListener
{
Color kleur;
boolean aan = true; //If light is on
boolean knipperend = false; //if light is blinkin
Timer blinkinLight;
int PosY, PosX, size;
public Lampje(int PosX, int PosY, int size, Color kleur)
{
this.kleur = kleur;
this.PosX = PosX;
this.PosY = PosY;
this.size = size;
Timer blinkinLight = new Timer(200, null);
blinkinLight.start();
}
public void paintComponent(Graphics g)
{
if(aan == true)
{
super.paintComponent(g);
g.setColor(kleur);
g.fillOval(PosX, PosY, grootte, grootte);
}
if(aan == false)
{
super.paintComponent(g);
g.setColor(Color.BLACK);
g.fillOval(PosX, PosY, grootte, grootte);
}
repaint();
}
Code:package Lights;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class Partylights extends JPanel implements KeyListener
{
ArrayList<Light> lights;
Light light;
public Partylights()
{
setRequestFocusEnabled(true);
lights = new ArrayList<Light>();
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
setBackground(Color.BLACK);
repaint();
}

