Hi people,

Yeah, so I have an application that works. The code is not buggy and I have worked hard on it. It is three files long but the section I need help with is small. It is the paintComponent section. It is a multi-threaded application and if you want to see the whole thing I will post it up here, but for now here is the part I believe to have the problem.

The code btw, is the multithreading problem with various balls bouncing around in a screen.

public void updatePicture()
	{
		
		repaint();
	}

public void paintComponent(Graphics g)
	{
		
		super.paintComponent(g);
		//System.err.println("Inside paint method outside loop.  Initialize: " + initialized);
		if (initialized)
		{
		//System.err.println("Inside the paint method");
		for (int i = 0; i <= ballNumber; i++)
		{
		g.setColor(Color.black);
		g.fillOval(b[ballNumber].getXCoord() + b[ballNumber].getShadowXFactor(),
				  b[ballNumber].getYCoord() + b[ballNumber].getShadowYFactor(),
				  b[ballNumber].getSize(), b[ballNumber].getSize());
		
		System.err.println("Printing ball Number: " + i);
		g.setColor(b[ballNumber].getColor());
		g.fillOval(b[ballNumber].getXCoord(), b[ballNumber].getYCoord(), b[ballNumber].getSize(), b[ballNumber].getSize());
		}
		}
	}

	public static void main(String args[])
	{
		Exercise_15_25 ex = new Exercise_15_25();
		
		JFrame frame = new JFrame();
		
		frame.add(ex);
		
		frame.addWindowListener(
				new WindowAdapter()
				{
					public void windowClosing(WindowEvent e)
					{
						e.getWindow().dispose();
						System.exit(0);
					}
				}
			);
		
		frame.setSize(700, 700);
		frame.setVisible(true);
		while(true)
			if (ex.initialized)
			ex.updatePicture();
	}

If you think you need more please let me know. I have been working on this program, trying to hunt down this specific bug for hours. The goal is to have up to twenty different balls bouncing around on the screen. Thanks.

-- Curtis Sumpter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.