java.awt包提供了基本的java程序的GUI设计工具。主要包括下述三个概念:
组件--Component
容器--Container
布局管理器--LayoutManager
package TomAwt; import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
public class TomAwt_11 extends Applet implements AdjustmentListener{
Label label1=new Label("0",Label.CENTER);
Scrollbar scrollbar1;
public void init(){
scrollbar1=new Scrollbar(Scrollbar.HORIZONTAL);
scrollbar1.setMinimum(0);
scrollbar1.setMaximum(100);
//add AdjustmentListener to scrollbar
scrollbar1.addAdjustmentListener(this);
setLayout(new BorderLayout());
add(label1,BorderLayout.CENTER);
add(scrollbar1,BorderLayout.SOUTH);
}
//implementation of AdjustmentListener
public void adjustmentValueChanged(AdjustmentEvent e){
label1.setText(""+scrollbar1.getValue());
}
}