java 运行的时候总是出现“未初始化小应用程序”,这是为什么呢?
packagely;importjava.applet.Applet;importjava.awt.Color;importjava.awt.Graphics;impor...
package ly;
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageProducer;
import java.awt.image.MemoryImageSource;
public class filling extends Applet{
int red = Color.red.getRGB();
Image image;
double dy,dx;
int ymax,ymin;
int x,y;
int w=80,h=70;
int[] pixels= new int[w*h];
int p[][]=new int [4][2];
public void init() //初始化
{
p[0][0]=20;
p[0][1]=70;
p[1][0]=50;
p[1][1]=20;
p[2][0]=70;
p[2][1]=90;
p[3][0]=100;
p[3][1]=60;
image = boundary();
image = interior();
}
public void paint(Graphics g){
g.drawImage(image,0,0,null);
}
public Image boundary()
{
int i;
for(i=0;i<4;i++)
{
dy=p[i+1][1]-p[i][1];
dx=(p[i+1][0]-p[i][0])/dy;
if(dy>0)
x=p[i][0];
else x=p[i+1][0];
ymax=(Math.max(p[i][1],p[i+1][1]));
ymin=(Math.min(p[i][1],p[i+1][1]));
for(y=ymin+1;y<=ymax;y++)
{
x=(int)(x+dx+.5);
if(pixels[y*w+x]==red)
pixels[y*w+x+1]=red;
else pixels[y*w+x]=red;
}
}
ImageProducer ip=new MemoryImageSource(w,h,pixels,0,w);
image=createImage(ip);
return image;
}
public Image interior()
{
int l;
int maxx=100;
int minx=20;
int maxy=90;
int miny=20;
int in_flag;
for(y=miny-1;y<=maxy;y++)
{
in_flag=0;
for(x=minx-1;x<maxx;x++)
{
l=pixels[y*w+x];
if(l==red)
{
if(in_flag==0)
in_flag=1;
else in_flag=0;
}
if(in_flag==1)
pixels[y*w+x]=red;
}
}
ImageProducer ip=new MemoryImageSource(w,h,pixels,0,w);
image=createImage(ip);
return image;
}
} 展开
import java.applet.Applet;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.ImageProducer;
import java.awt.image.MemoryImageSource;
public class filling extends Applet{
int red = Color.red.getRGB();
Image image;
double dy,dx;
int ymax,ymin;
int x,y;
int w=80,h=70;
int[] pixels= new int[w*h];
int p[][]=new int [4][2];
public void init() //初始化
{
p[0][0]=20;
p[0][1]=70;
p[1][0]=50;
p[1][1]=20;
p[2][0]=70;
p[2][1]=90;
p[3][0]=100;
p[3][1]=60;
image = boundary();
image = interior();
}
public void paint(Graphics g){
g.drawImage(image,0,0,null);
}
public Image boundary()
{
int i;
for(i=0;i<4;i++)
{
dy=p[i+1][1]-p[i][1];
dx=(p[i+1][0]-p[i][0])/dy;
if(dy>0)
x=p[i][0];
else x=p[i+1][0];
ymax=(Math.max(p[i][1],p[i+1][1]));
ymin=(Math.min(p[i][1],p[i+1][1]));
for(y=ymin+1;y<=ymax;y++)
{
x=(int)(x+dx+.5);
if(pixels[y*w+x]==red)
pixels[y*w+x+1]=red;
else pixels[y*w+x]=red;
}
}
ImageProducer ip=new MemoryImageSource(w,h,pixels,0,w);
image=createImage(ip);
return image;
}
public Image interior()
{
int l;
int maxx=100;
int minx=20;
int maxy=90;
int miny=20;
int in_flag;
for(y=miny-1;y<=maxy;y++)
{
in_flag=0;
for(x=minx-1;x<maxx;x++)
{
l=pixels[y*w+x];
if(l==red)
{
if(in_flag==0)
in_flag=1;
else in_flag=0;
}
if(in_flag==1)
pixels[y*w+x]=red;
}
}
ImageProducer ip=new MemoryImageSource(w,h,pixels,0,w);
image=createImage(ip);
return image;
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询