home *** CD-ROM | disk | FTP | other *** search
/ Internet 1996 World Exposition / park.org.s3.amazonaws.com.7z / park.org.s3.amazonaws.com / Cdrom / Pavilions / BrainOpera / online / net-music / net-instrument / RectButton.java < prev    next >
Encoding:
Java Source  |  2017-09-21  |  1.2 KB  |  43 lines

  1. import java.awt.*;
  2.  
  3. public class RectButton
  4. {
  5.     int m_iXPos, m_iYPos;
  6.     int m_iWidth, m_iHeight;
  7.     int m_iBorderWidth=1;
  8.     Color m_cMain = Color.white, m_cBorder = Color.black;
  9.  
  10. public RectButton (int iXPos, int iYPos, int iWidth, int iHeight)
  11. {    m_iXPos = iXPos; m_iYPos = iYPos;
  12.     m_iWidth = iWidth; m_iHeight = iHeight;
  13. }
  14.  
  15. //--------------------------------------
  16. // Call this from mouse functions
  17. public boolean bMouseOver (int x, int y)
  18. {    if (x < m_iXPos) return false;
  19.     if (x > m_iXPos + m_iWidth) return false;
  20.     if (y < m_iYPos) return false;
  21.     if (y > m_iYPos + m_iHeight) return false;
  22.     return true;
  23. }
  24.  
  25. //--------------------------------------
  26. // This needs to be called from your paint function.
  27. public void paint (Graphics g, Color cMain, Color cBorder)
  28. {    if (cMain != null) m_cMain = cMain;
  29.     if (cBorder != null) m_cBorder = cBorder;
  30.  
  31.     g.setColor(m_cMain);
  32.     int iX = m_iXPos + m_iBorderWidth, iY = m_iYPos + m_iBorderWidth;
  33.     g.fillRect(iX, iY, m_iWidth - 2*m_iBorderWidth,
  34.         m_iHeight - 2*m_iBorderWidth);
  35.     
  36.     g.setColor(m_cBorder);
  37.     for (int C=0; C<m_iBorderWidth; C++)
  38.         g.draw3DRect(m_iXPos + C, m_iYPos + C, 
  39.             m_iWidth -1-2*C, m_iHeight -1-2*C, true);
  40. }
  41.  
  42. }    // end RectButton
  43.