?? 5.txt
字號:
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import javax.swing.*;
public class Applet1 extends Applet {
Button b1,b2;
TextField tf;
Image urlImg;
URL imgurl;
Panel p1;//面板用來放組件:按鈕、標(biāo)簽、文本框。
int i;
public void init(){
//獲取媒體資源
getResource();
urlImg=getImage(imgurl);//加載圖片
setLayout(new BorderLayout());
p1=new Panel();
b1=new Button("按鈕1");
b1.setBackground(Color.red);
b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event){
i=1;
repaint();
}
});
b2=new Button("按鈕2");
b1.setBackground(Color.red);
tf=new TextField(20);
p1.add(b1);
p1.add(b2);
p1.add(tf);
p1.setBackground(Color.white);
add(p1,BorderLayout.SOUTH);
}
public void paint(Graphics g){
super.paint(g);
if(i==1)
g.drawImage(urlImg,1,1,this);
}
private void getResource(){
try{
imgurl=new URL(getCodeBase(),"t-mac.bmp");
}catch(MalformedURLException e) {
e.printStackTrace();
}
}
}
新建HTML文件,輸入<applet code ="Applet1.class" width="500" height="500"></applet>
從而讓applet在web中運行
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -