![[Назад]](prev.gif)  | 
   
 
  
     | 
    Исходный текст программы SimpleButton.java
     | 
   
  
    | Оглавление | 
    Назад 
    // ==========================================
// SimpleButton.java
//(C) Alexandr Frolov, 1998
// E-mail: frolov@glasnet.ru
// Web:    http://www.glasnet.ru/~frolov 
// ==========================================
import java.applet.Applet;
import java.awt.*;
public class SimpleButton extends Applet
{
  Button btnYellowBackground;
  Button btnWhiteBackground;
  Button btnDisable;
  Button btnEnable;
  // ==========================================
  // init
  // ==========================================
  public void init()
  {
    btnYellowBackground = 
      new Button("Yellow");
    btnWhiteBackground = new Button("White");
    btnDisable = new Button("Disable");
    btnEnable = new Button("Enable");
    
    add(btnYellowBackground);
    add(btnWhiteBackground);
    add(btnDisable);
    add(btnEnable);
    
    btnEnable.disable();
  }
  
  // ==========================================
  // action
  // ==========================================
  public boolean action(Event evt, Object obj)
  {
    if(evt.target instanceof Button)
    {
      if(
        evt.target.equals(btnYellowBackground))
      {
        setBackground(Color.yellow);
      }
      
      else if(
        evt.target.equals(btnWhiteBackground))
      {
        setBackground(Color.white);
      }
      
      else if(evt.target.equals(btnDisable))
      {
	btnWhiteBackground.disable();
	btnYellowBackground.disable();
	
        btnDisable.disable();
        btnEnable.enable();
      }
      
      else if(evt.target.equals(btnEnable))
      {
	btnWhiteBackground.enable();
	btnYellowBackground.enable();
	
        btnEnable.disable();
        btnDisable.enable();
      }
      repaint();
      return true;
    }
    else
    {
      return false;
    }
  }
  
  // ==========================================
  // getAppletInfo
  // ==========================================
  public String getAppletInfo()
  {
    return "Name: SimpleButton";
  }
}
     
     | 
   
 
  
    ![[Назад]](prev.gif)  | 
   
 
 |