{
image = getImage(getCodeBase(),\}
public void paint(Graphics g) {
setBackground(Color.lightGray);
g.drawString(\g.drawImage(image,20,30,150,100,this); } }
HTML页面代码如下:
3.Applet代码如下: import java.awt.Graphics; import java.applet.*;
public class SoundApplet extends Applet{ AudioClip soundObj; public void init(){
soundObj=getAudioClip(getCodeBase(),\}
public void paint(Graphics g){
g.drawString(\}
public void start(){ soundObj.loop(); }
public void stop(){ soundObj.stop(); } }
HTML页面代码如下:
4、import java.awt.*; import java.awt.event.*;
class jisuanqi implements ActionListener{ Frame f=new Frame(\计算器\Panel p=new Panel(); Panel p1=new Panel(); Panel p2=new Panel(); Button b=new Button(\Button b1=new Button(\Button b2=new Button(\清除\
Label lbx=new Label(\Label lby=new Label(\TextField tfx=new TextField(4); TextField tfy=new TextField(4); TextArea ta=new TextArea();
Font ft =new Font(\宋体\GridLayout g1=new GridLayout(4,1); GridLayout g2=new GridLayout(2,1); double x,y,sum;
public static void main(String [] args){ jisuanqi ji=new jisuanqi() ; ji.go(); }
public void go(){ b.setFont(ft); b1.setFont(ft); b2.setFont(ft);
lbx.setAlignment(Label.CENTER); lby.setAlignment(Label.CENTER); lbx.setFont(ft); lby.setFont(ft); tfx.setFont(ft); tfy.setFont(ft); ta.setFont(ft);
p.setLayout(g1); p.add(lbx); p.add(tfx); p.add(lby); p.add(tfy); f.add(p,\p1.setLayout(g2); p1.add(b); p1.add(b1);
b.addActionListener(this); b1.addActionListener(this); f.add(p1,\p2.add(b2);
b2.addActionListener(this); f.add(p2,\f.add(ta,\f.setSize(250,150); f.setVisible(true); }
public void actionPerformed(ActionEvent ae){ String s=ae.getActionCommand(); x=Double.parseDouble(tfx.getText()); y=Double.parseDouble(tfy.getText()); if (s.equals(\
ta.append(\}
if (s.equals(\ta.append(\if (s.equals(\清除\ta.setText(\} } }
第九章:、
一、 1、 创建一个有一个文本区域和三个按钮的程序。当我们按下每个按钮时,使不同的文字显示在文
本区域中。
2 编写程序,创建下面的GUI(不必为各组件提供功能)。