Ejemplo n.º 1
0
 demo5() {
   f = new Frame();
   f.setSize(300, 300);
   // f.setBackground(Color.red);
   f.setLayout(null);
   s1 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260);
   s1.setBackground(Color.red);
   s1.setBounds(30, 35, 20, 255);
   s2 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260);
   s2.setBackground(Color.green);
   s2.setBounds(60, 35, 20, 255);
   s3 = new Scrollbar(Scrollbar.VERTICAL, 0, 5, 0, 260);
   s3.setBackground(Color.blue);
   s3.setBounds(90, 35, 20, 255);
   f.add(s1);
   f.add(s2);
   f.add(s3);
   s1.addAdjustmentListener(this);
   s2.addAdjustmentListener(this);
   s3.addAdjustmentListener(this);
   p1 = new Panel();
   p1.setBounds(120, 35, 170, 255);
   f.add(p1);
   f.setVisible(true);
 }
Ejemplo n.º 2
0
  public void init() {

    /*
     * O construtor usado cria "uma barra" com valor inicial 0,
     * de largura 10 pixels, valor m�ni,o poss�vel 0 e m�ximo 265
     * como a barra de rolagem tem 10 pixels, seu canto inferior
     * esquerdo d� pode chegar ate 255 (valor m�ximo em RGB)
     */
    redScroll = new Scrollbar(Scrollbar.HORIZONTAL, 0, 10, 0, 265);
    greenScroll = new Scrollbar(Scrollbar.HORIZONTAL, 0, 10, 0, 265);
    blueScroll = new Scrollbar(Scrollbar.HORIZONTAL, 0, 10, 0, 265);

    /* Create Labels showing current RGB and HSB values. */
    redLabel = new Label(" R = 0");
    greenLabel = new Label(" G = 0");
    blueLabel = new Label(" B = 0");

    /* Set background colors for Scrollbars and Labels, so they don't
      inherit the gray background of the applet.
    */

    redScroll.setBackground(Color.lightGray);
    greenScroll.setBackground(Color.lightGray);
    blueScroll.setBackground(Color.lightGray);

    redLabel.setBackground(Color.white);
    greenLabel.setBackground(Color.white);
    blueLabel.setBackground(Color.white);

    /* Set the applet to listen for changes to the Scrollbars' values */ redScroll
        .addAdjustmentListener(this);
    greenScroll.addAdjustmentListener(this);
    blueScroll.addAdjustmentListener(this);

    /* Create a canvas whose background color will always be set to the currently selected color. */ colorCanvas =
        new Canvas();
    colorCanvas.setBackground(Color.black);

    /* Create the applet layout, which consists of a row of three equal-sized regions holding the Scrollbars, the Labels, and the color patch. The background color of the applet is gray, which will show around the edges and between components. */

    setLayout(new GridLayout(1, 3, 3, 3));
    setBackground(Color.gray);

    Panel scrolls = new Panel();
    Panel labels = new Panel();
    add(scrolls);
    add(labels);
    add(colorCanvas);

    /* Add the Scrollbars and the Labels to their respective panels. */

    scrolls.setLayout(new GridLayout(3, 1, 2, 2));
    scrolls.add(redScroll);
    scrolls.add(greenScroll);
    scrolls.add(blueScroll);

    labels.setLayout(new GridLayout(3, 1, 2, 2));
    labels.add(redLabel);
    labels.add(greenLabel);
    labels.add(blueLabel);

    setSize(new Dimension(500, 100));
    // curiosamente, aqui n�o funcionou setPreferredSize() !!!
  } // end init();