import java.applet.* ; import java.awt.* ; public class demo03e extends Applet { ctrlPanel1 myPanel1 = new ctrlPanel1() ; ctrlPanel2 myPanel2 = new ctrlPanel2() ; Scrollbar scV = new Scrollbar(Scrollbar.VERTICAL,50,10,0,100+10) ; Scrollbar scH = new Scrollbar(Scrollbar.HORIZONTAL,50,10,0,100+10) ; myCanvas drawingCanvas = new myCanvas() ; public void init() { // 全体はBorderLayoutで配置 setLayout(new BorderLayout()) ; add("North", myPanel1) ; add("West", myPanel2) ; add("East", scV) ; add("South", scH) ; add("Center", drawingCanvas) ; } // class内にもclassを作成可能 class ctrlPanel1 extends Panel { public Button bt1, bt2, bt3 ; // このパネルはGridLayoutで横1行に配置 public ctrlPanel1() { setLayout(new GridLayout(1,3)) ; bt1 = new Button("Button(1)") ; bt2 = new Button("Button(2)") ; bt3 = new Button("Button(3)") ; add(bt1) ; add(bt2) ; add(bt3) ; } } class ctrlPanel2 extends Panel { public Checkbox cb1, cb2, cb3 ; // このパネルはGridLayoutで縦1列に配置 public ctrlPanel2() { setLayout(new GridLayout(3,1)) ; cb1 = new Checkbox("Check(1)") ; cb2 = new Checkbox("Check(2)") ; cb3 = new Checkbox("Check(3)") ; add(cb1) ; add(cb2) ; add(cb3) ; } } class myCanvas extends Canvas { public myCanvas() { setBackground(Color.black) ; setForeground(Color.white) ; } public void paint(Graphics g) { int w, h ; w = getSize().width ; h = getSize().height ; g.drawString("My Canvas",w/2-30,h/2) ; } } }