# Java/Netbeans Assistance Desired (Not Homework)

**URL:** <https://boards.straightdope.com/t/java-netbeans-assistance-desired-not-homework/276256>\
**Category:** Factual Questions\
**Created:** [November 23, 2004, 10:16am UTC](https://boards.straightdope.com/t/java-netbeans-assistance-desired-not-homework/276256 "2004-11-23T10:16:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Netbrian](https://avatars.discourse-cdn.com/v4/letter/n/71e660/32.png) [@Netbrian](https://boards.straightdope.com/u/Netbrian)\
**Post date:** [November 23, 2004, 10:16am UTC](https://boards.straightdope.com/t/java-netbeans-assistance-desired-not-homework/276256/1 "2004-11-23T10:16:08Z")

</div>

For my Introduction to Programming class, we’ve been studying Java through the Netbeans 3.6 (I know there is a more recent version available, but it was released after the class began, and the instructors wanted to use a consistent version. So we’re also using Java 1.4.6). This particular assignment was to use threading to make a ball bounce. Thus, I created an applet with one thread being the GUI part, that decides when to repaint it, and a class for the ball, which dictates when and where the ball moves.

All my code seems to work properly. Each thread is doing exactly what I told it to, and through console output, you can see the position of the ball moving more or less how I told it to (there are some minor possible glitches with the upper and lower limits that I haven’t quite worked out, but they should be comparitively trivial. Likewise, a better model of gravity should also be fairly easy to add once I finish this).

Unfortunately, when I actually run my applet, either in Netbeans or on a web page, nothing whatsoever gets painted. I’m using java.awt.Graphics, and have done so in the past, so I’m somewhat familiar with it. Moreover, I know the “paint” part of my applet itself is being ran, it just won’t run the parts that actually draw anything.

You can find my code at www.willamette.edu/~btrautma/BallBouncer.zip . Be careful regarding stability, as it’s running two active threads the entire time, which could slow down some computers. If anyone can help me, please do so! Note that my instructor looked at my code and program at length, and could not figure out what was going on. Note also that if I use the built in “repaint()” method rather than calling paint() directly, it never actually runs the method at all, which is further compounding my immense confusion.

Please help!

Netbrian

---

<div class="post-metadata">

**Author:** ![ticker](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@ticker](https://boards.straightdope.com/u/ticker)\
**Post date:** [November 23, 2004, 12:19pm UTC](https://boards.straightdope.com/t/java-netbeans-assistance-desired-not-homework/276256/2 "2004-11-23T12:19:09Z")

</div>

I am not sure if it is relevant (I don’t have the time right now to look at your code) but it is worth noting that the AWT and Swing classes are not thread safe. That means that all AWT code must be run from a single event-dispatching thread and you must not make an AWT call, including _paint()_ from another thread. I think you can call _repaint()_ because all it does is arrange for _paint()_ to be called in the event-dispatching thread.

---

<div class="post-metadata">

**Author:** ![ticker](https://avatars.discourse-cdn.com/v4/letter/t/d07c76/32.png) [@ticker](https://boards.straightdope.com/u/ticker)\
**Post date:** [November 23, 2004, 1:30pm UTC](https://boards.straightdope.com/t/java-netbeans-assistance-desired-not-homework/276256/3 "2004-11-23T13:30:23Z")

</div>

Just had a quick look at your code. I think the problem may be the interaction between _paintLoop()_ and the GravityBall thread. You do not want to have your ThreadApplet and GravityBall both call _sleep(…)_. Try removing _paintLoop()_ and having _run()_ in GravityBall call _repaint()_ (not _paint()_) on the ThreadApplet
