picture.java

来自「这是一个买卖系统,一个模拟的系统,根据下订单,看订单,买,等功能」· Java 代码 · 共 65 行

JAVA
65
字号
package Clients;

import java.awt.*;
import java.awt.geom.*;
import javax.swing.ImageIcon;

class Picture extends Canvas
{
  private static final long serialVersionUID = 1;
  private int   width      = 260;
  private int   height     = 260;
  private Image thePicture = null;

  public Picture()
  {
    setSize( width, height );
  }
  
  public Picture(int aWidth, int aHeight)
  {
    width = aWidth;
    height= aHeight;
    setSize( width, height );
  }

  public void set( ImageIcon ic )
  {
    thePicture = ic.getImage();         // Image to be drawn
    repaint();
  }
    
  public void clear()
  {
    thePicture = null;                  // clear picture
    repaint();                          // Force repaint
  }

  public void paint( Graphics g )       // When 'Window' is first
  {                                     //  shown or damaged
    drawImage( (Graphics2D) g );
  }
  
  public void update( Graphics g )      // Called by repaint
  {                                     //
    drawImage( (Graphics2D) g );        // Draw picture
  }

  /**
    * Draw the picture
    * First set the area to white and then 
    *  draw the image 
    */

  public void drawImage( Graphics2D g )
  {
    setSize( width, height );
    g.setPaint( Color.white );
    g.fill( new Rectangle2D.Double( 0, 0, width, height ) );
    if ( thePicture != null )
    {
      g.drawImage(thePicture, 0, 0, null);
    }
  }
}

⌨️ 快捷键说明

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