?? nancheng2.java
字號(hào):
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
import java.net.*;
public class nancheng2 extends Applet
{
int m=18,n=22,j=0;URL url1;
Image image0,image1,image2,image3;
GridBagLayout g=new GridBagLayout();
GridBagConstraints c=new GridBagConstraints();
Font font1=new Font(" TimesRoman",Font.BOLD,12);
Font font2=new Font(" TimesRoman",Font.PLAIN,14);
Font font3=new Font(" TimesRoman",Font.BOLD,26);
Label lb=new Label(" 歡迎進(jìn)入貪吃蛇世界");
Panel p1,p2;Graphics g1,g2;
Image image;URL codeBase,theURL;
String url="nancheng.htm";
public void init()
{ setBackground(Color.white);
this.setLayout(g);
p1=new Panel();p2=new Panel();
addlabel(m,n,this,"*");
url1=getCodeBase();
image1=getImage(url1,"welcom.gif");
image0=getImage(url1,"shengdan.gif");
location(6,6,11,4,p1);
p1.setLayout(g);p2.setLayout(g);
addlabel(4,13,p1," ");
addlabel(10,17,p2," ");
lb.setFont(font3);lb.setForeground(Color.blue);
location2(2,1,8,2,lb,p1);
g1=p1.getGraphics();g2=p2.getGraphics();
codeBase=getCodeBase();
try{
theURL=new URL(getDocumentBase(),url);
}catch(MalformedURLException e){}; //捕獲URL異常
}
public void paint(Graphics g)
{
image=getImage(codeBase,"01s.jpg");
g.drawImage(image,100,50,150,150,this);
try{
Thread.sleep(1000);
}catch(InterruptedException e){}
getAppletContext().showDocument(theURL);
}
public void addlabel(int m,int n,Panel p,String str)
{ int i,j;
for (i=0;i<m;i++)
for(j=0;j<n;j++)
{
Label label=new Label(str);
label.setFont(font1);
label.setForeground(Color.pink);
if (j==n-1)c.gridwidth=GridBagConstraints.REMAINDER;
location2(j,i,1,1,label,p);
if (i>=1&&i<m-1)j=j+n-2;
}
}
public void location2(int x,int y,int gx,int gy,Component b,Panel p)
{
c.gridx=x;c.gridy=y;
c.gridwidth=gx;c.gridheight=gy;
p.add(b);g.setConstraints(b,c);
}
public void location(int x,int y,int gx,int gy,Component b)
{
c.gridx=x;c.gridy=y;
c.gridwidth=gx;c.gridheight=gy;
add(b);g.setConstraints(b,c);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -