Электронная библиотека книг Александра Фролова и Григория Фролова.
Shop2You.ru Создайте свой интернет-магазин
Библиотека
Братьев
Фроловых
[Назад]

Исходный текст программы ScrollColor.java

Оглавление

Назад

// ==========================================
// ScrollColor.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web:    http://www.glasnet.ru/~frolov 
// ==========================================

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class ScrollColor extends Applet
{
  // =======================================
  // main
  // =======================================
  public static void main(String args[])
  {
    FrameWindow frame;
    
    frame =  new FrameWindow("Frame window");
    frame.init();
    frame.show();
  }
}

// =======================================
// Class FrameWindow
// =======================================
class FrameWindow extends Frame
  implements AdjustmentListener, WindowListener
{
  Scrollbar scrlRed;
  Scrollbar scrlGreen;
  Scrollbar scrlBlue;
  
  int nRed = 0;
  int nGreen = 0;
  int nBlue = 0;

  // ============================================
  // FrameWindow
  // ============================================
  public FrameWindow(String szTitle)
  {
    super(szTitle);
    setSize(150, 400);
  }

  // ============================================
  // init
  // ============================================
  public void init()
  {
    scrlRed = new Scrollbar(
      Scrollbar.VERTICAL, 0, 10, 0, 255);
      
    scrlGreen = new Scrollbar(
      Scrollbar.VERTICAL, 0, 10, 0, 255);
      
    scrlBlue = new Scrollbar(
      Scrollbar.VERTICAL, 0, 10, 0, 255);
      
    setLayout(new GridLayout(1, 3, 40, 0));
    
    add(scrlRed);
    add(scrlGreen);
    add(scrlBlue);
    
    scrlRed.addAdjustmentListener(this);
    scrlGreen.addAdjustmentListener(this);
    scrlBlue.addAdjustmentListener(this);
    
    this.addWindowListener(this);
    
    setBackground(
      new Color(nRed, nGreen, nBlue));
  }

  // ============================================
  // paint
  // ============================================
  public void paint(Graphics g)
  {
    super.paint(g);
  }
  
  // ============================================
  // adjustmentValueChanged
  // ============================================
  public void adjustmentValueChanged(
    AdjustmentEvent e)
  {
    Scrollbar scrl;
    int nValue;
    
    if(e.getSource() instanceof Scrollbar)
    {
      scrl = (Scrollbar)e.getSource();
      nValue = e.getValue();
      
      if(scrl.equals(scrlRed))
	nRed = nValue;
	
      else if(scrl.equals(scrlGreen))
	nGreen = nValue;
	
      else if(scrl.equals(scrlBlue))
	nBlue = nValue;
	
      setBackground(
        new Color(nRed, nGreen, nBlue));
      repaint();	
    }
  }
  
  // ============================================
  // windowClosing
  // ============================================
  public void windowClosing(WindowEvent e)
  {
    setVisible(false);
    System.exit(0);
  }
  
  public void windowOpened(WindowEvent e) {}
  public void windowClosed(WindowEvent e) {}
  public void windowIconified(WindowEvent e) {}
  public void windowDeiconified(WindowEvent e) {}
  public void windowActivated(WindowEvent e) {}
  public void windowDeactivated(WindowEvent e) {}
}

[Назад]