repaint one of Jpanels

could anyone help me with solving my repaint problem

When i wont to repaint one of Jpanels i have somthing like that

Exception in thread"Thread-3" java.lang.NullPointerException

at Newton.run(Newton.java:141)

at java.lang.Thread.run(Unknown Source)

MY PROGRAM

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Container;

import java.awt.Dimension;

import java.awt.FlowLayout;

import java.awt.Font;

import java.awt.Graphics;

import java.awt.Graphics2D;

import java.awt.Image;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.geom.Arc2D;

import java.awt.geom.Line2D;

import java.awt.geom.Rectangle2D;

import javax.swing.*;

publicclass Newtonextends JAppletimplements ActionListener,Runnable{

JPanel p1,p2;

JButton b1,b2;

Thread w;

long start,end;

double ww,s,droga;

float M=100,m=0.1f,g=9.81f,tarcie=0,a;

String time="";

Dimension rozmiar;

Image image;

Graphics2D grafika;

Font font =new Font("Serif", Font.PLAIN, 20);

Line2D.Double linia1 =new Line2D.Double();

Line2D.Double linia2 =new Line2D.Double();

Rectangle2D.Double wiekszy =new Rectangle2D.Double();

Rectangle2D.Double mniejszy =new Rectangle2D.Double();

Arc2D.Double arc =new Arc2D.Double(150, 30, 30, 30, 0,90 , Arc2D.OPEN);

publicvoid init(){

w =new Thread(this);

w.start();

a = (( m * g ) + (tarcie * M * g)) / M + m ;

this.setSize(500,500);

rozmiar = getSize();

image = createImage(rozmiar.width,rozmiar.height);

grafika = (Graphics2D) image.getGraphics();

Container c = getContentPane();

c.setLayout(new BorderLayout());

p1 =new JPanel();

p1.setLayout(new FlowLayout());

p2 =new JPanel();

p2.setLayout(new FlowLayout());

b1 =new JButton("TAJ");

b2 =new JButton("new");

p2.add(b1);

p2.add(b2);

c.add(p1,BorderLayout.CENTER);

c.add(p2,BorderLayout.EAST);

}

publicvoid paint(Graphics g){

//grafika = (Graphics2D) p1.getGraphics();

Graphics2D g2 = (Graphics2D)g;

p1.setBackground(new Color(255,255,255));

p2.setBackground(new Color(255,255,0));

//czysczenie bufora

grafika.setColor(new Color(255, 255, 255));

grafika.fillRect(0, 0, rozmiar.width, rozmiar.height);

grafika.setColor(new Color(0, 0, 0));

grafika.setFont(font);

grafika.drawString(time,0,300);

//wozki

wiekszy.setRect(droga,20,30,30);

mniejszy.setRect(175,droga+200,10,10);

grafika.draw(wiekszy);

grafika.draw(mniejszy);

//linie

linia1.setLine(droga+30,30,165,30);

linia2.setLine(180,45,180,droga+200);

grafika.draw(linia1);

grafika.draw(linia2);

grafika.draw(arc);

//podloze

grafika.setColor(Color.BLUE);

grafika.fillRect(0,40,180,20);

//grafika.setStroke(new BasicStroke(10f));

//grafika.drawRect(0,0,200,200);

g2.drawImage(image,0,0,this);

}

publicvoid actionPerformed(ActionEvent e){

// TODO Auto-generated method stub

}

publicvoid run(){

start = System.currentTimeMillis();

while(true){

try{

Thread.sleep(10);

end = System.currentTimeMillis();

}catch(InterruptedException e){

}

ww = (end -start) / 1000D;

s = a*ww*ww/2;

if(s >= 1)break;

//System.out.println(ww);

//time = java.lang.Double.toString(ww);

time = java.lang.Double.toString(s);

droga = droga + s;

p1.repaint();

}

}

}

[6489 byte] By [argola] at [2007-11-27 2:02:34]
# 1
use a debugger
tjacobs01a at 2007-7-12 1:44:08 > top of Java-index,Desktop,Core GUI APIs...
# 2

i use debugger but i really dont konw how to solve it

when i use repaint() it is working but it is alsow repainting panle with buttons

when i use Jpanel.repaint() panel with button is ok but not repainting on the first one

i alsow try to use paintComponent but still dont working

argola at 2007-7-12 1:44:08 > top of Java-index,Desktop,Core GUI APIs...