华容道java代码解释 华容道程序

1200分跪求JAVA数字拼图游戏源代码!1:
import java.io.IOException;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.UnsupportedAudioFileException;
// 华容道原理的拼图游戏 。利用轻组建的套用 。
import java.awt.BorderLayout;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Container;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class MyMainFrame extends JFrame implements ActionListener {
/**
*
*/
private static final long serialVersionUID = 1L;
MyCanvas myCanvas;
JPanel panelNorth,panelPreview;
Button start,preview,set;
Container container;
public MyMainFrame() {//初使化
container=this.getContentPane();
start=new Button("开始");
start.addActionListener(this);
preview=new Button("预览");
preview.addActionListener(this);
set = new Button("设置");
set.addActionListener(this);
panelPreview=new JPanel();
panelPreview.setLayout(null);
Icon icon=new ImageIcon ("images/pic_"+MyCanvas.pictureID+".jpg");
JLabel label=new JLabel(icon);
label.setBounds(0,0,400,400);
panelPreview.add(label);
panelNorth=new JPanel();
panelNorth.setBackground(Color.yellow);
panelNorth.add(start);
panelNorth.add(preview);
panelNorth.add(set);
myCanvas=new MyCanvas();
container.add(myCanvas,BorderLayout.CENTER);
container.add(panelNorth,BorderLayout.NORTH);
this.setTitle("成型拼图小游戏-1212");
this.setLocation(300,200);
this.setSize(408,465);
this.setResizable(false);
this.setVisible(true);
this.setDefaultCloseOperation(3);
}//end of 初始化 构造函数
public void actionPerformed(ActionEvent e) {
Button button=(Button)e.getSource();
if(button==start){
myCanvas.Start();
}else if(button==preview){
if(button.getLabel()=="预览"){
container.remove(myCanvas);
container.add(panelPreview);
panelPreview.updateUI();
container.repaint();
button.setLabel("返回");
}else{
container.remove(panelPreview);
container.add(myCanvas);
container.repaint();
button.setLabel("预览");
}
}else if(button==set){
Choice pic = new Choice();
//pic.add("QQ");
pic.add("美女");
int i=JOptionPane.showConfirmDialog(this,pic,"选择图片", JOptionPane.OK_CANCEL_OPTION);
//使用选择对话框来进行选择图片 。
if(i==JOptionPane.YES_OPTION){
MyCanvas.pictureID=pic.getSelectedIndex()+5;
myCanvas.reLoadPictrue();
Icon icon=new ImageIcon("images/pic_"+MyCanvas.pictureID+".jpg");
JLabel label=new JLabel(icon);
label.setBounds(0,0,400,400);
panelPreview.removeAll();
panelPreview.add(label);
panelPreview.repaint();
}
}
}
public static void main(String[] args) throws UnsupportedAudioFileException, LineUnavailableException, IOException
{
new MyMainFrame();
}//end of main
}
2:
import java.awt.Rectangle;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class MyCanvas extends JPanel implements MouseListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
boolean hasAddActionListener=false;//设置方格的动作监听器的标志位,TRUE为已经添加上动作事件

推荐阅读