Java Bouncing Balls Threads problem?

Hello,
I am working on a homework assignment to represent a java applet with some bouncing balls inside. So far so good. The balls bounce and behave as they are supposed. The only thing is that I want to make 2 buttons, Start and Stop (this is not part of the assignment, but my free will to provide some extra stuff :) ) . I am implementing Runnable for the animation and ActionListener for the buttons. I did research on threading, but somehow I am still not getting quite the result I want. The applet is not displaying my buttons (I guess I am not implementing them correctly) and I dont know whether I have synchronized the threads correctly as well. So, I am asking for some guidance how can I do this? Thanks in advance!
As a remark, I am new to Java, as I am just starting to learn it and this is my first assignment.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JPanel;
public class Balls extends JApplet implements Runnable, ActionListener
     Thread runner = null;     
     Image img;
    Graphics gr;          
    BallCollision ball[];
    Balls can;
    JButton stopButton;
    JButton startButton;
    JPanel controls;
    boolean stop,start;
    //field for 10 balls
    static final int MAX=10;
     public void init()
          setSize(800,600);
          img = createImage(size().width,size().height);
          gr = img.getGraphics();     
          startButton = new JButton("Start");
          stopButton = new JButton("Stop");
          stopButton.addActionListener(this);
          startButton.addActionListener(this);
          controls = new JPanel();
          controls.setLayout(new FlowLayout());
          controls.add(startButton);
          controls.add(stopButton);
          //new Thread(this).start();
          ball = new BallCollision[MAX];
          int w=size().width;
          int h=size().height;          
          //creation of balls, which have different coordinates,
          //speed, direction and colors
          ball[0] = new BallCollision(w,h,50,20,1.5,7.5,Color.orange);
        ball[1] = new BallCollision(w,h,60,210,2.0,-3.0,Color.red);
        ball[2] = new BallCollision(w,h,15,70,-2.0,-2.5,Color.pink);
        ball[3] = new BallCollision(w,h,150,30,-2.7,-1.0,Color.cyan);
        ball[4] = new BallCollision(w,h,210,30,2.2,-12.5,Color.magenta);
          ball[5] = new BallCollision(w,h,360,170,2.2,-1.5,Color.yellow);
          ball[6] = new BallCollision(w,h,210,180,-1.2,-2.5,Color.blue);
          ball[7] = new BallCollision(w,h,330,30,-2.2,-1.8,Color.green);
          ball[8] = new BallCollision(w,h,180,220,-2.2,-1.8,Color.white);
          ball[9] = new BallCollision(w,h,330,130,-2.2,9.0,Color.gray);     
     public void actionPerformed(ActionEvent e)
          if(e.getSource() == startButton) start = true;
               can.start();
          if(e.getSource() == stopButton) start = false;
               can.stop();
     public void start()
          if (runner == null)
               runner = new Thread (this);
               runner.start();
     public void stop()
          if (runner != null)
              runner.stop();
                runner = null;
     public void run()
          while(true)
               try {Thread.sleep(15);}
                 catch (Exception e) { }               
               //move our balls around
               for(int i=0;i<MAX;i++)
                    ball.move();
               handleCollision();
               repaint();     
     boolean collide(BallCollision b1, BallCollision b2)
          double wx=b1.getCenterX()-b2.getCenterX();
          double wy=b1.getCenterY()-b2.getCenterY();
          //the distance between 2 colling balls' centres is
          //calculated by the theorem of Pythagoras
          double distance=Math.sqrt(wx*wx+wy*wy);
          if(distance<b1.diameter)
               return true;          
               return false;     
     private void handleCollision()
          //ecah ball is checked for possible collisions
          for(int i=0;i<MAX;i++)
               for(int j=0;j<MAX;j++)
                         if(i!=j)
                              if(collide(ball[i], ball[j]))
                                   ball[i].hit(ball[j]);
                                   ball[j].hit(ball[i]);
     public void update(Graphics g)
          paint(g);
     public void paint(Graphics g)
          gr.setColor(Color.black);
          gr.fillRect(0,0,size().width,size().height);          
          //paint the balls
          for(int i=0;i<MAX;i++)
                    ball[i].paint(gr);          
          g.drawImage (img,0,0, this);                    
class BallCollision
     int width, height;
     int diameter=30;
     //balls' coordinates and values to be incremented for directions
     double x, y, xIncremented, yIncremented, coll_x, coll_y;
     boolean collide;
     Color color;
     Graphics g;
     //constructor
     public BallCollision(int w, int h, int x, int y, double xInc, double yInc, Color c)
          width=w;
          height=h;
          this.x=x;
          this.y=y;
          this.xIncremented=xInc;
          this.yIncremented=yInc;          
          color=c;          
     public double getCenterX() {return x+diameter/2;}
     public double getCenterY() {return y+diameter/2;}
     public void move()
          if (collide)
               double xvect=coll_x-getCenterX();
               double yvect=coll_y-getCenterY();
               if((xIncremented>0 && xvect>0) || (xIncremented<0 && xvect<0))
                    xIncremented=-xIncremented;
               if((yIncremented>0 && yvect>0) || (yIncremented<0 && yvect<0))
                    yIncremented=-yIncremented;
               collide=false;
          x+=xIncremented;
     y+=yIncremented;
          //if the ball reaches a wall, it bounces to the opposite direction
     if(x<1 || x>width-diameter)
          xIncremented=-xIncremented;
               x+=xIncremented;
          if(y<1 || y>height-diameter)
               yIncremented=-yIncremented;
               y+=yIncremented;
     public void hit(BallCollision b)
          if(!collide)
               coll_x=b.getCenterX();
               coll_y=b.getCenterY();
               collide=true;
     public void paint(Graphics graphics)
          g=graphics;
          g.setColor(color);
          //the coordinates in fillOval have to be int, so we cast
          //explicitly from double to int
          g.fillOval((int)x,(int)y,diameter,diameter);

well i didnt arrive at this point without reading tutorials and researching.... sometimes other people can spot your mistakes a lot easier than you can, that's why I asked for help. 10x anyway for the interest!

Similar Messages

  • Possibility of drawing numbers on java bouncing balls?

    Can anyone show me how to put numbers on these moving balls in my code. I need the numbers 1-60 on them. I have two sets the red and white. Here is my code. Any help is appreciated. I am trying to write a program to represent the powerball.
    import java.awt.*;
    import java.applet.*;
    import java.util.*;
    import javax.swing.*;
    import java.awt.Rectangle;
    class CollideBall{
    int width, height;
    public static final int diameter=20;
    //coordinates and value of increment
    double x, y, xinc, yinc, coll_x, coll_y;
    boolean collide;
    Color color;
    Graphics g;
    Rectangle r;
    //the constructor
    public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c){
    width=w;
    height=h;
    this.x=x;
    this.y=y;
    this.xinc=xinc;
    this.yinc=yinc;
    color=c;
    r=new Rectangle(150,80,130,90);
    public double getCenterX() {return x+diameter/2;}
    public double getCenterY() {return y+diameter/2;}
    public void alterRect(int x, int y, int w, int h){
    r.setLocation(x,y);
    r.setSize(w,h);
    public void move(){
    if (collide){  
    double xvect=coll_x-getCenterX();
    double yvect=coll_y-getCenterY();
    if((xinc>0 && xvect>0) || (xinc<0 && xvect<0))
    xinc=-xinc;
    if((yinc>0 && yvect>0) || (yinc<0 && yvect<0))
    yinc=-yinc;
    collide=false;
    x+=xinc;
    y+=yinc;
    //when the ball bumps against a boundary, it bounces off
    //ball width is 6 so if the ball becomes less then 6 it is touching the frame
    //if ball is greater than the entire width-the diameter of the rectangle, then the ball is just touching the frame of the rectangle and must switch to negative to go in opposit direction
    if(x<6 || x>width-diameter){
    xinc=-xinc;
    x+=xinc;
    //same thing as about just about the Y-axis instead of the x-axis
    if(y<6 || y>height-diameter){
    yinc=-yinc;
    y+=yinc;
    public void hit(CollideBall b){
    if(!collide){
    coll_x=b.getCenterX();
    coll_y=b.getCenterY();
    collide=true;
    public void paint(Graphics gr){
    g=gr;
    g.setColor(color);
    //the coordinates in fillOval have to be int, so we cast
    //explicitly from double to int
    g.fillOval((int)x,(int)y,diameter,diameter);
    //Draws half white and half dark gray arc around the balls to give light and shadow effect
    g.setColor(Color.white);
    g.drawArc((int)x,(int)y,diameter,diameter,45,180);
    g.setColor(Color.darkGray);
    g.drawArc((int)x,(int)y,diameter,diameter,225,180);
    public class BouncingBalls extends Applet implements Runnable { 
    Thread runner;
    Image Buffer;
    Graphics gBuffer;
    CollideBall ball[];
    //Obstacle o;
    //how many balls?
    static final int MAX=60;
    boolean intro=true,drag,shiftW,shiftN,shiftE,shiftS;
    boolean shiftNW,shiftSW,shiftNE,shiftSE;
    int xtemp,ytemp,startx,starty;
    int west, north, east, south;
    public void init() {  
    Buffer=createImage(getSize().width,getSize().height);
    gBuffer=Buffer.getGraphics();
    ball=new CollideBall[MAX];
    int w=getSize().width-5;
    int h=getSize().height-5;
    //our balls have different start coordinates, increment values
    //(speed, direction) and colors
    for (int i = 0;i<30;i++){
    ball=new CollideBall(w,h,48+i,500+i,1.5,2.0,Color.white);
    ball[i+30]=new CollideBall(w,h,890+i,200+i,1.5,2.0,Color.red);
    public void start(){
    if (runner == null) {
    runner = new Thread (this);
    runner.start();
    /* public void stop(){
    if (runner != null) {
    runner.stop();
    runner = null;
    public void run(){
    while(true) {
    Thread.currentThread().setPriority(Thread.MAX_PRIORITY);
    try {runner.sleep(15);}
    catch (Exception e) { }
    //move our balls around
    for(int i=0;i<MAX;i++){
    ball[i].move();
    handleCollision();
    repaint();
    boolean collide(CollideBall b1, CollideBall b2){
    double wx=b1.getCenterX()-b2.getCenterX();
    double wy=b1.getCenterY()-b2.getCenterY();
    //we calculate the distance between the centers two
    //colliding balls (theorem of Pythagoras)
    double distance=Math.sqrt(wx*wx+wy*wy);
    if(distance<b1.diameter)
    return true;
    return false;
    private void handleCollision(){
    //we iterate through all the balls, checking for collision
    for(int i=0;i<MAX;i++)
    for(int j=0;j<MAX;j++){
    if(i!=j){         
    if(collide(ball[i], ball[j])){  
    ball[i].hit(ball[j]);
    ball[j].hit(ball[i]);
    public void update(Graphics g){
    paint(g);
    public void paint(Graphics g) { 
    gBuffer.setColor(Color.lightGray);
    gBuffer.fillRect(0,0,getSize().width,getSize().height);
    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
    //paint our balls
    for(int i=0;i<MAX;i++)
    ball[i].paint(gBuffer);
    g.drawImage (Buffer,0,0, this);
    Thanks again

    this.user wrote:
    JakeG27 post your code within the code tab it will be more clear.
    You can do this by clicking on CODE when you do this will appear { code} { code} post your code inbetween those to tags.
    ie
    { code} code... { code}
    and it will look like this
    code
    This must be the first sensible post you've ever made. At least you're able to copy someone else's response and pretend you know something.

  • Bouncing Ball without Main Method

    Hi. I needed to reserch on the Internet sample code for a blue bouncing ball which I did below. However, I try coding a main class to start the GUI applet and it's not working. How can I create the appropriate class that would contain the main method to start this particular application which the author did not provide? The actual applet works great and matches the objective of my research (http://www.terrence.com/java/ball.html). The DefaultCloseOperation issues an error so that's why is shown as remarks // below. Then the code in the Ball.java class issues some warning about components being deprecated as shown below. Thank you for your comments and suggestions.
    Compiling 2 source files to C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\build\classes
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:32: warning: [deprecation] size() in java.awt.Component has been deprecated
        size = this.size();
    C:\Documents and Settings\Fausto Rivera\My Documents\NetBeansProjects\Rivera_F_IT271_0803B_01_PH3_DB\src\Ball.java:93: warning: [deprecation] mouseDown(java.awt.Event,int,int) in java.awt.Component has been deprecated
      public boolean mouseDown(Event e, int x, int y) {
    2 warnings
    import javax.swing.*;
    public class BallMain {
    * @param args the command line arguments
    public static void main(String[] args) {
    Ball ball = new Ball();
    //ball.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
    ball.setSize( 500, 175 ); // set frame size
    ball.setVisible( true ); // display frame
    import java.awt.*;*
    *import java.applet.*;
    import java.util.Vector;
    // Java Bouncing Ball
    // Terrence Ma
    // Modified from Java Examples in a Nutshell
    public class Ball extends Applet implements Runnable {
    int x = 150, y = 100, r=50; // Position and radius of the circle
    int dx = 8, dy = 5; // Trajectory of circle
    Dimension size; // The size of the applet
    Image buffer; // The off-screen image for double-buffering
    Graphics bufferGraphics; // A Graphics object for the buffer
    Thread animator; // Thread that performs the animation
    boolean please_stop; // A flag asking animation thread to stop
    /** Set up an off-screen Image for double-buffering */
    public void init() {
    size = this.size();
    buffer = this.createImage(size.width, size.height);
    bufferGraphics = buffer.getGraphics();
    /** Draw the circle at its current position, using double-buffering */
    public void paint(Graphics g) {
    // Draw into the off-screen buffer.
    // Note, we could do even better clipping by setting the clip rectangle
    // of bufferGraphics to be the same as that of g.
    // In Java 1.1: bufferGraphics.setClip(g.getClip());
    bufferGraphics.setColor(Color.white);
    bufferGraphics.fillRect(0, 0, size.width, size.height); // clear the buffer
    bufferGraphics.setColor(Color.blue);
    bufferGraphics.fillOval(x-r, y-r, r*2, r*2); // draw the circle
    // Then copy the off-screen buffer onto the screen
    g.drawImage(buffer, 0, 0, this);
    /** Don't clear the screen; just call paint() immediately
    * It is important to override this method like this for double-buffering */
    public void update(Graphics g) { paint(g); }
    /** The body of the animation thread */
    public void run() {
    while(!please_stop) {
    // Bounce the circle if we've hit an edge.
    if ((x - r + dx < 0) || (x + r + dx > size.width)) dx = -dx;
    if ((y - r + dy < 0) || (y + r + dy > size.height)) dy = -dy;
    // Move the circle.
    x += dx; y += dy;
    // Ask the browser to call our paint() method to redraw the circle
    // at its new position. Tell repaint what portion of the applet needs
    // be redrawn: the rectangle containing the old circle and the
    // the rectangle containing the new circle. These two redraw requests
    // will be merged into a single call to paint()
    repaint(x-r-dx, y-r-dy, 2*r, 2*r); // repaint old position of circle
    repaint(x-r, y-r, 2*r, 2*r); // repaint new position of circle
    // Now pause 50 milliseconds before drawing the circle again.
    try { Thread.sleep(50); } catch (InterruptedException e) { ; }
    animator = null;
    /** Start the animation thread */
    public void start() {
    if (animator == null) {
    please_stop = false;
    animator = new Thread(this);
    animator.start();
    /** Stop the animation thread */
    public void stop() { please_stop = true; }
    /** Allow the user to start and stop the animation by clicking */
    public boolean mouseDown(Event e, int x, int y) {
    if (animator != null) please_stop = true; // if running request a stop
    else start(); // otherwise start it.
    return true;
    }

    FRiveraJr wrote:
    I believe that I stated that this not my code and it was code that I researched.and why the hll should this matter at all? If you want help here from volunteers, your code or not, don't you think that you should take the effort to format it properly?

  • Urgent!!!!!!!HANDLER THREAD PROBLEM

    file name GetName.html
    <html>
    <body>
    <FORM METHOD = POST ACTION = "SaveName.jsp">
    what is your name?
    <INPUT TYPE = TEXT NAME=username SIZE= 20>
    <p><INPUT TYPE= SUBMIT>
    </FORM>
    </BODY>
    </HTML>
    file name SaveName.jsp
    <%
    String name = request.getParameter( "username" );
    session.setAttribute( "theName", name );
    %>
    <HTML>
    <BODY>
    Continue
    </BODY>
    </HTML>
    file name NextPage.jsp
    <html>
    <body>
    Hello, <%=session.getAttribute("theName") %>
    </body>
    </html>
    when I try to execute , SaveName.jsp is generating the following error message. what is the problem? I am using jswdk. please help. I have included tools.jar in classpath. what could be the problem?
    Unhandled error! You might want to consider having an error page to report such
    errors more gracefully
    com.sun.jsp.JspException: Compilation failed:Note: sun.tools.javac.Main has been
    deprecated.
    work\%3A8080%2Fexamples\SaveName_jsp_1.java:71: Method setAttribute(java.lang.St
    ring, java.lang.String) not found in interface javax.servlet.http.HttpSession.
    session.setAttribute( "theName", name );
    ^
    1 error, 1 warning
    at com.sun.jsp.compiler.Main.compile(Main.java:347)
    at com.sun.jsp.runtime.JspLoader.loadJSP(JspLoader.java:135)
    at com.sun.jsp.runtime.JspServlet$JspServletWrapper.loadIfNecessary(JspS
    ervlet.java:77)
    at com.sun.jsp.runtime.JspServlet$JspServletWrapper.service(JspServlet.j
    ava:87)
    at com.sun.jsp.runtime.JspServlet.serviceJspFile(JspServlet.java:218)
    at com.sun.jsp.runtime.JspServlet.service(JspServlet.java:294)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
    at com.sun.web.core.ServletWrapper.handleRequest(ServletWrapper.java:155
    at com.sun.web.core.Context.handleRequest(Context.java:414)
    at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:139)
    HANDLER THREAD PROBLEM: java.net.SocketException: Socket is closed
    java.net.SocketException: Socket is closed
    at java.net.Socket.getInputStream(Socket.java:643)
    at com.sun.web.server.ConnectionHandler.run(ConnectionHandler.java:161)

    Are you using JSWDK 1.0.1? If you are, then the implementation uses the Servlet Spec. 2.1. The set/getAttribute methods were added in 2.2.
    Try using the now-deprecated method putValue like this in SaveName.jsp.
    <%
    String name = request.getParameter( "username" );
    session.putValue( "theName", name );
    %>

  • Sun Java System Web Server 6.1 SP3 service-j2ee threads problem

    Hi,
    Sorry my english.
    I'm an intermediate Java programmer and a newbie in
    the Sun's web servers world.
    I'm doing an evaluation of an web applicaction
    written in Java Servlets that is
    supposed to have a leaking threads problem. We use
    SunOS 5.9 (... sun4u sparc SUNW,UltraAX-i2) and
    JVM 1.5 Update 4 (the problem is presented too
    in SunOS 5.8 and JVM 1.4.2_04).
    We have seen, thanks to 'prstat' (PROCESS/NLWP) a
    increasing thread's growing in one of the process
    that correspond to our web server instance (I'm sure I'm
    looking the right process). I have checkout the source
    code and it seems like the app doesn't have threads
    problems. I have used the Netbeans Profiler and I see a
    high number of threads called service-j2ee-x that grows
    in congestion moments and never disappear.
    Anybody could help me with suggestions?
    Thank you very much.

    Elvin,
    Thankyou, yes I am unfamiliar with debugging Java apps. I got the web server Java stack trace and I have passed this on to the developer.
    The web server finally closes the socket connection after the total connections queued exceeds 4096.
    There are several hundred entries like this... waiting for monitor entry.. could be a deadlock somewhere?
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "service-j2ee-506" prio=5 tid=0x04b62a08 nid=0x17a waiting for monitor entry [dd74e000..dd74f770]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.util.JSDispenser.getConnResource(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting to lock <0xe979b2b0> (a com.verity.search.util.JSDispenser)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.getDoc(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.getDoc(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.docViewIntern(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.verity.search.DocRead.docView(Unknown Source)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at au.com.relevance.viewDoc.PdfXmlServlet.performRequest(PdfXmlServlet.java:120)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at au.com.relevance.viewDoc.PdfXmlServlet.doGet(PdfXmlServlet.java:141)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at javax.servlet.http.HttpServlet.service(HttpServlet.java:787)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at javax.servlet.http.HttpServlet.service(HttpServlet.java:908)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardWrapperValve.invokeServletService(StandardWrapperValve.java:771)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:322)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:212)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:209)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:509)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.connector.nsapi.NSAPIProcessor.process(NSAPIProcessor.java:161)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at com.iplanet.ias.web.WebContainer.service(WebContainer.java:580)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[highlight]" daemon prio=5 tid=0x000f3530 nid=0x1e waiting on condition [e15ff000..e15ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[highlight]" daemon prio=5 tid=0x000f3328 nid=0x1d waiting on condition [e16ff000..e16ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[]" daemon prio=5 tid=0x000f2b08 nid=0x1c waiting on condition [e1b7f000..e1b7fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[]" daemon prio=5 tid=0x000f2900 nid=0x1b waiting on condition [e1c7f000..e1c7fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[sitesearch]" daemon prio=5 tid=0x000f1cd0 nid=0x1a waiting on condition [e23ff000..e23ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "WebappLoader[sitesearch]" daemon prio=5 tid=0x000f1ac8 nid=0x19 waiting on condition [e24ff000..e24ffc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.threadSleep(WebappLoader.java:1214)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.loader.WebappLoader.run(WebappLoader.java:1341)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "StandardManager[search]" daemon prio=5 tid=0x000f0a88 nid=0x18 waiting on condition [e317f000..e317fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.sleep(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.threadSleep(StandardManager.java:800)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at org.apache.catalina.session.StandardManager.run(StandardManager.java:859)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Thread.run(Thread.java:534)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Signal Dispatcher" daemon prio=10 tid=0x000ef840 nid=0x12 waiting on condition [0..0]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Finalizer" daemon prio=8 tid=0x000ef638 nid=0x10 in Object.wait() [fa27f000..fa27fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting on <0xe917fb10> (a java.lang.ref.ReferenceQueue$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:111)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - locked <0xe917fb10> (a java.lang.ref.ReferenceQueue$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:127)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Reference Handler" daemon prio=10 tid=0x000ef430 nid=0xf in Object.wait() [fa37f000..fa37fc28]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Native Method)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - waiting on <0xe917fb78> (a java.lang.ref.Reference$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.Object.wait(Object.java:429)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:115)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: - locked <0xe917fb78> (a java.lang.ref.Reference$Lock)
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "main" prio=5 tid=0x000ee3f0 nid=0x1 runnable [0..ffbff200]
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "VM Thread" prio=5 tid=0x004ee328 nid=0xe runnable
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "VM Periodic Task Thread" prio=10 tid=0x004ee5d0 nid=0x16 waiting on condition
    [15/May/2006:22:01:51] warning ( 3196): CORE3283: stderr: "Suspend Checker Thread" prio=10 tid=0x004ee548 nid=0x11 runnable
    [15/May/2006:22:15:10] failure ( 3196): HTTP3287: connection limit (4096) exceeded, closing socket

  • 64-bit JNI C++ to JAVA invocation multiple threads classloader problem

    Hi ALL,
    I have a C++ app that invokes Java classes on 64-bit Solaris 10 with 64-bit JVM.
    Here is the problem:
    The native non-main (not the thread that initializes the JVM) threads would not be able to find any user-define class.
    Here are the symptoms and observations:
    1. JNIEnv::ExceptionDescribe() showed the following StackOverflowError:
    Exception in thread "Thread-0" java.lang.StackOverflowError
            at java.util.Arrays.copyOf(Arrays.java:2734)
            at java.util.Vector.ensureCapacityHelper(Vector.java:226)
            at java.util.Vector.addElement(Vector.java:573)
            at java.lang.ClassLoader.addClass(ClassLoader.java:173)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)2. The "main thread" that instantiates the JVM has no problem finding and loading any class or method
    3. But the other threads (non-main threads) would not be able to find the user-defined classes unless the classes were already loaded by the main thread.
    4. The non-main threads can find the "standard" java classes with no problem
    5. The same app ran fine on 32-bit system.
    6. Except for the JVM reference is global, each thread acquired JNIEnv by either GetEnv() or AttachCurrentThread().
    Any idea why it is a problem with 64-bit?
    I have the sample program to reproduce this issue in this thread: http://forums.sun.com/thread.jspa?messageID=10885363&#10885363. That was the original thread I raised but I have narrowed it down to a more concrete scenario. That's why I am creating this new thread. I hope this does not break any rule on this forum. If it does, I apologize.
    I really appreciate it if anyone can provide any help/suggestion.
    Regards,
    - Triet

    Here is the sample program. Again, this works on 32-bit but not 64-bit.
    #include <string>
    #include "jni.h"
    #include "TestThread.h"
    static JavaVM *g_pjvm = NULL;  /* denotes a Java VM */
    static JNIEnv *g_penv = NULL;  /* pointer to native method interface */
    void initJVM(char** jvmOptions) {
        printf("RJniTest init starts...\n");
        JavaVMInitArgs vm_args; /* JDK/JRE 6 VM initialization arguments */
        JavaVMOption* poptions;
        int optionLen = 0;
        while (jvmOptions[optionLen]) {
            optionLen++;
        printf("RJniTest::init len=%d\n", optionLen);
        if (optionLen > 0) {
            printf("RJniWrapper::init jvmOptions\n");
            poptions = new JavaVMOption[optionLen];
            //poptions[0].optionString = "-Djava.class.path=/usr/lib/java";
            int idx = 0;
            while (jvmOptions[idx]) {
                poptions[idx].optionString = jvmOptions[idx];
                idx++;
        printf("RJniTest::init vm_args: version(%x), nOptions(%d)\n",
                JNI_VERSION_1_6, optionLen);
        vm_args.version = JNI_VERSION_1_6;
        vm_args.nOptions = optionLen;
        vm_args.options = poptions;
        vm_args.ignoreUnrecognized = JNI_FALSE;
        // load and initialize a Java VM, return a JNI interface
        // pointer in env
        printf("RJniTest::init creates JVM\n");
        JNI_CreateJavaVM(&g_pjvm, (void**)&g_penv, &vm_args);
        printf("RJniTest init ends\n");
    void findClass(const char* classname) {
        static const char* fname = "justFindClasses";
        printf("%s: findClass: %s\n", fname, classname);
        JNIEnv* jenv;
        jint ret = g_pjvm->GetEnv((void**)&jenv, JNI_VERSION_1_6);
        if (ret == JNI_EDETACHED) {
            ret = g_pjvm->AttachCurrentThread((void**)&jenv, NULL);
            if (ret != JNI_OK || jenv == NULL) {
                printf("%s: get env error: ret=%d\n", ret, fname);
            } else {
                printf("%s: got new env\n", fname);
        } else if (ret == JNI_OK) {
            printf("%s: env already there\n");
        jclass classref;
        classref = jenv->FindClass(classname);
        if (classref == NULL) {
            printf("%s: %s class not found!\n", fname, classname);
            if (jenv->ExceptionOccurred()) {
                jenv->ExceptionDescribe();
                jenv->ExceptionClear();
        printf("%s: found class: %s\n", fname, classname);
    class RJniTestThread : public TestThread {
    public:
        void threadmain();
    void RJniTestThread::threadmain() {
        printf("RJniTestThread::threadmain: Starting testing\n");
        findClass("org/apache/commons/logging/Log");
        findClass("java/util/List");
        printf("RJniTestThread::threadmain: done.\n");
    int main(int argc, char** argv) {
        char **jvmOptions = NULL;
        printf("RJniTestDriver starts...\n");
        if (argc > 1) {
            jvmOptions = new char*[argc];
            for (int i = 0; i < argc ; i ++) {
                jvmOptions[i] = argv[i + 1];
            jvmOptions[argc - 1] = NULL;
        } else {
            int size = 8;
            int i = 0;
            jvmOptions = new char*[size];
            jvmOptions[i++] = (char*) "-Djava.class.path=<list of jar files and path here>";
            jvmOptions[i++] = (char*) "-Djava.library.path=/sandbox/mxdev/3rdparty/java/unix/jdk1.6.0_14/jre/lib/sparc";
            jvmOptions[i++] = (char*) "-Djava.compiler=NONE";
            jvmOptions[i++] = (char*) "-verbose:jni";
            jvmOptions[i++] = (char*) "-Xcheck:jni";
            jvmOptions[i++] = NULL;
        printf("init JVM\n");
        initJVM(jvmOptions);
        // UNCOMMENT HERE
        // findClass("org/apache/commons/logging/Log");
        // findClass("java/util/List");
        // UNCOMMENT END
        printf("start test thread\n");
        RJniTestThread testThread;
        ThreadId tid = testThread.launch();
        printf("wait for test thread\n");
        int ret = pthread_join(tid, NULL);
        printf("RJniTestDriver ends\n");
    }

  • Many Bouncing Balls Program

    I am trying to create a program that can use one method to create many bouncing balls.I want each ball to function independently of each other.
    The problem I am having is that when I call my BouncingBall () method three times, it only creates one ball that moves randomly instead of three.
    If you have any idea of how to tackle this problem I would really appreciate if you shared them with me. I am relatively new to java.
    I read that threads might be a good option to work on this problem but I am not sure how to use them.
    *(Code Starts)*
    import acm.graphics.*;
    import acm.program.*;
    import acm.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class BouncingBalls extends GraphicsProgram {
         public void run(){
              BouncingBall(50, 50);
              BouncingBall(100, 100);
              BouncingBall(300, 300);
         public void BouncingBall(double width, double height) {
              //Create variables for x and y position of balls
              double xPosition = getWidth()/2;
              double yPosition = getHeight()/2;
              //Create Ball
              GOval Ball = new GOval (xPosition, yPosition, width, height);
              add (Ball);
              // Initialize variables for use in Random movement method
              double xMoveBall = rgen.nextDouble(-4.0, 4.0);
              double yMoveBall = rgen.nextDouble(-4.0, 4.0);
              //Ball's Random Movement
              while (true) {     
                        Ball.move(xMoveBall,yMoveBall);
                        pause(10);
                             xPosition += xMoveBall;
                             yPosition += yMoveBall;
                   //Ball's Collisions     with walls
                   if (xPosition >= (getWidth() - width)) {
                        xMoveBall = -(xMoveBall);
                        pause(10);
                   if (xPosition <= 0){
                        xMoveBall = -(xMoveBall);
                        pause(10);
                   if (yPosition <= 0){
                        yMoveBall = -(yMoveBall);
                        pause(10);
                   if (yPosition >= getHeight() - height){
                        yMoveBall = -(yMoveBall);
                        pause(10);
         private RandomGenerator rgen = RandomGenerator.getInstance();{}
    *(Code Ends)*

    Hi,
    I have been experimenting with threads for the last couple of days. Here is the code I have been working on. I explain what I am trying to do below it:
    import acm.graphics.*;
    import acm.program.*;
    import acm.util.*;
    import java.awt.*;
    import java.awt.event.*;
    public class BB5 extends GraphicsProgram implements Runnable{
         // Debbuging Label
         private GLabel label = new GLabel("");
         //Initialize variables for ball's position
         private double xPosition = getWidth()/2;
         private double yPosition = getHeight()/2;
         //Initialize variables for use in Random movement method
         private double yMoveBall;
         private double xMoveBall;
         //Initialize variables for width and height of ball, so that they can be used in both metods: bounce() and CreateBall()
         private double width;
         private double height;
         public void mouseClicked (MouseEvent e){
              new Thread(this).start();
         public void run() {
              CreateBall(50,50).bounce();
         public void CreateBall(double x, double y) {
              //Create variables for x and y position of balls
                 xPosition = getWidth()/2;
                 yPosition = getHeight()/2;
              //Create Ball
              x = width;
              y = height;
              GOval Ball = new GOval (xPosition, yPosition, width, height);
              add (Ball);
         public void bounce() {     
         yMoveBall = rgen.nextDouble(-4.0, 4.0);
         xMoveBall = rgen.nextDouble(-4.0, 4.0);
              //Ball's Random Movement
              while (true){
                   //Put thread to sleep for 5 milliseconds so that other balls can use bounce()
                   try { Thread.sleep(5); } catch(InterruptedException e) {}
                        //Move Ball created in previous methods
                        Ball.move(xMoveBall,yMoveBall);
                        pause(10);
                             xPosition += xMoveBall;
                             yPosition += yMoveBall;
                             label.setLabel(""+xPosition); add (label, 50, 50);
                   //Ball's Collisions     with walls
                   if (xPosition >= (getWidth() - width)) {
                        xMoveBall = -(xMoveBall);
                        pause(10);
                   if (xPosition  <= 0){
                        xMoveBall = -(xMoveBall);
                        pause(10);
                   if (yPosition  <= 0){
                        yMoveBall = -(yMoveBall);
                        pause(10);
                   if (yPosition  >= getHeight() - height){
                        yMoveBall = -(yMoveBall);
                        pause(10);
         private RandomGenerator rgen = RandomGenerator.getInstance();{}
    }The idea is that I have a method that creates the ball CreateBall(), and another that bounces the ball bounce().
    My init method creates one ball. Then, when I click the mouse, I create a new thread which applies the bounce method to the ball by running the run method.
    Inside the bounce method, I have a thread sleep so that other threads can be started.
    Eventually, what I would like to do, is that everytime I click the mouse, a new ball is created and the bounce is applied to it.
    I am also having trouble with getting the ball from my CreateBall() method, to work inside my bounce().
    Can you please help me understand what might be wrong with my code?
    Thank you!

  • Bouncing ball question

    Hi, I'm new to the forums and really new to java and I was wondering if anyone could help me with a simple java program that I'm writing.
    It deals simply with a bouncing ball (yes I know there's a topics on this one heh) that bounces aimlessly inside a drawing window.
    Here's my problem:
    I can make the ball bounce off two boundaries (top and right, left and bottom, right and bottom etc.) but when the ball reaches the 3rd boundary it just passes through it. It wont bounce off opposite sides (left and right, top and bottom) it only bounces off the first.
    I believe it has something to do with my if statements under the move method.
    I need to make some kind of loop so it keeps checking if the ball comes to a new boundary.
    Right now it's only checking it once and after it bounces the ball one time thats it.
    (I've tested all the boundaries to see if they bounce the ball and they all do, its just I can't bounce it more than 2 times)
    I'm stuck on how to write this loop statement. Any help would be greatly appreciated! Thanks.
    My code (If this isnt enough let me know please):
    (BallTester.java)
    import element.*;
    public class BallTester{
    public static void main(String[] args){
    int width = 500;
    int height = 400;
    DrawingWindow d = new DrawingWindow(width,height);      
    Ball b = new Ball(70,30,width,height);
    b.send(d);                                   
    (Ball.java)
    import element.*;
    public class Ball{
    int base; // center line of where the circle starts
    int size; // radius of circle
    int xPos,yPos; // circle ctr
    Circle c;
         int width, height;
         int dx,dy;
    public Ball(int base, int size, int width, int height) {
              this.base = base;
    this.size = size;
    c = new Circle(50,base,size);
              this.width = width; this.height = height;
              xPos = 50;
              yPos = base;
    public void drawOn(DrawingWindow d){
              //draws the circle
              c.drawOn(d);
    public void clearOn(DrawingWindow d){
              d.invertMode(); // black-> white
              drawOn(d); //redraw in white: erase!
              d.invertMode(); // white -> black
    public void move(int dx, int dy){
              //Sets boundaries for x values
              if((xPos<=size)||(xPos>=width-size)){
              dx = -dx;
              else
              xPos += dx;
              //Sets boundaries for y values
              if((yPos<=size)||(yPos>=height-size)){
              dy = -dy;
              else     
              yPos += dy;
              c.move(dx,dy);
    public void send(DrawingWindow d){
              Waiting w = new Waiting();
    //This below keeps the ball drawing up until j = width)
    for(int j = 0; j < width; j++){
              move(6,-3); // moves the circle based on dx, dy values
              this.drawOn(d);
    w.snooze(60);
    this.clearOn(d);}

    You don't need a loop to check - you just need to check every loop (before you repaint).
    I created an example for you. If this assignment is homework, don't hand it in - use it as a reference. Try to understand what's going on in the code and why it works.
    import java.awt.*;
    import javax.swing.*;
    public class Test extends JFrame {
        public Test () {
            getContentPane ().setLayout (new BorderLayout ());
            getContentPane ().add (new TestPanel ());
            setDefaultCloseOperation (DISPOSE_ON_CLOSE);
            setTitle ("Test");
            pack ();
            setLocationRelativeTo (null);
            setVisible (true);
        public static void main (String[] parameters) {
            new Test ();
        private class TestPanel extends JPanel {
            private Ball ball;
            public TestPanel () {
                ball = new Ball ();
                Thread painter = new Thread (new Runnable () {
                    public void run () {
                        while (true) {
                            try {
                                Thread.sleep (20);
                            } catch (InterruptedException exception) {}
                            repaint ();
                painter.setDaemon (true);
                painter.start ();
            public Dimension getPreferredSize () {
                return new Dimension (300, 200);
            public void paintComponent (Graphics g) {
                super.paintComponent (g);
                ball.move (getWidth (), getHeight ());
                ball.paint (g);
            private class Ball {
                private static final int W = 10;
                private static final int H = 10;
                private int x;
                private int y;
                private int dx;
                private int dy;
                public Ball () {
                    x = 0;
                    y = 0;
                    dx = 2;
                    dy = 2;
                public void move (int width, int height) {
                    int x = this.x + dx;
                    int y = this.y + dy;
                    if ((x < 0) || (x + W > width)) {
                        dx = -dx;
                        x = this.x + dx;
                    if ((y < 0) || (y + H > height)) {
                        dy = -dy;
                        y = this.y + dy;
                    this.x = x;
                    this.y = y;
                public void paint (Graphics g) {
                    g.fillOval (x, y, W, H);
    }

  • How to repaint a JPanel in bouncing balls game?

    I want to repaint the canvas panel in this bouncing balls game, but i do something wrong i don't know what, and the JPanel doesn't repaint?
    The first class defines a BALL as a THREAD
    If anyone knows how to correct the code please to write....
    package fuck;
    //THE FIRST CLASS
    class CollideBall extends Thread{
        int width, height;
        public static final int diameter=15;
        //coordinates and value of increment
        double x, y, xinc, yinc, coll_x, coll_y;
        boolean collide;
        Color color;
        Rectangle r;
        bold BouncingBalls balls; //A REFERENCE TO SECOND CLASS
        //the constructor
        public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c, BouncingBalls balls) {
            width=w;
            height=h;
            this.x=x;
            this.y=y;
            this.xinc=xinc;
            this.yinc=yinc;
            this.balls=balls;
            color=c;
            r=new Rectangle(150,80,130,90);
        public double getCenterX() {return x+diameter/2;}
        public double getCenterY() {return y+diameter/2;}
        public void move() {
            if (collide) {
            x+=xinc;
            y+=yinc;
            //when the ball bumps against a boundary, it bounces off
            //bounce off the obstacle
        public void hit(CollideBall b) {
            if(!collide) {
                coll_x=b.getCenterX();
                coll_y=b.getCenterY();
                collide=true;
        public void paint(Graphics gr) {
            Graphics g = gr;
            g.setColor(color);
            //the coordinates in fillOval have to be int, so we cast
            //explicitly from double to int
            g.fillOval((int)x,(int)y,diameter,diameter);
            g.setColor(Color.white);
            g.drawArc((int)x,(int)y,diameter,diameter,45,180);
            g.setColor(Color.darkGray);
            g.drawArc((int)x,(int)y,diameter,diameter,225,180);
            g.dispose(); ////////
        ///// Here is the buggy code/////
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.canvas.repaint();
    //THE SECOND CLASS
    public class BouncingBalls extends JFrame{
        public Graphics gBuffer;
        public BufferedImage buffer;
        private Obstacle o;
        private List<CollideBall> balls=new ArrayList();
        private static final int SPEED_MIN = 0;
        private static final int SPEED_MAX = 15;
        private static final int SPEED_INIT = 3;
        private static final int INIT_X = 30;
        private static final int INIT_Y = 30;
        private JSlider slider;
        private ChangeListener listener;
        private MouseListener mlistener;
        private int speedToSet = SPEED_INIT;
        public JPanel canvas;
        private JPanel p;
        public BouncingBalls() {
            super("fuck");
            setSize(800, 600);
            p = new JPanel();
            Container contentPane = getContentPane();
            final BouncingBalls xxxx=this;
            o=new Obstacle(150,80,130,90);
            buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
            gBuffer=buffer.getGraphics();
            //JPanel canvas start
            final JPanel canvas = new JPanel() {
                final int w=getSize().width-5;
                final int h=getSize().height-5;
                @Override
                public void update(Graphics g)
                   paintComponent(g);
                @Override
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    gBuffer.setColor(Color.ORANGE);
                    gBuffer.fillRect(0,0,getSize().width,getSize().height);
                    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
                    //paint the obstacle rectangle
                    o.paint(gBuffer);
                    g.drawImage(buffer,0,0, null);
                    //gBuffer.dispose();
            };//JPanel canvas end
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            addButton(p, "Start", new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    CollideBall b = new CollideBall(canvas.getSize().width,canvas.getSize().height
                            ,INIT_X,INIT_Y,speedToSet,speedToSet,Color.BLUE,xxxx);
                    balls.add(b);
                    b.start();
            contentPane.add(canvas, "Center");
            contentPane.add(p, "South");
        public void addButton(Container c, String title, ActionListener a) {
            JButton b = new JButton(title);
            c.add(b);
            b.addActionListener(a);
        public boolean collide(CollideBall b1, CollideBall b2) {
            double wx=b1.getCenterX()-b2.getCenterX();
            double wy=b1.getCenterY()-b2.getCenterY();
            //we calculate the distance between the centers two
            //colliding balls (theorem of Pythagoras)
            double distance=Math.sqrt(wx*wx+wy*wy);
            if(distance<b1.diameter)
                return true;
            return false;
        synchronized void repairCollisions(CollideBall a) {
            for (CollideBall x:balls) if (x!=a && collide(x,a)) {
                x.hit(a);
                a.hit(x);
        public static void main(String[] args) {
            JFrame frame = new BouncingBalls();
            frame.setVisible(true);
    }  And when i press start button:
    Exception in thread "Thread-2" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-3" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-4" java.lang.NullPointerException
    at fuck.CollideBall.run(CollideBall.java:153)
    and line 153 is: balls.canvas.repaint(); in Method run() in First class.
    Please help.

    public RepaintManager manager;
    public BouncingBalls() {
            manager = new RepaintManager();
            manager.addDirtyRegion(canvas, 0, 0,canvas.getSize().width, canvas.getSize().height);
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.manager.paintDirtyRegions(); //////// line 153
       but when push start:
    Exception in thread "Thread-2" java.lang.IllegalMonitorStateException
    at java.lang.Object.notifyAll(Native Method)
    at fuck.CollideBall.run(CollideBall.java:153)
    Exception in thread "Thread-3" java.lang.IllegalMonitorStateException
    at java.lang.Object.notifyAll(Native Method)
    at fuck.CollideBall.run(CollideBall.java:153)
    i'm newbie with Concurrency and i cant handle this exceptons.
    Is this the right way to do repaint?

  • Balls don't move in bouncing balls game.Please Help !?

    I want to repaint the canvas panel in this bouncing balls game, but i do something wrong i don't know what, and the JPanel doesn't repaint?
    The first class defines a BALL as a THREAD
    If anyone knows how to correct the code please to write....
    package ****;
    //THE FIRST CLASS
    class CollideBall extends Thread{
        int width, height;
        public static final int diameter=15;
        //coordinates and value of increment
        double x, y, xinc, yinc, coll_x, coll_y;
        boolean collide;
        Color color;
        Rectangle r;
        bold BouncingBalls balls; //A REFERENCE TO SECOND CLASS
        //the constructor
        public CollideBall(int w, int h, int x, int y, double xinc, double yinc, Color c, BouncingBalls balls) {
            width=w;
            height=h;
            this.x=x;
            this.y=y;
            this.xinc=xinc;
            this.yinc=yinc;
            this.balls=balls;
            color=c;
            r=new Rectangle(150,80,130,90);
        public double getCenterX() {return x+diameter/2;}
        public double getCenterY() {return y+diameter/2;}
        public void move() {
            if (collide) {
            x+=xinc;
            y+=yinc;
            //when the ball bumps against a boundary, it bounces off
            //bounce off the obstacle
        public void hit(CollideBall b) {
            if(!collide) {
                coll_x=b.getCenterX();
                coll_y=b.getCenterY();
                collide=true;
        public void paint(Graphics gr) {
            Graphics g = gr;
            g.setColor(color);
            //the coordinates in fillOval have to be int, so we cast
            //explicitly from double to int
            g.fillOval((int)x,(int)y,diameter,diameter);
            g.setColor(Color.white);
            g.drawArc((int)x,(int)y,diameter,diameter,45,180);
            g.setColor(Color.darkGray);
            g.drawArc((int)x,(int)y,diameter,diameter,225,180);
            g.dispose(); ////////
        ///// Here is the buggy code/////
        public void run() {
            while(true) {
                try {Thread.sleep(15);} catch (Exception e) { }
                synchronized(balls)
                    move();
                    balls.repairCollisions(this);
                paint(balls.gBuffer);
                balls.canvas.repaint();
    //THE SECOND CLASS
    public class BouncingBalls extends JFrame{
        public Graphics gBuffer;
        public BufferedImage buffer;
        private Obstacle o;
        private List<CollideBall> balls=new ArrayList();
        private static final int SPEED_MIN = 0;
        private static final int SPEED_MAX = 15;
        private static final int SPEED_INIT = 3;
        private static final int INIT_X = 30;
        private static final int INIT_Y = 30;
        private JSlider slider;
        private ChangeListener listener;
        private MouseListener mlistener;
        private int speedToSet = SPEED_INIT;
        public JPanel canvas;
        private JPanel p;
        public BouncingBalls() {
            super("****");
            setSize(800, 600);
            p = new JPanel();
            Container contentPane = getContentPane();
            final BouncingBalls xxxx=this;
            o=new Obstacle(150,80,130,90);
            buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
            gBuffer=buffer.getGraphics();
            //JPanel canvas start
            canvas = new JPanel() {
                final int w=getSize().width-5;
                final int h=getSize().height-5;
                @Override
                public void update(Graphics g)
                   paintComponent(g);
                @Override
                public void paintComponent(Graphics g) {
                    super.paintComponent(g);
                    gBuffer.setColor(Color.ORANGE);
                    gBuffer.fillRect(0,0,getSize().width,getSize().height);
                    gBuffer.draw3DRect(5,5,getSize().width-10,getSize().height-10,false);
                    //paint the obstacle rectangle
                    o.paint(gBuffer);
                    g.drawImage(buffer,0,0, null);
                    //gBuffer.dispose();
            };//JPanel canvas end
            addWindowListener(new WindowAdapter() {
                @Override
                public void windowClosing(WindowEvent e) {
                    System.exit(0);
            addButton(p, "Start", new ActionListener() {
                public void actionPerformed(ActionEvent evt) {
                    CollideBall b = new CollideBall(canvas.getSize().width,canvas.getSize().height
                            ,INIT_X,INIT_Y,speedToSet,speedToSet,Color.BLUE,xxxx);
                    balls.add(b);
                    b.start();
            contentPane.add(canvas, "Center");
            contentPane.add(p, "South");
        public void addButton(Container c, String title, ActionListener a) {
            JButton b = new JButton(title);
            c.add(b);
            b.addActionListener(a);
        public boolean collide(CollideBall b1, CollideBall b2) {
            double wx=b1.getCenterX()-b2.getCenterX();
            double wy=b1.getCenterY()-b2.getCenterY();
            //we calculate the distance between the centers two
            //colliding balls (theorem of Pythagoras)
            double distance=Math.sqrt(wx*wx+wy*wy);
            if(distance<b1.diameter)
                return true;
            return false;
        synchronized void repairCollisions(CollideBall a) {
            for (CollideBall x:balls) if (x!=a && collide(x,a)) {
                x.hit(a);
                a.hit(x);
        public static void main(String[] args) {
            JFrame frame = new BouncingBalls();
            frame.setVisible(true);
    }  This code draws only the first position of the ball:
    http://img267.imageshack.us/my.php?image=51649094by6.jpg

    I'm trying to draw everything first to a buffer:
    buffer=new BufferedImage(getSize().width, getSize().height, BufferedImage.TYPE_INT_RGB);
    gBuffer=buffer.getGraphics();
    The buffer is for one JPanel and then i want to draw this buffer every time when balls change their possitions(collide or just move).
    The logic is something like this:
    startButton -> (ball.start() and add ball to List<balls>),
    ball.start() -> ball.run() -> (move allballs, paint to buffer and show buffer)
    In the first class:
    BouncingBalls balls; //A REFERENCE TO SECOND CLASS
    In the second class:
    private List<CollideBall> balls=new ArrayList();
    the tames are the same but this isn't an error.
    Edited by: vigour on Feb 14, 2008 7:57 AM

  • The JAVA program for "Philosopher Problem"

    When I learn the book of "Operating Systems (Design and Implementation)"(written by Andrew S.Tanenbaum), I try to write a program for the "Philosopher Problem" . In the book there is a sample of this problem in C language, and I write it in JAVA. The following is my program, I have tested it. It is correct, but maybe it is not the most efficient way to solve the problem. Can you think out a more efficient program in JAVA to solve this problem?
    * Philosopher Eating Problem
    * @author mubin
    * @version 1.0
    public class PhilosopherEating {
    //Philosophers' number
    private final static int PHER_NUM = 20;
    //Philosophers' state
    private volatile static int[] pherState = new int[PHER_NUM];
    //THINKING
    private final static int THINKING = 0;
    //HUNGRY
    private final static int HUNGRY = 1;
    //EATING
    private final static int EATING = 2;
    //Philosophers thread group
    public static Philosopher[] philosophers = new Philosopher[PHER_NUM];
    //finish indicator
    public volatile static boolean finished =false;
    //thread lock
    public static Object threadLock = new Object();
    public PhilosopherEating() {
    * Philosopher class
    * @author mubin
    * @version 1.0
    public static class Philosopher extends Thread{
    int pherNo ;
    public Philosopher(int no){
    this.pherNo = no;
    public void run(){
    while(!PhilosopherEating.finished){
    think();
    takeForks(this.pherNo);
    eat();
    putForks(this.pherNo);
    * Thinking
    private void think(){
    System.out.println("Philosopher"+this.pherNo+"is thinking...");
    try {
    Thread.sleep( (int)(Math.random()*100));
    }catch (Exception ex) {
    ex.printStackTrace(System.out);
    * Eating
    private void eat(){
    System.out.println("Philosopher"+this.pherNo+"is eating...");
    try {
    Thread.sleep( (int)(Math.random()*100));
    }catch (Exception ex) {
    ex.printStackTrace(System.out);
    * Take the fork
    private void takeForks(int no){
    //System.out.println("takeForks:no:"+no);
    synchronized (threadLock) {
    pherState[no] = HUNGRY;
    testPher(no);
    * Put down the fork
    private void putForks(int no){
    //System.out.println("putForks:no:"+no);
    synchronized (threadLock) {
    pherState[no] = THINKING;
    if( pherState[getLeft()]==HUNGRY ){
    philosophers[getLeft()].interrupt();
    if( pherState[getRight()]==HUNGRY ){
    philosophers[getRight()].interrupt();
    * Return the NO. of philosopher who is sitting at the left side of this philosopher
    * @return the NO. of the left philosopher
    private int getLeft(){
    int ret = (pherNo-1)<0? PHER_NUM-1 : (pherNo-1);
    return ret;
    * Return the NO. of philosopher who is sitting at the right side of this philosopher
    * @return the NO. of the right philosopher
    private int getRight(){
    int ret = (pherNo+1)>=PHER_NUM ? 0 :(pherNo+1);
    return ret;
    private void testPher(int no){
    while(true){
    if(pherState[no]==HUNGRY
    &&pherState[getLeft()]!=EATING
    &&pherState[getRight()]!=EATING) {
    pherState[no] = EATING;
    //Print and check the philosophers' state
    printPher(pherState);
    return;
    }else{
    try {
    System.out.println(" Philosopher "+this.pherNo+"is waiting a fork");
    threadLock.wait();
    }catch (java.lang.InterruptedException ex) {
    System.out.println(" Philosopher "+this.pherNo+"is interrupted and woken up to take fork");
    //when it is interrupted, do nothing. Just let it continue!
    }//end of while(true)
    * Print and check the philosophers' state.
    * To insure there are no two philosophers sit side by side
    * are eating at the same time.
    private static void printPher(int[] phers){
    System.out.print(" philosophers' state��");
    for (int i = 0; i < phers.length; i++) {
    System.out.print(" "+phers);
    System.out.println("");
    for (int i = 0; i < phers.length-1; i++) {
    if (phers[i]==EATING && phers[i+1]==EATING){
    System.err.println(i+" and "+(i+1)+"two of philosophers sitted side by side are eating at the same time!");
    if (phers[0]==EATING && phers[PHER_NUM-1]==EATING){
    System.err.println("0 and "+PHER_NUM+"two of philosophers sitted side by side are eating at the same time!");
    public static void main(String[] args) {
    for (int i = 0; i < PHER_NUM; i++) {
    PhilosopherEating.pherState[i] = THINKING;
    PhilosopherEating aPhilosopherEating = new PhilosopherEating();
    for (int i = 0; i < PHER_NUM; i++) {
    philosophers[i] = new Philosopher(i);
    philosophers[i].start();
    try {
    Thread.sleep(30000);
    catch (InterruptedException ex) {
    ex.printStackTrace(System.out);
    //End all the threads of philosophers
    PhilosopherEating.finished = true;

    this problem is about learning how to use threads/synchronise objects etc, the efficiency of the code isn't really an issue, if that's what you mean. As for the efficiency of the solution, it's very hard to tell how efficient it is, but as long as all the philosphers get to eat there's no problem. I haven't really scrutized your code, but I'm not sure that you have a deadlock free solution: as long as it is possible for all the phils to pick up one fork at the same time there's a problem, and it seems from your code that each philosopher will pick up "his" fork. Again, I could be wrong, I haven't really looked. If you haven't come up with a solution, try drawing it on paper and working it out, or if you're lazy a quick google will probably give you the answer, but I'm pretty sure nobody here will :)

  • Cant syncronize! Threads problem

    Hello everybody,
    recently i posted a question(im new to threads) and it was asked immediately but now i have another
    type of problem.
    Please read here the initial post and the answer and please give me any ideas..
    Initial Post
    Hi everybody,i have this thread problem(i'm new to java and h
    ave no idea what exactly to do).
    Well,in my applet i have this action performed method
    that i imagine is in the event dispatch thread.
    This method calls as u see, two other methods of a class named CPU(.
    Note that fetch and execute are observed classes and my applet class
    is the observer.
    The problem is that during the execution of fetch() and execute(),
    inside these methods change some things and so they call notifyObservers(Object arg)
    passing to the applet the argument and so the applet updates some text components.
    But as you can immagine there is no time for the gui to update himself so i see nothing.
    So, my question is which of the methods need to be in a separate thread so to ensure
    visible results(component updating)?
    Perhaps,the update method needs to be invokedLater with SwingUtilities?
    Please give me an example code if possible.
    Here is the actionPerformed code(from the applet class) and the fetch method:
        void executeProgramButton_actionPerformed(ActionEvent e) {      
    int numInstr = this.machine.ram.segmentSize;       
    for (int i = 0; i < numInstr; i = i + 4) {           
    machine.cpu.fetch();           
    machine.cpu.execute();       
    /*The following method is in the CPU class
    fetch method:here the observedPC is the observable value
    that notifies the observer(the main applet)
    that does: pcTextField.setText(arg.toString());*/   
    public void fetchInstructionProgram() {       
    observedPC = Integer.toString(pc);       
    setChanged();       
    notifyObservers(observedPC);       
    instructions++;       
    instruction=readOperation(cache.instructionfetch,pc);       
    pc = pc + 4;    }
    Answer to initial post
    Author: stevejluke
    One way could be to put the content of the action performed method into a new thread, then use invokeLater in your Observers that cause GUI updates:
        void executeProgramButton_actionPerformed(ActionEvent e) {     
    new Thread()       {      
    public void run()        {         
    int numInstr = this.machine.ram.segmentSize;         
    for (int i = 0; i < numInstr; i = i + 4)           {           
    machine.cpu.fetch();           
    machine.cpu.execute();         
    }.start();    }
    // In your Observer    public void update(Observable o, Object arg)    {     
    SwingUtilities.invokeLater(new Runnable() {      
    public void run()        { 
    /* your GUI afecting code
    });[i]
    Or something like that.
    You might need to watch for synchronizing things
    He was right...GUI is responsive but the results...
    Well,let me describe the new problem.
    Here you cant see the method execute().
    The problem is a synchronization problem.
    Actually,what the two methods do is:fetch() updates the value of a long called instruction and execute() takes this value and do some things.Note also that the time the execute method needs to finish is not
    always the same.By that, i mean that it depends on the value of the instruction updated by fetch().
    By putting some System.outs before and after updating i realized that there are delays or sometimes
    i noticed that fetch() executes 2 times before execute() takes control.
    So,i created some synchronized private methods set and get to control access to these resources.
    Better but still not correct...
    What should i look?Where stays the answer?
    How to synchronize these two methods on these resources?
    Thank you in advance,
    Chris

    I think that your fetch and execute has a "Producer-Consumer Relationship"
    in such cases you can make the producer place the produced value in to a queue and consumer take the vlues from the queue
    In the producer thread it sleeps for a while and try again if the Queue is full
    In the Consumer thread it sleeps for a while if the Queue is empty and then try again
    Or you can do as follows
    In the Producer thread it waite() if the Queue is full
    In the Consumer thread it waite() if the queue is empty
    When ever Producer put a value in to the Queue it calls the notify on Consumer and when ever Consumer takes a value from Queue it calls the notify() on Producer
    you can even use notify all
    I think thiere is no built in Queue class in java so you will have to write one here is a example
    public class MyLongQueue{
                long data[];
                int head, tail;
                int size;
               public MyLongQueue(int size){
                    data = new long[size];
                    head = -1;
                    tail = -1;
                    this.size = 0;
                public synchronized boolean isFull(){
                    return (size==data.length);
                public synchronized boolean isEmpty(){
                    return (size==0);
                public synchronized boolean  insert(long l){
                    if (size==data.length) return false; //Queue is full cant add more data
                    tail = (tail + 1) % data.length;
                    data[tail] = l;
                     size++;
                    return true;
               public synchronized long remove(){
                   if (size==0) throw new ArrayIndexOutOfBoundsException();
                   size--;
                   head = (head + 1) % data.length;
                   return data[head];

  • Mac is way too slow and bouncing ball is constant

    I ran the etrecheck and this is what it came back with.  What should I do?
    Problem description:
    Bouncing ball all the time…computer super slow.
    EtreCheck version: 2.1.7 (114)
    Report generated January 31, 2015 at 5:37:13 PM PST
    Download EtreCheck from http://etresoft.com/etrecheck
    Click the [Support] links for help with non-Apple products.
    Click the [Details] links for more information about that line.
    Click the [Adware] links for help removing adware.
    Hardware Information: ℹ️
        MacBook Pro (15-inch, Early 2011) (Technical Specifications)
        MacBook Pro - model: MacBookPro8,2
        1 2 GHz Intel Core i7 CPU: 4-core
        4 GB RAM Upgradeable
            BANK 0/DIMM0
                2 GB DDR3 1333 MHz ok
            BANK 1/DIMM0
                2 GB DDR3 1333 MHz ok
        Bluetooth: Old - Handoff/Airdrop2 not supported
        Wireless:  en1: 802.11 a/b/g/n
        Battery Health: Normal - Cycle count 263
    Video Information: ℹ️
        Intel HD Graphics 3000 - VRAM: 384 MB
        AMD Radeon HD 6490M - VRAM: 256 MB
            Color LCD 1440 x 900
    System Software: ℹ️
        OS X 10.10.2 (14C109) - Time since boot: 0:13:39
    Disk Information: ℹ️
        ST9500325ASG disk0 : (500.11 GB)
            EFI (disk0s1) <not mounted> : 210 MB
            Recovery HD (disk0s3) <not mounted>  [Recovery]: 650 MB
            Macintosh HD (disk1) / : 498.88 GB (235.63 GB free)
                Core Storage: disk0s2 499.25 GB Online
        HL-DT-ST DVDRW  GS23NR 
    USB Information: ℹ️
        Apple Inc. FaceTime HD Camera (Built-in)
        HP Photosmart Plus B210 series
        Apple Inc. Apple Internal Keyboard / Trackpad
        Apple Inc. BRCM2070 Hub
            Apple Inc. Bluetooth USB Host Controller
        Apple Computer, Inc. IR Receiver
    Thunderbolt Information: ℹ️
        Apple Inc. thunderbolt_bus
    Gatekeeper: ℹ️
        Mac App Store and identified developers
    Kernel Extensions: ℹ️
            /System/Library/Extensions
        [loaded]    com.LaCie.ScsiType00 (1.2.9 - SDK 10.6) [Support]
        [loaded]    com.jmicron.driver.jmPeripheralDevice (2.0.4) [Support]
        [not loaded]    com.kaspersky.kext.klif (3.0.0d23) [Support]
        [loaded]    com.kaspersky.nke (1.0.2d43) [Support]
        [loaded]    com.lacie.driver.LaCie_RemoteComms (1.0.1 - SDK 10.4) [Support]
        [loaded]    com.oxsemi.driver.OxsemiDeviceType00 (1.28.13 - SDK 10.5) [Support]
    Launch Daemons: ℹ️
        [loaded]    com.adobe.fpsaud.plist [Support]
        [running]    com.fitbit.galileod.plist [Support]
    User Launch Agents: ℹ️
        [loaded]    com.adobe.ARM.[...].plist [Support]
    User Login Items: ℹ️
        iTunesHelper    Application Hidden (/Applications/iTunes.app/Contents/MacOS/iTunesHelper.app)
    Internet Plug-ins: ℹ️
        FlashPlayer-10.6: Version: 16.0.0.296 - SDK 10.6 [Support]
        QuickTime Plugin: Version: 7.7.3
        Flash Player: Version: 16.0.0.296 - SDK 10.6 [Support]
        Default Browser: Version: 600 - SDK 10.10
        SharePointBrowserPlugin: Version: 14.3.9 - SDK 10.6 [Support]
        Silverlight: Version: 5.1.20913.0 - SDK 10.6 [Support]
        JavaAppletPlugin: Version: 15.0.0 - SDK 10.10 Check version
    Safari Extensions: ℹ️
        Pin It Button [Installed]
    3rd Party Preference Panes: ℹ️
        Flash Player  [Support]
    Time Machine: ℹ️
        Skip System Files: NO
        Mobile backups: ON
        Auto backup: YES
        Volumes being backed up:
            Macintosh HD: Disk size: 498.88 GB Disk used: 263.25 GB
        Destinations:
            LaCie [Local]
            Total size: 499.76 GB
            Total number of backups: 11
            Oldest backup: 2013-04-08 05:32:50 +0000
            Last backup: 2014-12-29 20:32:29 +0000
            Size of backup disk: Too small
                Backup size 499.76 GB < (Disk used 263.25 GB X 3)
    Top Processes by CPU: ℹ️
             5%    WindowServer
             0%    systemstatsd
             0%    HP Scanner 3
             0%    AppleSpell
             0%    fontd
    Top Processes by Memory: ℹ️
        232 MB    Image Capture Extension
        159 MB    ocspd
        133 MB    Safari
        120 MB    com.apple.WebKit.WebContent
        94 MB    Dock
    Virtual Memory Information: ℹ️
        40 MB    Free RAM
        1.56 GB    Active RAM
        1.53 GB    Inactive RAM
        1.14 GB    Wired RAM
        1.40 GB    Page-ins
        5 MB    Page-outs
    Diagnostics Information: ℹ️
        Jan 31, 2015, 05:24:14 PM    Self test - passed

    I can't stand peremptory affirmations like "Nothing is wrong with Safari".
    Thousands of users can't be wrong (see the discussions).
    If I read you the right way, it's never software' fault, it's the user who's the culprit.
    Amazing!
    In this very case, the fact is we can't give to "christinefromfonthill" a good solution because weren't sitting in front of her Mac.
    You give her a good advice which could, perhaps, lead to an improvement.
    But must also admit that Safari is a very slow browser compared to Firefox or Chrome.
    And you can't ignore all the problems which arose when upgrading to Lion and were related to the new build and specs of Safari 5.1.
    The best example is the apparition of "garbage type" (use of Last Resort font) when reading numerous sites. This never occured before and is the direct consequence of Safari compliance to Web Open Type. This standard prohibits the use of Type 1 Postscript Fonts and is the reason why so many people are in trouble.
    I use a Mac for more than 25 years.
    I am a very "clean" user who hates the bells and whistles of third party.
    My Mac is always up-to-date and despite all my Mac loving care, I run into some problems.
    Imagine the nightmare which can occurs for the vulgum pecus who isn't, by definition, a power user aware of all the requirements for running a System in optimal conditions.
    May be Safari is one step in advance on its time but lambda users are paying the price for it.

  • JNI & thread problem

    Folks,
    I am using JNI to access WIA (Windows Image Acquisition) functionality under MS Windows XP. WIA consists of a bunch of COM interfaces. I have several native functions in a single dll, with a limited number of static variables stored in the dll between calls. This all works fine as long as long as the calls occur from the same java thread, but not if a new thread is created for some of the calls. I.e., this works:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    but this does not:
    final WIACtrl ctrler=new WIACtrl();
    ctrler.initializeWIA();
    (new Thread() {
    public void run() {               
    ctrler.transferJPGNative("0001\\Root\\IMG_0087","c:\\test.jpg");
    }).start();
    Here, initializeWIA() and transferJPGNative() are the native methods. What happens in the second case is that transferJPGNative fails in one of the COM methods (not the first COM method it calls). The COM method returns an HRESULT indicating an error (509) which I can't find using any of the usual MS error look-up mechanisms. (Admittedly I am not the world's greatest Windows programmer...)
    Anyway, any suggestions would be much appreciated. I have found some issues regarding JNI and threads in this forum's archives, but none of them seem to apply to quite this situation.

    As a guess this is just a windows threading problem.
    And with COM you have to do things differently (I believe) if there is more than one thread. You might not even be allowed to do it with for that particular API.
    It could also be that you are initializing things more than once. Or you need to initialize twice (two handles.)
    At any rate you could always fix it by making the java code only allow calls for a single thread.

  • ActionListener: Thread problem in JApplet with JButton?

    Sorry for crossposting, this is my first question on this list, and I posted my question in the "Applet Development" section first. Then I discovered that there is a SWING category as well, which is closer to my problem. So please read about my problem behind this link:
    http://forum.java.sun.com/thread.jspa?threadID=634757
    Thank you very much
    Jan

    Marcin,
    you pointed me in the right direction: I put the .java file in a fresh project and checked the bin folder: And there it was: The missing (second) file the VM was complaining about. I had just forgotten to put all the respective .class files in the webdirectory. Now it works (for a start) with these two files in the webdirectory. I will improve this by creating a jar and Manifest file soon.
    Thanks again
    Jan
    PS: This was truly an (applet) newbie mistake, sorry :-(

Maybe you are looking for

  • Out of memory error when opening an .xlsx file in numbers v1.6.2 on ipad 2

    The file sizes are too small (38KB) for this to be a true "out of memory" issue. Any suggestions? I didn't have any problems before updating numbers to the current version. I haven't downloaded the new iOS 6 operating system. Is that the problem?

  • Can a C++ sub-program invoked as a cin node call a LabView sub-vi as a "function"

    The subject says it all, we have a mostly LabView system that controls a numerical simulation program. We would like to add a new numerical analysis package written in C. To be used as written this C package must call one of our LabView sub-vi's as a

  • Deleting and Adding Album Artwork

    I am able to add album artwork from saved files onto iTunes, but if I want to delete an image that iTunes gave the song, which is wrong, it won't let me. The image is still there after I hit delete and then OK. Also, I added an image that wasn't from

  • Olá, eu tenho um iMac G3.

    Olá, eu tenho um iMac G3 com Mac OS X 10.3.9 e, quero instalar o Mac OS X 10.4 Tiger. Preciso saber o passo a passo dessa instalação, pois não encontrei o DVD de instalação do Tiger à venda, o que à princípio é um problema.

  • Divi cam 525d

    where can i buy this divi cam in Dubai ?can it be bught in Dubai or no?and how much dose it cost?help me plz