Repaint not running properly when called in another class/actionlistener

I've got this code that is suppose to call and create a JPanel
(The frame and timeframe variables were declared statically at the beginning of the class)
When I call the runGame1 method from the main, the code runs fine and my JPanel is being repainted with the time and pictures, but when I can this runGame1 method from an ActionListener/actionPerformed method, it doesn't repaint properly and the while loop is running properly but I think there isn't enough resources for the method to actually paint my JFrame?? The JFrames open but nothing is painted.
Anyone know what I can do?
More Info........................
Basically my program contains a title JFrame and 2 game JFrames, I want to be able to call the game JFrames from the title JFrames and go back and forth from the JPanels.
The title JFrame consists of just components such as JLabels and JButtons.
One of the game JFrames consists of JLabels, JTextFields and JButtons, basically the method generates random numbers and an arithmetic operation that the user has to calculate and enter in the program and the program checks if its correct or not.
One of the game JFrames consist of a paint method that paints circles and the user has to click on it and when a circle is clicked on, it is repainted to not show the circle.(a coordinate system is used etc etc)
public static void runGame1(){
          k=20;
          kcolor=2;
          fillcolor();
          checkcolor();
          frame = new Circlepix();
          timeframe = new TimerPanel();
          time1 = System.currentTimeMillis();     
          //Repaints the count down
          while((60-seconds)>0){
               try{
                    Thread.sleep(1000);
               catch(InterruptedException e){
               timeframe.repaint();
               System.out.println("aaa");
          timeframe.dispose();
public void actionPerformed(ActionEvent e) {
               if (e.getActionCommand().equals("Reset Scores"))
                    game1score=0;
                    game2score=0;
               else if(e.getActionCommand().equals("Speed Circles")){
               mainframe.dispose();
               runGame1();
          }

main is running in a different thread (the main thread)
action events are sent via the event dispatch thread, and painting is done on the event dispatch thread.
You should always be calling your runGame1 method from a separate thread of your own, so you don't block the event dispatch thread and painting
http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html
Edited by: bsampieri on Jun 5, 2008 4:50 PM

Similar Messages

  • Stored Procedure Does Not Run Properly When Called From Portlet

    We have a simple Java portlet that calls a PL/SQL stored procedure which we wrote. The stored procedure sends a large number of emails to users in our corporation using the "utl_smtp" package. The stored procedure returns a count of the emails back to the Java portlet when it's finished. This number is displayed in the portlet.
    Our problem:
    The stored procedure functions as expected when run from a PL/SQL block in SQL*Plus, and the Java portlet calls the procedure properly when sending out a smaller number of emails (Less than 200 usually). When we get into a higher number of emails the procedure hangs when called from the portlet, but it STILL functions properly from SQL*Plus. It does not return the number of emails sent
    and the Java portlet is unable to return a SQLException. Also, we have noticed that emails are sent at a much slower pace from the stored procedure when it's called from the portlet.

    Any Ideas?

  • Subvi does not work properly when called inside a vi

    Hello Every body
    thanks for your help. i am using a sub vi for sine signal generation. as a vi it works fine. but when i called this subvi inside another VI it gives some problems. for example timer indicator works properly.it reinitializes as well in the sub vi, but in the main VI it does not work properly. means does not count the time.in the sub vi on the fly i can change the values of frequency and amplitude in real time, but when i use as sub vi, it does not reponse as i change the values in the control arrays.similarly pause and continue works properly in the sub vi, but once again in the main VI, it does not work properly.graph indicator also work properly in the sub vi. but here once again it does not work properly in the main VI.the pause resume indicator also does not blink, when it is continue. in the subvi it blinks very well.generally why the sub vi does not work properly inside the VI?i am sending my VI and sub vis.
    any tips would be highly appreciated.
    thanks
    Regards
    Attachments:
    vi.zip ‏87 KB

    I just want to add some more details to Dan's answer. The subVI is acting exactly like you've coded it. The mistake is in understanding how subVIs work. When you call a subVI (or a function in any other language), you pass some parameters to it, the subVI does it's thing and returns values. the subVI does not accept new parameters from the calling VI until it returns to the caller and the caller runs the subVI again. In your case, you have a subVI with a while loop. You have some front panel control wired to the subVI's stop terminal. When first called, the value is false. So the subVI will keep running until the subVI's stop button becomes true but you cannot change it from main until the subVI finishes and returns so the subVI will never stop. As Dan says, the solution is pass references of front panel controls to the subVI and have the subVI monitor those references for changes and to update references to indicators on Main. You subVI does not need any front panel controls or indicators of it's own.

  • Insert SQL does not work properly when called using CALL

    I have a stored procedure (TEST_SP) which is used to insert a record in this perticular case. The SQL statement is 2526 characters long. I'm using
    dim Params : Params=chr(1) & "Insert query" & Chr(1) & "=300"
    runsql=&"{call TEST_SP(?,?)}"&Params 
    dim db : db=dbSelect("",0,"","")
    dbExecSQL db,runsqlto execute the stored procedure. I'm facing an issue when the 2000th character on the insert SQL (pUPDSQL) is a single quote, where the SQL is not getting executed (i.e. record is not getting created).
    The same stored procedure and the same SQL when run as below
    runsql=runsql&"DECLARE "
    runsql=runsql&"PUPDSQL VARCHAR2(4000); "
    runsql=runsql&"PRES VARCHAR2(300); "
    runsql=runsql&"BEGIN "
    runsql=runsql&"PUPDSQL := 'INSERT query..."
    runsql=runsql&"PRES:=300; "
    runsql=runsql&"MRT_LKIDFULUP(PUPDSQL => PUPDSQL,PRES => PRES); "
    runsql=runsql&"END; "
    dim db : db=dbSelect("",0,"","")
    dbExecSQL db,runsqlis working fine. Does anyone know if there is a limitaion in ODBC Call function or any explanation to above behaviour? I'm connecting to a Oracle 11g database using Microsoft ODBC for Oracle driver on Window 7
    The stored procedures:
    create or replace procedure TEST_SP(pUPDSQL IN VARCHAR2,pRES OUT VARCHAR2)
    AS
    BEGIN
    DECLARE
      emsg VARCHAR2(100);
    BEGIN
    if pUPDSQL<>'-1' then
      emsg:='Cant exec UPDATE';
      EXECUTE IMMEDIATE pUPDSQL;
        if SQL%RowCount=0 then
        pRES:='ERR:No row updated';
        return;
      end if;
    end if;
    pRES:='OK:';
    EXCEPTION
      WHEN OTHERS THEN
       pRES:='ERR:' || emsg;
    END;
    END;Edited by: BluShadow on 11-Dec-2012 15:47
    added {noformat}{noformat} tags for readability.  Please read {message:id=9360002} and learn to do this yourself in future.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    ... I'm facing an issue when the 2000th character on the insert SQL (pUPDSQL) is a single quote, ...Perhaps you need two single quotes? like:
    runsql=runsql&"PUPDSQL := 'INSERT query...Values(..,..,,,''This value in two single quotes'',..,...)' "
    ... I'm connecting to a Oracle 11g database using Microsoft ODBC ...Dump windoze ODBC and better use the Oracle client ODBC.
    :p

  • TS1630 My Iphone 4s reciever is not working properly, when i call someone from my iphone 4s.  can any one help me how to solve this problem?

    My Iphone 4s reciever is not working properly, when i call someone from my iphone 4s.  can any one help me how to solve this problem?

    You might like to define "not working properly".

  • I had photoshop elements 8 installed on my previous computer and it did not work properly when it came to sizing  photos for a website I was adding to.  I now have a new computer which runs windows 7.  Is it worth installing it again on my new computer?

    I had photoshop elements 8 installed on my previous computer and it did not work properly when it came to sizing  photos for a website I was adding to.  I now have a new computer which runs windows 7.  Is it worth installing photoshop elements 8 again on my new computer or will it be a waste of time?

    I have PSEv.8 on my computer running WINDOWS 7. It works perfectly..
    Perhaps you need help with saving files for web use.. Will be pleased to assist you when you get everything set up.

  • Swf is not working properly when upload to server

    I develop 1.swf which is having 3 buttons each one having
    anather .swf to call 2.swf, 3.swf respectively.
    This application is running perfectly on my PC, but
    While uploading the swf to server the 2.swf and 3.swf is
    not running. Can any one tell how to recover from this kind
    of problem.

    justbipin wrote:
    > basically my code working perfectly,
    > but its not working properly when upload to server
    > can anybody having any ref. or link to solve this
    issues.
    why is that we insist on seeing the source file ?
    There is no one way of doing things in flash and no one can
    help
    you based on "does not work description".
    This is way to broad of a subject to even try to guess.
    Same as asking "my car does not work, what's up with
    that"....
    Please upload the problematic file and provide url for us to
    check.
    Otherwise you need to try to troubleshoot it yourself as we
    can't
    guess from here what possibly is wrong with that file.
    Regards
    Urami
    Happy New Year guys - all the best there is in the 2006 :)
    <urami>
    http://www.Flashfugitive.com
    </urami>
    <web junk free>
    http://www.firefox.com
    </web junk free>

  • Application does not work properly when I press a CommanButton

    Hi all, I am having a problem with weblogic 10.3.5.
    It turns out that an application built with JDeveloper 11.1.5, I test it, and everything goes well in the JDeveloper integrated Weblogic.
    But when deploy in a standalone weblogic 10.3.5 server, the application does not work properly when I press a CommanButton to go to another page search (the property "action" is set correctly) , but nothing happens, stays in the same home page. Similarly when a commanButton link to run a task-flow, It do not work , however in the JDeveloper integrated Weblogic it runs correctly.
    How I can solve these problems?
    Thanks.

    Thanks Frank for help us, but when I writing this comment we are doing at home. So, we going to test the page in a stand alone weblogic server 10.3.5. We wrote the URL as :
    " http://<our ip>:7001/myApp/faces/index.jspx "
    this application contains a report desing and compiled with iReport 4.5.1 ( last version in the moment ), we can see the report when I press a commanButton without any problem.
    But now, we need try your suggestions in the office, and give you more information about it . Thanks for the moment.
    In the Afternoon we gonna give you more information about it .

  • My Ipod touch does not work properly.When i charge it,it only works for 5 min.n gets discharge.I showed it to the apple store in banglore n the person told me its fine n It is working properly.Bt its not working properly.Can someone help

    My Ipod touch does not work properly.When i charge it,it only works for 5 min.n gets discharge.I showed it to the apple store in banglore n the person told me its fine n It is working properly.Bt its not working properly.Can someone help

    If after you charge it for about three hours and it only last about five minutes the battery is probably dead or there could be another hardware problem.  I would go back to the Apple store and ask them specifically how can it be OK if the fully charged battery only lasts five minutes.

  • Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Hello My ipads Power button is not working properly when I press it once it shows option to turn off instead of locking and some other display problems like it suddenly lockes down or display disappears ...Please help. Thank You

    Thanks for that information!
    I'm sure I will be calling AppleCare, but the problem is, they charge for the phone calls don't they? Because I don't have money to be spending to be on the phone with a support service.
    In other things, it seemed like the only time my MacBook was working was when I had Snow Leopard without the 10.6.8 update download that was supposed to be done to prepare for OS X Lion.
    When I look at the information of my HD it says that I have 10.6.8 but that was the install that it claimed to have failed and caused me to restart resulting in all of the repeated problems.
    Also, because my computer is currently down, and I've lost all files how would that effect the use of my iPhone? Because if it doesn't get fixed by the time OS 5 is released, how would I be able to upgrade?!

  • Why do the youtube clips not expand properly when I double click on the page

    why do the youtube clips not expand properly when I double click on the page

    The exclamation mark is telling you that iPhoto has broken the file path/link to the original file. Assuming you're using iPhoto 9 or later Apply the two fixes below in order as needed:
    Fix #1
    1 - launch iPhoto with the Command+Option keys held down and rebuild the library.
    2 - run Option #4 to rebuild the database.
    Fix #2
    Using iPhoto Library Manager  to Rebuild Your iPhoto Library
    1 - download iPhoto Library Manager and launch.
    2 - click on the Add Library button and select the library you want to add in the selection window..
    3 - Now that the library is listed in the left hand pane of iPLM, click on your library and go to the Library ➙ Rebuild Library menu option.
    4 - In the next  window name the new library and select the location you want it to be placed.
    5 - Click on the Create button.
    Note: This creates a new library based on the LIbraryData.xml file in the library and will recover Events, Albums, keywords, titles and comments but not books, calendars or slideshows. The original library will be left untouched for further attempts at fixing the problem or in case the rebuilt library is not satisfactory.
    OT

  • Background of Virtual keyboard in iOS8 for iPad not display properly when pop up in Column mode.

    Background of Virtual keyboard in iOS8 for iPad not display properly when pop up in Column mode.
    Device:iPad 4
    OS:iOS8.0
    Repro Steps:
    1.Navigate to any page that virtual keyboard will be used.
    2.Use your finger slide on virtual keyboard to make it in Column mode.
    3. Hide the virtual keyboard in Column mode.
    4.Tap on any field to use the keyboard again.
    Actually result:
    Background of Virtual keyboard not display properly when pop up in Column mode.(It's fine in iOS7)
    Please refer to the image:

    Are you running the latest Adobe Reader Version i.e. 11.0.1? Can you please share the file where you are encountering this issue to [email protected]?

  • Captivate project not running properly on iPad

    Hello,
    I built a project using Captivate 7.0.  When I published the project, I checked both the SWF and HTML5 boxes so the tutorial would run on an iPad.  However, when I view the tutorial on the iPad, the tutorial does not run properly.  The pages do not advance (even though, in Captivate, I have the slides advancing automatically - not on mouse clicks), all of the bullets on a slide do not appear, and the narration stops in the middle of a slide and does not resume.
    Do you have any suggestions?
    Thank you,
    Sarah

    Hi Joel,
    I removed all bullet animations and re-published the project (I checked the "Force re-publish all the slides").  My tutorial runs on an iPad, without the slides hanging up.  It appears removing the bullet annimations solved that issue.  Thanks for the suggestion.
    However, neither my music introduction on the first slide nor my narration on subsequent slides comes in.  I confirmed I do not have "mute" on and that my volume is up.  Also, I confirmed the sound works by running the tutorial on my desktop. 
    Do you have any ideas?
    Thanks,
    Sarah

  • Jar file not starting properly when in dir with name 2 or more words

    Hello,
    I have a pretty weird problem here. When I start my jar file from a directory like Test/MyJar.jar everything is fine. But if I try to start it from Test 1/MyJar.jar the file is not running properly. The jar file reads files from it's directory and the message I receive is can't find Test20%1/MyFile.txt.
    Any help will be appreciated.

    Anyway. Probably the easiest thing is to not read from the directory. Rather, put the files you need to read into the Jar file itself, and read them using Class.getResourceAsStream.
    This is a workaround, but it's a good one.

  • I defined custom action but it is not running properly.

    Hi,
    I defined custom action but it is not running properly.
    I deployed in MII (System Management --> Custom Actions)
    When i use it as an action in a transaction error below generated.
    Errors
    [ERROR]: STEP EXCEPTION (Custom_Action_0) : Item 'Custom_Action_0' is not an Action
    [ERROR]: STEP EXCEPTION (Custom_Action_0) : Item 'Custom_Action_0' is not an Action
    Custom action code is below.
    package com.wipro.action;
    import com.sap.xmii.xacute.actions.ActionReflectionBase;
    import com.sap.xmii.xacute.core.ILog;
    import com.sap.xmii.xacute.core.Transaction;
    @author cemil.bozlagan
    public class CustomAction extends ActionReflectionBase {
        private String strFirstInput;
        private String strSecondInput;
        private String strOutString;
        public CustomAction() {
            strFirstInput = "";
            strSecondInput = "";
            strOutString = "";
        @Override
        public String GetIconPath() {
            return "/com/wipro/action/resources/icons/CustomAction.png";
        @Override
        public void Invoke(Transaction trx, ILog ilog) {
            try {
                strOutString = strFirstInput + strSecondInput;
                // This varaible is defined in ActionReflectionBase class
                _success = true;
            } catch (Exception e) {
                _success = false;
        public String getFirstInput() {
            return strFirstInput;
        public void setFirstInput(String strFirstInput) {
            this.strFirstInput = strFirstInput;
        public String getSecondInput() {
            return strSecondInput;
        public void setSecondInput(String strSecondInput) {
            this.strSecondInput = strSecondInput;
        public String getOutString() {
            return strOutString;
        @Override
        public boolean isConfigurable() {
            return false;
    How can i solve this problem?
    Thanks.

    Hi Cemil,
    Pls check document, I hv sent to your mail.
    May be it helps.
    Regards
    Padma

Maybe you are looking for