
//Title:       Trappomkopplare
//Version:
//Copyright:   Copyright (c) 1998
//Author:      Mikael Bonnier
//Company:     Orbin
//Description: Your description
package trappomk;

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

//import com.sun.java.swing.UIManager;
public class TrappOmkDemo extends Applet
{
  boolean isStandalone = false;
  LampButton lampKnapp1 = new LampButton();
  LampButton lampKnapp2 = new LampButton();

  boolean on = false;

  void toggleLight()
  {
    if(on)
    {
      this.setBackground(Color.black);
    }
    else
    {
      this.setBackground(Color.yellow);
      Toolkit.getDefaultToolkit().beep();
    }
    on = !on;
  }

  //Construct the applet

  public TrappOmkDemo()
  {
  }
//Initialize the applet

  public void init()
  {
    try
    {
    jbInit();
    }
    catch (Exception e)
    {
    e.printStackTrace();
    }
  }
  //static {
  //  try {
  //    //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.metal.MetalLookAndFeel());
  //    //UIManager.setLookAndFeel(new com.sun.java.swing.plaf.motif.MotifLookAndFeel());
  //    UIManager.setLookAndFeel(new com.sun.java.swing.plaf.windows.WindowsLookAndFeel());
  //  }
  //  catch (Exception e) {}
  //}
//Component initialization

  private void jbInit() throws Exception
  {
    lampKnapp1.setBounds(new Rectangle(64, 101, 114, 53));
    lampKnapp1.addActionListener(lampKnapp1);
    lampKnapp2.setBounds(new Rectangle(222, 101, 118, 57));
    lampKnapp2.addActionListener(lampKnapp2);
    this.setLayout(null);
    this.setSize(400,300);
    this.add(lampKnapp1, null);
    this.add(lampKnapp2, null);
    this.setBackground(Color.black);
  }
//Start the applet

  public void start()
  {
  }
//Stop the applet

  public void stop()
  {
  }
//Destroy the applet

  public void destroy()
  {
  }
//Get Applet information

  public String getAppletInfo()
  {
    return "Applet Information";
  }
//Get parameter info

  public String[][] getParameterInfo()
  {
    return null;
  }
//Main method

  public static void main(String[] args)
  {
    TrappOmkDemo applet = new TrappOmkDemo();
    applet.isStandalone = true;
    Frame frame = new Frame();
    frame.setTitle("Applet Frame");
    frame.add(applet, BorderLayout.CENTER);
    applet.init();
    applet.start();
    frame.setSize(400,320);
    Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
    frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
    frame.setVisible(true);
  }
}

class LampButton extends Button implements ActionListener
{
  static final Color darkgreen = new Color(0x008000);
  boolean up = false;

  LampButton()
  {
    this.setLabel("Ner");
    this.setForeground(LampButton.darkgreen);
  }

  public void actionPerformed(ActionEvent e)
  {
    TrappOmkDemo pnl = (TrappOmkDemo)this.getParent();
    if(up)
    {
      this.setForeground(Color.red);
      this.setLabel("Ner");
    }
    else
    {
      this.setForeground(darkgreen);
      this.setLabel("Upp");
    }
    pnl.toggleLight();
    up = !up;
  }
}

