java.awt包提供了基本的java程序的GUI设计工具。主要包括下述三个概念:
组件--Component
容器--Container
布局管理器--LayoutManager
1 package TomAwt; 2 3 4 import java.applet.Applet; 5 import java.awt.*; 6 import java.awt.event.*; 7 public class TomAwt_11 extends Applet implements AdjustmentListener{ 8 Label label1=new Label("0",Label.CENTER); 9 Scrollbar scrollbar1; 10 public void init(){ 11 scrollbar1=new Scrollbar(Scrollbar.HORIZONTAL); 12 scrollbar1.setMinimum(0); 13 scrollbar1.setMaximum(100); 14 //add AdjustmentListener to scrollbar 15 scrollbar1.addAdjustmentListener(this); 16 setLayout(new BorderLayout()); 17 add(label1,BorderLayout.CENTER); 18 add(scrollbar1,BorderLayout.SOUTH); 19 } 20 //implementation of AdjustmentListener 21 public void adjustmentValueChanged(AdjustmentEvent e){ 22 label1.setText(""+scrollbar1.getValue()); 23 } 24 }