How do I access objects from the original Thread?

I have this simple JApplet that just makes a circle bounce around the screen. Here it is:
import java.awt.Color;
import javax.swing.JApplet;
import java.awt.Graphics;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
public class TestApplet3 extends JApplet implements MouseListener {
    private int lastX;          // x coordinate of circle
    private int lastY;          // y coordinate of circle
    private int d = 15;          // diameter of circle
    public void paint(Graphics g) {
    public void init() {
        addMouseListener(this);
    public void mouseClicked(MouseEvent event) {
        Graphics gx = this.getGraphics();
        for (int x = 0, y = 0, count = 0, horiz = 2, vert = 2, k = 2; count < 1000; x = x + horiz, y = y + vert, count++) {
            if ((x + d) >= 350) {
                horiz = -horiz;
            if ((x <= 0) && (horiz < 0)) {
                horiz = -horiz;
            if ((y + d) >= 200) {
                vert = -vert;
            if ((y <= 0) && (vert < 0)) {
                vert = -vert;
            gx.setColor(Color.WHITE);
            gx.fillOval(lastX, lastY, d, d);
            gx.setColor(Color.RED);
            lastX = x;
            lastY = y;
            gx.fillOval(lastX, lastY, d, d);
            try {
                Thread.sleep(20);
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
    public void mouseEntered(MouseEvent event) {
    public void mouseExited(MouseEvent event) {
    public void mousePressed(MouseEvent event) {
    public void mouseReleased(MouseEvent event) {
}But now I'd like to change it so that when the mouse is clicked a new Thread is spawned to run the code within the mouseClicked method..... this will allow multiple circles to bounce around and will also keep the applet responsive to new mouse clicks... so I've tried changing it below:
* To change this template, choose Tools | Templates
* and open the template in the editor.
package runninggraph;
* @author epuknol
import java.awt.Color;
import javax.swing.JApplet;
import java.awt.Graphics;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
public class TestApplet3 extends JApplet implements MouseListener, Runnable {
    private int lastX;          // x coordinate of circle
    private int lastY;          // y coordinate of circle
    private int d = 15;          // diameter of circle
    public void paint(Graphics g) {
    public void init() {
        addMouseListener(this);
    public void run() {
        Graphics gx = this.getGraphics();
        for (int x = 0, y = 0, count = 0, horiz = 2, vert = 2, k = 2; count < 1000; x = x + horiz, y = y + vert, count++) {
            if ((x + d) >= 350) {
                horiz = -horiz;
            if ((x <= 0) && (horiz < 0)) {
                horiz = -horiz;
            if ((y + d) >= 200) {
                vert = -vert;
            if ((y <= 0) && (vert < 0)) {
                vert = -vert;
            gx.setColor(Color.WHITE);
            gx.fillOval(lastX, lastY, d, d);
            gx.setColor(Color.RED);
            lastX = x;
            lastY = y;
            gx.fillOval(lastX, lastY, d, d);
            try {
                Thread.sleep(20);
            } catch (Exception ex) {
                System.out.println(ex.getMessage());
    public void mouseClicked(MouseEvent event) {
        (new Thread(new TestApplet())).start();       
    public void mouseEntered(MouseEvent event) {
    public void mouseExited(MouseEvent event) {
    public void mousePressed(MouseEvent event) {
    public void mouseReleased(MouseEvent event) {
}but this doesn't work - I think because the this.getGraphics() doesn't refer back to the same object ..... I've tried some other things too - like defining the Graphics gx as a class variable and initializing it before spawning the new Thread ... but I can't access gx using that technique either.
Can somebody please help me get where I'm trying to go?
Thanks.

Aw heck, got bored. For instance, this draws a bunch of balls without a direct call to Thread anything:
BouncingCircles.java
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JPanel;
import javax.swing.Timer;
* creates a JPanel that draws bouncing circles within it. 
* @author Pete
public class BouncingCircles {
  private static final int DELAY = 15;
  private static final int DIAMETER = 15;
  private static final int DELTA = 5;
  List<Ball> ballList = new ArrayList<Ball>(); // list of all balls
  private JPanel mainPanel = new JPanel() {
    @Override
    protected void paintComponent(Graphics g) {
      super.paintComponent(g);
      myPaint(g);
  // Swing Timer that tells the balls to move and tells the JPanel to then draw them
  private Timer sTimer = new Timer(DELAY, new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      timerAction(e);
  public BouncingCircles() {
    mainPanel.setPreferredSize(new Dimension(400, 400));
    mainPanel.addMouseListener(new MouseAdapter() {
      @Override
      // add new ball with each mouse press
      public void mousePressed(MouseEvent e) {
        ballList.add(new Ball(e.getPoint(), new Point(DELTA, DELTA)));
    sTimer.start();
  public JPanel getPanel() {
    return mainPanel;
  private void timerAction(ActionEvent e) {
    Dimension d = mainPanel.getSize();
    for (Ball ball : ballList) {
      if (ball.getPoint().x < 0) {
        ball.setXDirectionRight(true);
      } else if (ball.getPoint().x + DIAMETER > d.width) {
        ball.setXDirectionRight(false);
      if (ball.getPoint().y < 0) {
        ball.setYDirectionDown(true);
      } else if (ball.getPoint().y + DIAMETER > d.height) {
        ball.setYDirectionDown(false);
      ball.increment();
    mainPanel.repaint();
   * paintComponent method draws all balls in List
   * @param g
  private void myPaint(Graphics g) {
    g.setColor(Color.red);
    Graphics2D g2d = (Graphics2D) g;
    RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING,
        RenderingHints.VALUE_ANTIALIAS_ON);
    g2d.setRenderingHints(rh);
    for (Ball ball : ballList) {
      g.fillOval(ball.getPoint().x, ball.getPoint().y, DIAMETER, DIAMETER);
  private class Ball {
    private Point point = new Point();
    private Point velocity = new Point();
    public Ball(Point point, Point velocity) {
      this.point = point;
      this.velocity = velocity;
    public Point getPoint() {
      return point;
    public Point getVelocity() {
      return velocity;
    public void increment() {
      point = new Point(point.x + velocity.x, point.y + velocity.y);
    public void setXDirectionRight(boolean right) {
      int newVelocityX = Math.abs(velocity.x);
      if (!right) {
        newVelocityX = -newVelocityX;
      velocity = new Point(newVelocityX, velocity.y);
    public void setYDirectionDown(boolean down) {
      int newVelocityY = Math.abs(velocity.y);
      if (!down) {
        newVelocityY = -newVelocityY;
      velocity = new Point(velocity.x, newVelocityY);
}And this displays the JPanel produced above in a standard JApplet.
BouncingCircApplet.java
import java.lang.reflect.InvocationTargetException;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;
public class BouncingCircApplet extends JApplet {
  @Override
  public void init() {
    try {
      SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
          getContentPane().add(new BouncingCircles().getPanel());
    } catch (InterruptedException e) {
      e.printStackTrace();
    } catch (InvocationTargetException e) {
      e.printStackTrace();
}

Similar Messages

  • How to remove unused objects from the webcatalog In OBIEE11g

    Hi,
    I want to delete unused objects from obiee11g catalog, i know in obiee10g it's working fine (i.e: we can do it via manage catalog then delete the unused objects) is there any way to do it automatically like RPD utility --->removing unused objects from Physical layer in RPD
    fyi: I don't want to delete manualy. i need somethink like button/link to find unused objects(report,filter,folder..etc) from my obiee11g catalog.
    Thanks
    Deva
    Edited by: Devarasu on Nov 29, 2011 12:06 PM
    Edited by: Devarasu on Nov 29, 2011 3:15 PM

    Hi,
    Checked with Oracle Support team and confirmed below points
    --> incorporated into the Current product and consider as BUG it may resolve future release
    --> Currently there isnt any automatic method to remove the unused objects like reports, filters,folder etc from catalog.
    Treated as Bug
    Bug 13440888 - AUTOMATICALLY REMOVE OF UNUSED CATALOG OBJECTS FROM WEBCATALOG
    FYI:
    SR 3-4984291131: How to remove unused objects from the webcatalog in obiee11g
    Thanks
    Deva

  • Trying to split large library, I exported a folder of 3000 images to a new library.  The new library was created with these images, but it still remained in the original library.  How can I remove it from the original library while keeping it in the new l

    Splitting a library does not remove the folder I moved from the original library.  I exported a folder of 3000 images from the original library to a new library.  The new libraryb was created alright, but the folder and the 3000 images remain in the original library.  Why? And how do I safely remove them?

    The new libraryb was created alright, but the folder and the 3000 images remain in the original library.  Why? And how do I safely remove them?
    Exporting a library will  create a duplicate of the exported library items. Usually you do this to work on a partial library on another computer and later merge the changed images back. Splitting the library is not the primary purpose of exporting.
    If you want to remove the library items that you exported, select them in the source list of the library inspector and delete them (File > Delete Original Images and all Versions).  Then empty the Aperture Trash, after checking that you did not trash more than you wanted.
    But check, if the backup of your Aperture library is in working condition, and check the exported library carefully, before you do such a massive delete.
    Regards
    Léonie

  • HT204053 how do i access music from the cloud for download into my iTunes?

    How do I get to my music once it's in the cloud and how to I download it to my itunes on all devices from the cloud?

    Use one of the following services.
    iTunes Match
    iTunes in the Cloud

  • HT1750 How to remove an object from the DVD slot

    I accidentally inserted an SD card into the DVD slot.  Can someone tell me how to safely remove the SD card?Quest

    The solution here also can work for a SD, just flip the Mac over to get the SD to "land" on the card stock.
    https://discussions.apple.com/docs/DOC-3112

  • How to send an object from one application to another?

    Hi all,
    I have two applications over the same server. The first application needs to send an object to the other application.
    I try to put the object as a session attribute, but in the moment that the second application tries to get the attribute, the attribute doesn't exist.
    Does anybody now how can pass an object from the one application to the other?

    You can also use JMS

  • How to access objects in the Child Form from Parent form.

    I have a requirement in which I have to first open a Child Form from a Parent Form. Then I want to access objects in the Child Form from Parent form. For example, I want to insert a record into a block present in Child Form by executing statements from a trigger present in Parent Form.
    I cannot use object groups since I cannot write code into Child Form to first create object groups into Child Form.
    I have tried to achieved it using the following (working of my testcase) :
    1) Created two new Forms TESTFORM1.fmb (parent) and TESTFORM2.fmb (child).
    2) Created a block named BLK1 manually in TESTFORM1.
    3) Created two items in BLK1:
    1.PJC1 which is a text item.
    2.OPEN which is a push button.
    4) Created a new block using data block wizard for a table EMPLOYEE_S1. Created items corresponding to all columns present in EMPLOYEE_S1 table.
    5) In WHEN-NEW-FORM-INSTANCE trigger of TESTFORM1 set the first navigation block to BLK1. In BLK1 first navigable item is PJC1.
    6) In WHEN-NEW-ITEM-INSTANCE of PJC1, code has been written to automatically execute the WHEN-BUTTON-PRESSED trigger for the "Open" button.
    7) In WHEN-BUTTON-PRESSED trigger of OPEN item, TESTFORM2 is opened using the following statement :
    open_form(‘TESTFORM2',no_activate,no_session,SHARE_LIBRARY_DATA);
    Since its NO_ACTIVATE, the code flows without giving handle to TESTFORM2.
    8) After invoking OPEN_FORM, a GO_FORM(‘TESTFORM2’) is now called to set the focus to TESTFORM2
    PROBLEM AT HAND
    ===============
    After Step 8, I notice that it passes the focus to TESTFORM2, and statements after go_form (in Parent Form trigger) doesnot executes.
    I need go_form with no_activate, similar to open_form.
    Edited by: harishgupt on Oct 12, 2008 11:32 PM

    isn't it easier to find a solution without a second form? If you have a second window, then you can navigate and code whatever you want.
    If you must use a second form, then you can handle this with WHEN-WINDOW-ACTIVATED and meta-data, which you have to store in global variables... ( I can give you hints if the one-form-solution is no option for you )

  • HT204053 I have one apple ID that my entire family has been using.  How do I create new apple ID's for each of us and move the appropriate content to each new ID from the original apple ID now that we all have our own devices?

    I have been using one apple ID for 4 family members.  Up until now it hasn't been a problem but now that we all have our own devices how do I create new apple ID's for each of us and them move the approprioate things from the original apple ID account to the new ones for each of us?

    stuartx4 wrote:
    Thanks Csound1, wish I have seperated everything from the beginning but when your kids are little and start buying music etc it just didn't seem like an issue.
    That has a familiar ring to it

  • When I share a pages document as a PDF (via e-mail) all the pictures change from the original document, most are missing with just a few of them repeated in the spots where others had been.  How do I do this without the document changing?

    When I share a pages document as a PDF (via e-mail) all the pictures change from the original document, most are missing with just a few of them repeated in the spots where others had been.  How do I do this without the document changing?
    I need to be able to send it to a PC in order to print it.

    Hard to say what is happening without examining the file.
    If you like click on my blue name and email me both the .pages file and the the .pdf you have made from it.
    Peter
    ps It would help to say what version of Pages you are using and on what you are running it. iOS or Mac and what version.

  • I recently bought, from the original website of Adobe, Photoshop elements 13. However, when I go with my mouse pointer over the menu, It hangs or he works very slow. Does anyone have an idea how I can fix it? I have already downloaded updates, both from A

    I recently bought, from the original website of Adobe, Photoshop elements 13. However, when I go with my mouse pointer over the menu, It hangs or he works very slow. Does anyone have an idea how I can fix it? I have already downloaded updates, both from Adobe and Windows. I have a new pc with window 8.1.

    It could be a coincidence, but I rebooted the machine and (knock on wood) PSE13 seems to be working ok.

  • How can I access files from a flash drive that were previously saved using a Windows computer? When I attempt to open the file on MacBook Pro, it is asking to "convert file to"; I also have Microsoft Word installed on the Mac as well.

    How can I access files from a flash drive that were previously saved using a Windows computer? When I attempt to open the file on MacBook Pro, it is asking to "convert file to"; none of the options I choose work. I also have Microsoft Office (with Word) installed on the Mac as well.

    Format the external drive as FAT32 or ExFAT. Both computers will then be able to read and write to it.

  • I have playlists on my original iPod but are not in the library.  How can I move them from the iPod to the library?

    I have playlists on my original iPod but are not in the library.  How can I move them from the iPod to the library?

    She can choose to either enable the setting on her iPod to Manually manage music and videos.  With setting enabled she can sync content to her iPod from multiple computers without it affecting whats already stored her iPod. For more information on syncing content to an iPod manually see this article. 
    http://support.apple.com/kb/ht1535
    However, I would recommend copying whats on her iPod to her iTunes library first.  There are several ways to accomplish this.  See this older post from another forum member Zevoneer discussing the different ways to do it.
    https://discussions.apple.com/thread/2452022?start=0&tstart=0
    B-rock

  • How do I output the smoothest video when changing or mixing frame rates from the original footage?

    I have been experimenting with various Media Encoder settings, and wondered if there was anything else I can try to get the smoothest video output possible, especially when changing frame rate and possibly resolution.  For clarification, let me start from the beginning and explain what I'm doing and what I've tried so far.  I'll try to be as brief as possible, but if I do go into too much detail, I apologize. 
    My original footage is AVCHD 1080p - 60fps.  (my camera only does 60fps...specifically 59.94fps)  We're not talking interlaced video here, I'm staying away from that.  This is definitely full frame, progressive video at 60 frames (not fields) per second.  My output will ultimately be for the web.  I have been keeping my output codec (H.264) and bit-rate (VBR 2-pass, relatively high-bitrate) consistent, and have been trying numerous output options and even sequence settings to see what would yield the best results.  I am using Premiere Pro CS5.5 along with Media Encoder.  Here's what I've done and the results I've observed:
    1.  I created a sequence with 1080p - 59.94fps settings to match my original footage.  I then output both 1080p and 720p versions at 59.94fps, and at 29.97fps.  The 59.94fps output files looked absolutely great, as would be expected.  Extremely smooth.  The 29.97fps output files were generally smooth, but not near as smooth as the 59.94fps.  This is expected since it's half the frame rate as my original footage.  However, my question is this:  What exactly is Media Encoder doing when "down converting" from 60p to 30p?  From a technical stand point, is it dropping every other frame?  I'm just curious to understand exactly what it does.  I tried the Frame Blending option as well, and that only yielded a bit more blur to the images which wasn't desirable for any of the output files. 
    2.  Just to see what would happen, I created a sequence with 1080p - 29.97 settings.  I then output both 1080p and 720p versions at 29.97fps.  The video was much more choppy in these cases, even with Frame Blending on.  Now, I know not matching my sequence settings with my original media isn't ideal, but I again just want to understand why this yields less smooth video than the 29.97fps options above.  Why does cutting the sequence settings frame rate in half from the original, then outputting the same frame rate as the sequence yield video that is not as smooth?
    3.  Next, I wanted to try mixing frame rates to see how Premiere and Media Encoder handled the footage and output files.  Premiere handled it great, no issues there.  However, I had some interesting things happen when I output the files.  Here's what I did:  I created a sequence with 1080p - 59.94fps to match my original footage.  Then I took the same exact footage that was in my sequence, copied it in my project panel and interpreted it at both 23.976 and 29.97 fps, yielding slow motion video.  The slow motion video looked great in Premiere, so I went ahead and just added it to my sequences, along with the original 59.94 footage.  I also created separate sequences for the 29.97 and 23.976 footage respectively, each with matching sequence settings, then added a nested sequence to another original footage sequence (with 59.94fps sequence settings) to see which yielded the best results.  Basically, I'm trying to output 59.94fps that match my original footage, but also throw in some slow motion footage at different framerates.  I'll explain my results in a moment as they are a bit convoluted, however, here is my question:  When mixing frame rates and trying to output the smoothest video, am I going about this the right way?  I would assume you would use your sequence settings that match the original footage (which is what the majority of the footage will be), then bring in a nested sequence for the slow motion (as oppose to just dropping the slow motion video directly into my main sequence), and then output to the same frame rate of the majority of the footage, in this case 59.94fps. Is there a better workflow for this?
    The results to #3 above were as follows.  Initially, it looked like it didn't matter if I nested the slow motion sequence into my main sequence, or simply dropped the actual slow motion video into my original 59.94fps sequence.  It seemed to produce smooth results either way.  Frame Blending blurred the video a bit, but didn't seem to make much difference, and quite honestly I like the footage without Frame Blending in general.  However, when I closed down Premiere, and opened the output files later (opening in Quicktime), the footage looked choppy.  In fact, it would go from choppy to smooth and back, almost like it had an irregular cadence (don't know if I'm using "cadence" in the right context here).  I would then open up Premiere again, import the output footage into my project panel, and play the footage in Premiere, and it would play back smooth again. Is this a Quicktime issue?  I was playing 1080p 59.94fps files when this happened, so maybe it's just because it's a large file.  Doesn't seem to have issues with the 720p files I created.  But it sure threw me off with my testing because I then started second guessing the settings I was using.  My iMac is the latest 2011 model with plenty of RAM, so I wouldn't think it's the computer.  Thoughts?
    4.  Next, I noticed on ALL my output files (again, using the H.264 codec from Media Encoder) that the color of my video seemed to flatten quite a bit.  It seems that the original footage has more contrast and saturation than the output files.  I figured maybe this was just how it was, but when I re-imported the output files back into Premiere, they looked IDENTICAL to the original footage.  And in Media Encoder's Source/Output windows, I don't see any difference there either. Is Quicktime again the culprit here, doing some odd things to the color of my videos?
    5.  Regarding Frame Blending, when is the best situation to enable this option in Media Encoder?  I've read it is when mixing frame rates, but I honestly didn't see too much of a change except for a bit more blur, which I didn't care for.
    6.  Lastly, my conclusion is that 60fps yields the smoothest video, which is an obvious conclusion.  However, I know that 60fps isn't the best or easiet frame rate for web delivery.  It seems 30p is more the standard.  Are there any integrated web players that would play 60fps?  Can you get 60fps video on YouTube/Vimeo?  If yes to any of these questions, can they do 720p and 1080p at 60fps? 
    Those are all my questions.  I hope I am clear enough without being overly wordy and hopefully I didn't put too many questions into one post.  Thanks in advance for any insight, I really appreciate it.

    Did you ever figure out which output worked the best? I have the same original footage; trying to determine the best output settings to make a dvd for tv.
    thanks!

  • How do i add songs to my ipod from another computer without losing the music i already have on it from the original computer?

    i want to connect my ipod to a friends computer to get some of her songs on my ipod. every time i do this tho it deletes the songs i already had on my ipod from the original computer. how do i get this to work? please help

    When you connect the ipod and are prompted to erase and sync....just click cancel.  Then click the ipod name below devices in the itunes source pane.  From the ipod summary screen you want to check manually manage music and videos under the options tab.  Apply the changes and you are now set to manually sync.  Which means you just drag and drop the music you want to sync to your ipod below devices in the itunes source pane.   Refer to this for more detailed instructions:  http://support.apple.com/kb/HT1535

  • How can I turn off the sound from the original midi  or audio tracks when I turned on the duplicate tracks for editing ?

    How can I turn off the sound from the original midi or audio tracks when I edit or listen to the duplicate tracks in Logic Pro 9 ?
    I'm using iMac desktop with Mac OS X Version 10.7.3. Pls advise.

    Dan,
    It sounds like one of your preferences has changed.
    Go to preferences > audio > general, and make sure "track mute/solo" is set to "CPU saving (slow response)". It is probably set to "Fast " at the moment.
    This setting (fast) basically causes immediate muting from the channel strip while your song is in play. This is because the audio is still being read from the hard drive, but the channel strip is simply muted.... like a hardware mixer. When set to "CPU saving", the audio from that track, when muted, is actually stopped from streaming from the hard drive, but there is a couple second delay before the audio is actually muted.
    One would think that the fast setting is generally preferable, except when you need to do what you are doing. The only way to keep duplicate copies of channel strips acting independent of one another is to leave this setting on the "CPU saving" setting.
    Hope that helps

Maybe you are looking for

  • Not able to Register-ObjectEvent for System.Diagnostics.Eventlog "EntryWritten" Event

    Hi, I'm trying to listen for an entry in an EventLog created.  New-EventLog -LogName TestLog -Source "MyScript" # This is my eventlog # And for monitoring, the code goes like this: $testlogs = Get-EventLog -LogName TestLog Register-ObjectEvent -INput

  • How can i change back to os after using bootcamp

    Hi, Im the proud owner of a early 2008 mac, I installed windows 7 on my mac using bootcamp. I wanted to clean up my mac by resetting it, there was nothing I really wanted to keep so thats why I wanted to reset. I went to the setting screen you know t

  • HOW TO edit original message text in a Reply email

    Hello All!  We have an Application over several countries in which our Field Technicians must answer emails (reply) informing field ocurrences in order to update our central database in a (quite) "real-time" basis. The problem is that, to do it, they

  • Product relationships data to find partner & warranty category

    HI experts, i have a product created in commpr01 as type material , for this product in relationships warranty category & vendors are assigned Can any one let me know if there is a FM or table to find for a product a warranty or vendor is assgined wh

  • ERROR iTMS-9000, is it always an intermittent apple outage

    I read a previous question about itms_ error, the correct answer from Neil was that that Apple has intermittent outages on the application loader, and to try again later. My reason for the failure is different than the previous questioner, in my case