1

我对Java完全陌生,我在Java代码中画了一面美国国旗,我想知道如何通过拖动窗口大小来调整它的大小(你让窗口变大,旗帜变大,让它变小,旗帜变小) . 我尝试了一切,我得到的只是错误。这是我当前的代码:

import java.applet.*;
import java.awt.*;
import java.awt.geom.*; 

public class MyDrawing extends Applet
{
    public void init() {
         this.setSize(953, 502);
    }
public void paint(Graphics page)
{
 Graphics2D page2=(Graphics2D)page;
 final int TOP = 500;
 final int MID = 475;
 int xx = 38;
 int yx = 380;
 int zx = 570;

 setBackground (Color.red);

 page.setColor (Color.blue);
 page.fillRect (0,0,380,269);

 page.setColor (Color.white);

 int x=0,x1=0,x2=0,x3=0,x4=0,x5=0,x6=0,x7=0,x8=0,x9=0;
 int y=0,y1=0,y2=0,y3=0,y4=0,y5=0,y6=0,y7=0,y8=0,y9=0;

 GeneralPath star = new GeneralPath();

 x=29;x1=54;x2=60;x3=66;x4=91;x5=71;x6=80;x7=x2;x8=40;x9=49;y=50;
 y1=41;y2=25;y3=y1;y4=y;y5=54;y6=y4+25;y7=y5+10;y8=y6;y9=y5;

 x= x / 2;x1= x1 / 2;x2= x2 / 2;x3= x3 / 2;x4= x4 / 2;x5= x5 / 2;x6= x6 / 2;x7= x7 / 2;x8= x8 / 2;x9= x9 / 2;
 y= y / 2;y1= y1 / 2;y2= y2 / 2;y3= y3 / 2;y4= y4 / 2;y5= y5 / 2;y6= y6 / 2;y7= y7 / 2;y8= y8 / 2;y9= y9 / 2;

 int xPoints[] = { x,x1,x2,x3,x4,x5,x6,x7,x8,x9 };
 int yPoints[] = { y,y1,y2,y3,y4,y5,y6,y7,y8,y9 };

 int e = 60;
 int d = 27;

 for (int g=0;g<9;g++)
 {  
    if (g % 2 == 1)
    {
   e=27;
   x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
   e=60;
    }
    else if (g!=0 & g % 2 == 0)
    {
   e=-27;
   x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
   e=60;
    }
    e=60;   
    for (int f=0;f<6;f++)
    {
   xPoints[0]=x;xPoints[1]=x1;xPoints[2]=x2;xPoints[3]=x3;xPoints[4]=x4;xPoints[5]=x5;xPoints[6]=x6;xPoints[7]=x7;xPoints[8]=x8;xPoints[9]=x9;
   yPoints[0]=y;yPoints[1]=y1;yPoints[2]=y2;yPoints[3]=y3;yPoints[4]=y4;yPoints[5]=y5;yPoints[6]=y6;yPoints[7]=y7;yPoints[8]=y8;yPoints[9]=y9;

   star.moveTo( xPoints[ 0 ], yPoints[ 0 ] );

   for ( int k = 1; k < xPoints.length; k++ )
   {
    star.lineTo( xPoints[ k ], yPoints[ k ] );
   }

   star.closePath();
   page2.fill(star);

   x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
    }
    y=y+d;y1=y1+d;y2=y2+d;y3=y3+d;y4=y4+d;y5=y5+d;y6=y6+d;y7=y7+d;y8=y8+d;y9=y9+d;
    e=-360;
    x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
 }

 for (int i=0; i<6; i++)
 {
    page.setColor (Color.white);
    page.fillRect (yx,xx,zx,38);

    xx+= 76;

    if (i==2)
    {
   yx = 0;
   zx = 950;
    }
 }
 page.drawString("By Kirill Shilov",MID-50,TOP-1);
}
}import java.applet.*;
import java.awt.*;
import java.awt.geom.*; 

public class MyDrawing extends Applet
{
    public void init() {
         this.setSize(953, 502);
    }
public void paint(Graphics page)
{
 Graphics2D page2=(Graphics2D)page;
 final int TOP = 500;
 final int MID = 475;
 int xx = 38;
 int yx = 380;
 int zx = 570;

 setBackground (Color.red);

 page.setColor (Color.blue);
 page.fillRect (0,0,380,269);

 page.setColor (Color.white);

 int x=0,x1=0,x2=0,x3=0,x4=0,x5=0,x6=0,x7=0,x8=0,x9=0;
 int y=0,y1=0,y2=0,y3=0,y4=0,y5=0,y6=0,y7=0,y8=0,y9=0;

 GeneralPath star = new GeneralPath();

 x=29;x1=54;x2=60;x3=66;x4=91;x5=71;x6=80;x7=x2;x8=40;x9=49;y=50;
 y1=41;y2=25;y3=y1;y4=y;y5=54;y6=y4+25;y7=y5+10;y8=y6;y9=y5;

 x= x / 2;x1= x1 / 2;x2= x2 / 2;x3= x3 / 2;x4= x4 / 2;x5= x5 / 2;x6= x6 / 2;x7= x7 / 2;x8= x8 / 2;x9= x9 / 2;
 y= y / 2;y1= y1 / 2;y2= y2 / 2;y3= y3 / 2;y4= y4 / 2;y5= y5 / 2;y6= y6 / 2;y7= y7 / 2;y8= y8 / 2;y9= y9 / 2;

 int xPoints[] = { x,x1,x2,x3,x4,x5,x6,x7,x8,x9 };
 int yPoints[] = { y,y1,y2,y3,y4,y5,y6,y7,y8,y9 };

 int e = 60;
 int d = 27;

 for (int g=0;g<9;g++)
 {  
    if (g % 2 == 1)
    {
   e=27;
   x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
   e=60;
    }
    else if (g!=0 & g % 2 == 0)
    {
   e=-27;
   x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
   e=60;
    }
    e=60;   
    for (int f=0;f<6;f++)
    {
   xPoints[0]=x;xPoints[1]=x1;xPoints[2]=x2;xPoints[3]=x3;xPoints[4]=x4;xPoints[5]=x5;xPoints[6]=x6;xPoints[7]=x7;xPoints[8]=x8;xPoints[9]=x9;
   yPoints[0]=y;yPoints[1]=y1;yPoints[2]=y2;yPoints[3]=y3;yPoints[4]=y4;yPoints[5]=y5;yPoints[6]=y6;yPoints[7]=y7;yPoints[8]=y8;yPoints[9]=y9;

   star.moveTo( xPoints[ 0 ], yPoints[ 0 ] );

   for ( int k = 1; k < xPoints.length; k++ )
   {
    star.lineTo( xPoints[ k ], yPoints[ k ] );
   }

   star.closePath();
   page2.fill(star);

   x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
    }
    y=y+d;y1=y1+d;y2=y2+d;y3=y3+d;y4=y4+d;y5=y5+d;y6=y6+d;y7=y7+d;y8=y8+d;y9=y9+d;
    e=-360;
    x=x+e;x1=x1+e;x2=x2+e;x3=x3+e;x4=x4+e;x5=x5+e;x6=x6+e;x7=x7+e;x8=x8+e;x9=x9+e;
 }

 for (int i=0; i<6; i++)
 {
    page.setColor (Color.white);
    page.fillRect (yx,xx,zx,38);

    xx+= 76;

    if (i==2)
    {
   yx = 0;
   zx = 950;
    }
 }
 page.drawString("By Kirill Shilov",MID-50,TOP-1);
}
}
4

0 回答 0