Graphics tt;这样tt肯定是null,当然你下面tt.drawLine就会exception了。
应该为:Graphics2D tt=(Graphices2D)g;

解决方案 »

  1.   

    sorry,没看全你的程序,你可以重载paint(Graphics g)函数来实现。
    public void paint(Graphics g){
         super.paint(g);
         Graphics2D tt=(Graphices2D)g;
         //your code here
    }
      

  2.   

    public class frmMain extends JFrame {
      private JPanel contentPane;
      private Border border1;
      private GridBagLayout gridBagLayout1 = new GridBagLayout();
      private JTable jTable1 = new JTable();  //Construct the frame
      public frmMain() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
          Graphics gg;
          gg=this.getGraphics() ;
          DrawRect(gg);
        }
        catch(Exception e) {
          e.printStackTrace();
        }
      }  //
      void DrawRect(Graphics g){
        Graphics2D tt=(java.awt.Graphics2D)g;//执行时候出现空指针异常错误
        tt.drawLine(0,0,10,10) ;
      }
      

  3.   

    刚才发错了,是执行以下语句出现的错误
    tt.drawLine(0,0,10,10) ;