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