2008. 4. 7. 12:14

package ex0407;

import java.awt.*;

class ScrollBar1 extends Frame
{
 public ScrollBar1(String str)
 {
 
  super(str);
  Panel c=new Panel();//패널 생성
  Label lbl=new Label("scroll");
  c.add(lbl);//생성된 레이블을 패널안에 삽입
  Scrollbar srb1= new Scrollbar(Scrollbar.VERTICAL,10,100,0,255);
  Scrollbar srb2= new Scrollbar(Scrollbar.HORIZONTAL,10,50,0,255);
  add("West",srb1);
  add("Center",c);
  add("South",srb2);
  setSize(200,200);
  setVisible(true);
  lbl.setBackground(Color.green);//레이블 색상지정
 
 }

 public static void main(String[] args)
 {
  new ScrollBar1("Scroll Ex");
 }

}

2008. 4. 7. 12:10

package ex0407;

import java.awt.*;
import java.awt.event.*;

class ScrollBar2 extends Frame implements AdjustmentListener
{
 /**
  *
  */
 private static final long serialVersionUID = 1L;
 Scrollbar red, green, blue;
 Panel panel1, panel2;
 public ScrollBar2(String str)
 {
  super(str);
  red = new Scrollbar(Scrollbar.VERTICAL, 0, 10,0,255);
  green = new Scrollbar(Scrollbar.VERTICAL, 0, 10,0,255);
  blue = new Scrollbar(Scrollbar.VERTICAL, 0, 10,0,255);
 
  red.addAdjustmentListener(this);
  green.addAdjustmentListener(this);
  blue.addAdjustmentListener(this);
 
  panel1 = new Panel();
  panel2 = new Panel();
  panel1.setSize(200,100);
  panel2.setSize(200,100);
  panel2.add(red);
  panel2.add(green);
  panel2.add(blue);
  add("Center", panel1);
  add("South", panel2);
  setSize(200,200);
  setVisible(true);
 }
 
  public  void adjustmentValueChanged(AdjustmentEvent e)
  {
   panel1.setBackground(new Color(red.getValue(), green.getValue(), blue.getValue()));
  }
  public static void main(String[] args)
  {
   new ScrollBar2("Scroll");
  }
}