PreviewPanel.java
上传用户:liming9091
上传日期:2014-10-27
资源大小:3376k
文件大小:3k
源码类别:

Java编程

开发平台:

Java

  1. package russiagame;
  2. /**
  3.  * <p>Title: </p>
  4.  * <p>Description: </p>
  5.  * <p>Copyright: Copyright (c) 2003</p>
  6.  * <p>Company: </p>
  7.  * @author not attributable
  8.  * @version 1.0
  9.  */
  10. import javax.swing.*;
  11. import java.awt.*;
  12. import java.awt.event.*;
  13. public class PreviewPanel extends Panel {
  14.     private GameTable gPreviewTable;
  15.     private Image myImage0, myImage1; //加载两个图片,用来覆盖背景和组成方块
  16.     private int intWhich;
  17.     public PreviewPanel(PreviewTable gPreviewTable) {
  18.         intWhich = 0;
  19.         myImage0 = getToolkit().getImage("b0.jpg");
  20.         myImage1 = getToolkit().getImage("b1.jpg");
  21.     }
  22.     public void PreviewGraph(int intWhich) {
  23.         this.intWhich = intWhich;
  24.         this.repaint();
  25.     }
  26.     public void paint(Graphics g) { //画下一个提前显示的方块
  27.         for (int i = 0; i < 5; i++) //先全部用白方块覆盖
  28.             for (int j = 0; j < 4; j++)
  29.                 g.drawImage(myImage0, 0 + i * (15 + 2), 0 + j * (15 + 2), this);
  30.         switch (intWhich) { //根据标志决定画哪个方块,画蓝方块
  31.             case 1:
  32.                 g.drawImage(myImage1, 34, 0, this);
  33.                 g.drawImage(myImage1, 34, 17, this);
  34.                 g.drawImage(myImage1, 34, 34, this);
  35.                 g.drawImage(myImage1, 34, 51, this);
  36.                 break;
  37.             case 2:
  38.                 g.drawImage(myImage1, 17, 17, this);
  39.                 g.drawImage(myImage1, 17, 34, this);
  40.                 g.drawImage(myImage1, 34, 17, this);
  41.                 g.drawImage(myImage1, 34, 34, this);
  42.                 break;
  43.             case 3:
  44.                 g.drawImage(myImage1, 17, 17, this);
  45.                 g.drawImage(myImage1, 17, 34, this);
  46.                 g.drawImage(myImage1, 34, 0, this);
  47.                 g.drawImage(myImage1, 34, 17, this);
  48.                 break;
  49.             case 4:
  50.                 g.drawImage(myImage1, 17, 0, this);
  51.                 g.drawImage(myImage1, 17, 17, this);
  52.                 g.drawImage(myImage1, 34, 17, this);
  53.                 g.drawImage(myImage1, 34, 34, this);
  54.                 break;
  55.             case 5:
  56.                 g.drawImage(myImage1, 17, 0, this);
  57.                 g.drawImage(myImage1, 17, 17, this);
  58.                 g.drawImage(myImage1, 17, 34, this);
  59.                 g.drawImage(myImage1, 34, 0, this);
  60.                 break;
  61.             case 6:
  62.                 g.drawImage(myImage1, 17, 0, this);
  63.                 g.drawImage(myImage1, 34, 0, this);
  64.                 g.drawImage(myImage1, 34, 17, this);
  65.                 g.drawImage(myImage1, 34, 34, this);
  66.                 break;
  67.             case 7:
  68.                 g.drawImage(myImage1, 34, 17, this);
  69.                 g.drawImage(myImage1, 34, 34, this);
  70.                 g.drawImage(myImage1, 17, 34, this);
  71.                 g.drawImage(myImage1, 51, 34, this);
  72.                 break;
  73.             case 8:
  74.                 g.drawImage(myImage1, 34, 17, this);
  75.                 break;
  76.             default:
  77.                 break;
  78.         }
  79.     }
  80. }