0

このクラスを実行すると、フレームの北中央にグラフが印刷され、中央に配置する方法がわかりません。x の値をさまざまな方法で調整してみましたが、放物線が正しい領域で移動することに気付きました。

class FunctionPlotPanel extends JPanel
{
   protected void paintComponent(Graphics g){
   super.paintComponent(g);

   int x1=0;
   int y1=100;
   int x2=200;
   int y2=100;
   g.drawLine( x1, y1, x2, y2);

   int x11=100;
   int y11=0;
   int x22=100;
   int y22=200;
   g.drawLine(x11, y11, x22, y22);

   Polygon p = new Polygon();

   double scalefactor = 0.1;
   for(int x=-100;x<=100;x++)
   {
      p.addPoint(x+100,100-(int)(scalefactor*x*x));
   }

   int[] xPoints=p.xpoints;
   int[] yPoints=p.ypoints;

   int nPoints=p.npoints;

   g.drawPolyline(xPoints,yPoints,nPoints);
  }
 }
4

1 に答える 1