Traffic light  repaint not working via button

I created a traffic light, a button is pressed and the colors should cycle yellow>green>yellow>red etc.. as a normal traffic light would
when i press the start button, the repaint(); doesnt work, system.output shows me the number which corresponds to the light changes but somehow the graphics/paint is not updated.
what am i doing wrong?
package test2;<br />
<br />
import java.awt.event.ActionEvent;<br />
import java.awt.event.ActionListener;<br />
import javax.swing.JButton;<br />
import javax.swing.JOptionPane;<br />
import javax.swing.JPanel;<br />
<br />
public class Traffic_Lights extends JPanel implements ActionListener {<br />
<br />
private Light_Controller LightController;<br />
private JButton jStart, jStop;<br />
<br />
public Traffic_Lights() {<br />
jStart = new JButton("START");<br />
jStop = new JButton("EXIT");<br />
<br />
// Register Listeners with buttons<br />
jStart.addActionListener(this);<br />
jStop.addActionListener(this);<br />
LightController = new Light_Controller();<br />
this.add(jStart);<br />
this.add(jStop);<br />
}<br />
// Adding the traffic light<br />
<br />
<br />
/**<br />
* This method traps the button click events<br />
*/<br />
public void actionPerformed(ActionEvent e) {<br />
// Rotate button is clicked<br />
if (e.getSource() == jStart) {<br />
// Change the color displayed<br />
LightController.changeColor();<br />
package test2;<br />
import java.awt.*;<br />
import java.awt.geom.Rectangle2D;<br />
import javax.swing.JComponent;<br />
import javax.swing.JPanel;<br />
<br />
<br />
public class Light_Controller extends JPanel {<br />
<br />
private int lightState = 1;<br />
<br />
<br />
public void changeColor() {<br />
lightState++;<br />
System.out.println(lightState);<br />
if (lightState > 5) {<br />
lightState = 2;<br />
<br />
}<br />
<br />
this.repaint();<br />
<br />
}<br />
<br />
/**<br />
* This method draws the traffic light on the screen<br />
*/<br />
public void paintComponent(Graphics g) {<br />
super.paintComponent(g);<br />
<br />
Graphics2D g1 = (Graphics2D) g;<br />
// Draws the traffic light<br />
// Draw out white frame<br />
g.setColor(new Color(255,255,255));<br />
g.fillRoundRect(35,15,120,225,30,30);<br />
<br />
// Draw inner black frame<br />
g.setColor(new Color(0,0,0));<br />
g.fillRoundRect(50,30,90,195,30,30);<br />
g.drawRoundRect(35,15,120,225,30,30);<br />
<br />
// RED dim<br />
g.setColor(new Color(100,0,0));<br />
g.fillOval(70,40,50,50);<br />
<br />
// YELLOW dim<br />
g.setColor(new Color(100,100,0));<br />
g.fillOval(70,100,50,50);<br />
<br />
// GREEN dim<br />
g.setColor(new Color(0,100,0));<br />
g.fillOval(70,160,50,50);<br />
<br />
// Draw traffic light stand<br />
g.setColor(new Color(50,50,50));<br />
g.fillRect(80,240,30,30);<br />
<br />
switch(lightState) {<br />
case 1:<br />
// red glows<br />
g.setColor(new Color(255, 0, 0));<br />
g.fillOval(70, 40, 50, 50);<br />
g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
break;<br />
<br />
case 2:<br />
// yellow glows<br />
g.setColor(new Color(255, 255, 0));<br />
g.fillOval(70, 100, 50, 50);<br />
g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
break;<br />
<br />
case 3:<br />
// green glows<br />
g.setColor(new Color(0, 255, 0));<br />
g.fillOval(70, 160, 50, 50);<br />
g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
break;<br />
<br />
case 4:<br />
// back to yellow glows<br />
g.setColor(new Color(255, 255, 0));<br />
g.fillOval(70, 100, 50, 50);<br />
g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
break;<br />
<br />
case 5:<br />
// back to red glows<br />
g.setColor(new Color(255, 0, 0));<br />
g.fillOval(70, 40, 50, 50);<br />
g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
break;<br />
}<br />
}<br />
} <br />

Code continued...
class Light_Controller extends JPanel {
    private int lightState = 1;
    public void changeColor() {
        lightState++;
        System.out.println(lightState);
        if (lightState > 5) {
            lightState = 2;
        this.repaint();
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        Graphics2D g1 = (Graphics2D) g;
        g.setColor(new Color(255, 255, 255));
        g.fillRoundRect(35, 15, 120, 225, 30, 30);
        g.setColor(new Color(0, 0, 0));
        g.fillRoundRect(50, 30, 90, 195, 30, 30);
        g.drawRoundRect(35, 15, 120, 225, 30, 30);
        g.setColor(new Color(100, 0, 0));
        g.fillOval(70, 40, 50, 50);
        g.setColor(new Color(100, 100, 0));
        g.fillOval(70, 100, 50, 50);
        g.setColor(new Color(0, 100, 0));
        g.fillOval(70, 160, 50, 50);
        g.setColor(new Color(50, 50, 50));
        g.fillRect(80, 240, 30, 30);
        switch (lightState) {
            case 1:
                g.setColor(new Color(255, 0, 0));
                g.fillOval(70, 40, 50, 50);
                g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                break;
            case 2:
                g.setColor(new Color(255, 255, 0));
                g.fillOval(70, 100, 50, 50);
                g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                break;
            case 3:
                g.setColor(new Color(0, 255, 0));
                g.fillOval(70, 160, 50, 50);
                g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                break;
            case 4:
                g.setColor(new Color(255, 255, 0));
                g.fillOval(70, 100, 50, 50);
                g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                break;
            case 5:
                g.setColor(new Color(255, 0, 0));
                g.fillOval(70, 40, 50, 50);
                g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                break;
}

Similar Messages

  • Nano 6th sinks (not working) Sleep Button.

    on my iPod nano 6th not working Sleep Button. problem occurs a second time.
    problem has been, decided to change the service center to the next. Now this is not possible, the warranty is over. how can I fix this problem?

    Hello J-Dub 181,
    And welcome to Apple Discussions!
    Have you tried resetting the iPod? If not, press and hold the Center and Menu buttons together until the Apple logo appears.
    If, you are still have issues after resetting the iPod, it may be best to restore the iPod via iTunes and start from scratch. Usually a restore can resolve these types of issues.
    [Restoring iPod to factory settings|http://support.apple.com/kb/HT1339]
    B-rock

  • I ipod classic 80 gb when I am connected pc connected after that is hanged just showing connected its not working any button

    I ipod classic 80 gb when I am connected pc connected after that is hanged just showing connected its not working any button .

    Try connecting it to another PC, if it is ok, then your PC has some software conflict with iTunes.
    If it hangs other PC also, then your iPod Hardisk, maybe bad.
    Do the disk diagnosticas posted earlier by tt2, to check the health of your Hardisk.
    Have a nice day!

  • Hello my battery power has a x on it and the lights are not working and its making a noise - Please assist

    Hello my battery power has a x on it and the lights are not working and its making a noise - Please assist

    The Battery icon with the "X" indicates that your computer does not detect a battery and is operating on electrical power from AC since your computer is plugged in. If your battery is installed but not detected that indicates a problem: 1. the battery is dead; 2. the battery connector is not functioning properly. You mention that there is no response from the indicator lights so it could be either of the two possibilities. The noise is not a good sign. Best to shut it down safely while you can to prevent any possibility of damage and get it to an Apple Genius Bar or Authorized Apple Service Provider to discover the nature of the problem

  • Multi-Row insert/update/delete not working via db-link

    App. Version: 2.0.0.00.49
    DB: Oracle 9i, not sure about the build
    Problem: Multirow Update/Insert/Delete doesn't work via db-link.
    Error received: ....ORA-1460: unimplemented or unreasonable conversion requested....
    Where: Tabular Form generated via Wizard
    Side note: It's working properly when local table(s) is/are used, it's not working via db-link or view.
    I've encountered this error with single update/insert/delete operations before, but was able to fix it via using temp-variables (v_xyz := :Px_xyz; as the proposed v('Px_xyz') was really slow with my scripts)...but with the automated DML-action I don't see a way to edit it accordingly.
    Workaround found:
    1a) Use local* collection on HTML-DB-Server, then write single row updates/deletes/inserts to the remote DB via DB-Link
    1b) Use local* table on HTML-DB-Server, then write single row updates/deletes/inserts to the remote DB via DB-Link
    * Local = on the same server that HTML-DB is running on...
    So,...to my questions:
    1. Can someone confirm that this is a "known feature" (aka bug)?
    2. Can someone tell me if this "known feature" has been eliminated in the newer version of HTML-DB/APEX (> 2.0.0.00.49)?
    Thanks.
    Ingo

    Hi,
    Do you have a small test case program that demonstrates this? A JDeveloper project showing what exactly is the problem when trying to use the BDB SQL JDBC driver to insert data into the BDB SQL database? What do you mean by "not working", do you get any errors, you do not get errors but you do not see the data in the database etc?
    What are the versions of Java, JDeveloper, ADF and BDB SQL you are using, and on what OS?
    Regards,
    Andrei

  • I have a macbook pro the fan wont stop running the keyboard light is not working and the it wont charge all happened all of a sudden what to do please.

    have a macbook pro the fan wont stop running the keyboard light is not working and the it wont charge all happened all of a sudden what to do please.

    Reset SMC.     http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".
    If this does not help, you may have to take the MBP to the Apple Store  to have it checked.
    Best

  • Lighting Effect not work in CS6*

    Why Filter/ Render/ Lighting Effect not work in CS6?
    It's not work only in CS6 Beta or in anything else :-/. It's Useful with me

    A bit more information would be helpful.  What is happening on your system when you go to  lighting effects?
    What system are you running on? What video card are you using? Are you using the most recent driver?
    Do check our system FAQ as GPU is requried for lignting effects to work properly.
    FAQ: What features use the GPU and how do I troubleshoot GPU issues?
    Pattie

  • My flash light is not working

    My flash light is not working..My phone is a month old... and I only used the flash twice... Doesn't work at all... I tried different apps as well...

    Backup and Restore
    http://support.apple.com/kb/HT1766

  • Flash light is not working in camera or Torch after upgrade

    Hello
    My S850 Flash light is not working while I click any Picture or while turning the torch ON. It was wprking perfectly before but after Upgrade it stopped working.
    baseband version is: S850.ROW.V109,2014/09/23
    BUILD NUMBER: S850_ROW_211_140923
    Kalpesh

    Hi
    Sorry...The flash isn't working when you take pictures or the torch/flashlight isn't working?
    Did someone help you today? Press the star on the left to thank them with a Kudo!
    If you find a post helpful and it answers your question, please mark it as ''ACCEPT AS SOLUTION"! 
    Unsolicited PM's will not be answered! ....Please post your question/s in the appropriate forum board.
    English Community   Deutsche Community   Comunidad en Español   Русскоязычное Сообщество

  • Segoe UI Light font not working

    Segoe UI Light does not work in Firefox 8 when using it in CSS.

    Use this CSS:
    font-family: "Segoe UI";
    font-weight: lighter;

  • Why light led not work???

    Hey, wondering why the light led not working on Htc one m7??? i tried everything like reset factory etc.. STILL SAME.. Ugh.... Anyone know how to force it to work????

    ajnevares3
    THANK YOU FOR TRYING HELP ME WITH UR INFORMATION.... I WENT AHEAD DO WHAT YOU EXPLAINED..
    IT WORKED ON MY HTC ONE M7!!!!!!!!!! THE LIGHT LED IS WORKING NOW.. BECAUSE OF YOU, YOU RE BEST!!!!
    THANK YOU SO MUCH!!!!

  • Toshiba - A665-S5170: ambient light sensor not working after recovery

    Hi all,
    Two weeks ago I bought Toshiba - Satellite Laptop Model: A665-S5170 | SKU: 1859059
    http://www.bestbuy.com/site/Toshiba+-+Satellite+Laptop+/skuId=1859059
    I tried to resize the C: partition using the recovery option. It works fine ending with C: partition (100 GB) and D: partition (480GB)
    All the divers and applications restored fine except the ambient light sensor.
    I used system recovery to out-of-box state, but still have the same problem "ambient light sensor not working".
    Would you please help me find a solution?
    Thanks in advance.

    I had the same problem. I tried resetting SMC but that didn't do the trick. Then I tried “Repair disc permissions“ and that fixed the problem.

  • My computer's power adapter is plugged into a power source, yet the indicator light is not working and my computer is not being charged.

    My computer's power adapter is plugged into a power source, yet the indicator light is not working and my computer is not being charged.

    I have the same issue.
    The magsafe goes orange for about 20 seconds, the battery shows 0% then it goes to a black X indicating no battery installed.
    With a new battery the same happens, although it can run on battery but does not charge.
    It runs fine on mains power, the green light is always lit.
    I have tried several things so far:
    1. Cleaned the magsafe contacts on cable and macbook
    2. Reset SMC and PRAM
    3. Installed latest battery update
    4. Tried new battery
    5. Put old battery in fridge for an hour
    I work in IT and am fairly confident taking it apart, what should I try next?
    Some people recommend a new battery connector, which doesn't seem to make sense as the battery has never been removed before.  Also some people say it will need a new logic/motherboard.
    Any experts here managed to sucessfully fix one of these?

  • CAPS LOCK light is not working

    Hello dear guys, 
    Had a problem today - some keyboard keys didn't work properly. 
    I opened the laptop (Pavilion G6 2241sa) cover and saw that keyboard cable was loose. I reconnected it properly, closed the cover and switched laptop on. Now, all  keys are working fine, BUT CAps Lock light is not working well. Key is functioning, but when I press it - the light come on, but as soon as I release the key - the light goes off. Light doesn't stay. Also when the actual function of caps lock is on, when I press any other key the light come on the surface of Caps lock key but it is dim. 
    I recheched keyboard cable again - all is fine, but Caps lock light doesn't stay on when pressed. 
    I do practice typing for the last 3 months for few hours each day, so I guess it also affects the life span of my keyboard.
    Would appreciate any insights about this Caps Lock light. Many thanks, Vit
    This question was solved.
    View Solution.

    Hi there @vitsirius 
    I understand that the Caps Lock LED is not working, after you had fixed a loose connection to your keyboard.
    You may want to walk through this page and see if something may help
    Notebook Keyboard Troubleshooting (Windows 8)
    Also for your convenience here is the maintenance guide. It is possible when you were working on it one of the of the other connections was loose or became so.
    HP Pavilion g6 Notebook PC Maintenance and Service Guide
    Malygris1
    I work on behalf of HP
    Please click Accept as Solution if you feel my post solved your issue, it will help others find the solution.
    Click Kudos Thumbs Up on the right to say “Thanks” for helping!

  • Appraisal template standard buttons not working via ESS/MSS

    Hi experts,
    The error which I am facing in appraisal template is as follows
    When I click on any button on appraisal template no action takes place.
    Kindly let me know how can I resolve this error.
    we are using BSP application HAP_DOCUMENT.
    according to me page fragment 'document_buttons.htm' (Method CONVERT_BUTTON_TO_UI) contains the code for button creation and button handling
    the page fragment 'document_buttons.htm' is getting triggered when page is initialized but it is not triggering when button is clicked.
    Additional info that might be useful to resolve the issue:
    1) While viewing appraisal template's web layout in t-code PHAP_CATALOG_PA.
         I am facing following script error.
         This error reappears when I click on any standard button For eg SAVE
    2)  We are currently using IE 8
    3)  We recently upgraded ECC system from ECC 6.0 to ECC 6.0 / EHP 6 (ECC 6.6)
    4) I checked SICF and corresponding services are active
    Thanks in advance

    Hi Adrian,
    Design2008 service is inactive in my system.when activated temporarily I was not able to see previous page (Blank page was displayed) in my appraisal application.
    For BSP application HAP_document, i checked SICF->default host->SAP->BC->BSP->SAP->HAP_document.This service is active.
    The image which I have attached with my question is appraisal template's web layout in t-code PHAP_CATALOG_PA.
    regards
    Ninad

Maybe you are looking for

  • Superimposing text on movie images

    The help guide says something about selecting the text file and then clicking on the "Options" button. There is not an "Options" button. I've also tried selecting the part of the movie onto which I want to overlay the text and then pasting it on. It

  • Can I repeat the navegation bar at the bottom of a page?

    Hello, Some webpages I am writing are fairly long. I would like to repeat the navegation bar at the bottom of the page, so that the reader does not have to go to the top of the page to navegate through the pages of my website. Thank you!

  • Does the power adapter work with any country's voltage input

    Hi, My name is Jo, I am in South Africa and wish to purchase a 13inch MacBook Pro online. (The companies here charge ridiculous prices when buying locally - up to 500$ in addition to what Apple charges online!!) I believe that I will receive the best

  • FW400 and FW800

    Hi. Okay, so recently I got a FW400 PCMCIA card to give me a dedicated buss for running FW400 devices off of, so that I could utilise the full potential of my FW800 external hard drive on the internal buss. But, I've noticed that, when the FW400 PCMC

  • Treeview showing "weird Anuj" data in Photoshop CC

    I have a huge plugin (more than 15,000 lines of code) working perfectly in CS5 and above. Althought it works on Photoshop CC, I noticed that javascript treeview (usually shows data from an external XML file) are not showing the correct data in CC ver