-1

なぜこれが機能しないのか、誰かが私に説明できますか? エラーは Gen クラス内にあるようですが、BoxMan に関係があるのではないかと思います。エラーは、シンボル変数 g が見つからないことを示しています。私もintとdoubleを入れてみましたが、次のようになります: Required (Java.awt.Graphics) Found(int) / (double). では、どうすればこれを修正できますか?私はいたるところを見てきましたが、答えが見つかりません。初心者を助けて!

import java.awt.*;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
import java.lang.Object.*;

       public class JFrame_Test
{
        public static void main (String [] args)
    {
         Gen Gen= new Gen (1500,1000,"A Name"); // this gives parameters for a Jframe later.
    }
}


{
     Gen (int size1, int size2, String title)
     {
     JFrame aFrame = new JFrame (title);
     aFrame.setSize(size1,size2);
     aFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
     aFrame.setVisible(true);
     //aFrame.getContentPane().add(new Canvas());
     //Was trying to get it to work with a canvas
     BoxMan.paint (g); // the error pops up here.
    }
}

public class BoxMan

{
    public Graphics2D g2;
  public void paint(Graphics a ) 
  {
     g2 = (Graphics2D) g; // i even tried declaring "g" here.
     g2.drawRect (10, 10, 200, 200); 
  }
}
4

2 に答える 2