⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 emptybutton.java

📁 sound recorder which supports .wav format files
💻 JAVA
字号:
package com.vimas.interfaceapplet.buttons;

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

/**
 * OpenlookButton - a class that produces a lightweight button.
 *
 * Lightweight components can have "transparent" areas, meaning that
 * you can see the background of the container behind them.
 *
 */
public class EmptyButton extends Component
{

  int param=70;
  static int capWidth = 20;          // The width of the Button's endcap
  protected boolean pressed = false; // true if the button is detented.
  ActionListener actionListener;     // Post action events to listeners
  protected boolean isEnabled = true;// is button enabled
  protected boolean isSunkable=false;// can bunnon sunk, like pause
  protected int clickNum=0;// number of click for sunking bunnons
//******************************************************************************
  public EmptyButton(int param)
  {
    this.param=param;
  }
//******************************************************************************
  public void paint(Graphics g) {
      int width = getSize().width - 1;
      int height = getSize().height - 1;


      Color interior;
      Color highlight1;
      Color highlight2;

      interior = getBackground();

      // ***** determine what colors to use
      if(pressed) {
	  highlight1 = interior.darker();
	  highlight2 = interior.brighter();
      } else {
	  highlight1 = interior.brighter();
	  highlight2 = interior.darker();
      }

      // ***** paint the interior of the button
      g.setColor(interior);
      g.fillRect(0,0,width, height);
      // ***** highlight the perimeter of the button
      // draw upper and lower highlight lines

      g.setColor(highlight1);
      g.drawLine(0, 0, width, 0);
      g.drawLine(0, 0, 0, height);
      g.setColor(highlight2);
      g.drawLine(0, height, width, height);
      g.drawLine(width, 0,width, height);

      if(!isEnabled)
        g.setColor(interior.darker());
      else
        g.setColor(getForeground());
      this.drawMyImage(g,param);
    }
//*****************************************************************************
  protected void drawMyImage(Graphics g, int param)
  {
    int x1=(int)param/4;
    int[] x=new int[]{x1,x1,3*x1};
    int[] y=new int[]{x1,3*x1,2*x1};
    g.fillPolygon(x,y,3);
  }
//*****************************************************************************
  public Dimension getPreferredSize()
  {
      return new Dimension(param, param);
  }
//*****************************************************************************
  public Dimension getMinimumSize() {
      return new Dimension(param, param);
  }
//*****************************************************************************
   public void addActionListener(ActionListener listener) {
       actionListener = AWTEventMulticaster.add(actionListener, listener);
       enableEvents(AWTEvent.MOUSE_EVENT_MASK);
   }
//*****************************************************************************
   public void removeActionListener(ActionListener listener) {
       actionListener = AWTEventMulticaster.remove(actionListener, listener);
   }
//*****************************************************************************
   public void processMouseEvent(MouseEvent e) {
     if(!isEnabled)return;
       Graphics g;
       switch(e.getID()) {
          case MouseEvent.MOUSE_PRESSED:
            // render myself inverted....
            pressed = true;

	    // Repaint might flicker a bit. To avoid this, you can use
	    // double buffering (see the Gauge example).
	    repaint();
            break;
          case MouseEvent.MOUSE_RELEASED:
            if(actionListener != null) {
               actionListener.actionPerformed(new ActionEvent(
                   this, ActionEvent.ACTION_PERFORMED,""));
            }
            if(isSunkable)
              {
                clickNum++;
                if (clickNum == 2)
                {
                  clickNum=0;
                  pressed=false;
                  repaint();
                }
              }
            else
            {
              if(pressed)
              {
                pressed = false;
                repaint();
              }
            }
            break;
          case MouseEvent.MOUSE_ENTERED:

            break;
          case MouseEvent.MOUSE_EXITED:
              if(!isSunkable&&pressed)
              {
                pressed = false;
                repaint();
              }

            break;
       }
       super.processMouseEvent(e);
   }
//*****************************************************************************
  public boolean isEnabled()
  {
    return isEnabled;
  }
//*****************************************************************************
  public void setEnabled(boolean isEnabled)
  {
    this.isEnabled = isEnabled;
    this.repaint();
  }
//*****************************************************************************
  public void setSunkable(boolean isSunkable)
  {
    this.isSunkable = isSunkable;
  }
//*****************************************************************************
   public void releaseButton()
   {
     if (isSunkable)
     {
       clickNum = 0;
       pressed=false;
       repaint();
     }
   }
//*****************************************************************************
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -