1 //package test;2 //Hua_Rong_Road.java
3 import java.awt.*;4 import javax.swing.*;5 import java.awt.event.*;6 public class Hua_Rong_Road extends JFrame implementsMouseListener,KeyListener,ActionListener {7 private Person person[]=new Person[10];8 privateJButton left,right,above,below;9 private JButton restart=new JButton("重新开始");10 private JButton begin=new JButton ("欢迎来到华容道!!"); //标题
11 private final int t_x=50;//起始坐标
12 private final int t_y=100;13 private final int l1=100;//长度
14 private final int l2=15;15 publicHua_Rong_Road() {16 init();17 setBounds(200,200,520,800);18 setVisible(true);19 }20 public voidinit() {21 Color c=new Color(0,255,205);22 begin.setBounds(100, 30, 300,50);23 begin.setBackground(c);24
25 restart.setBounds(150,650,200,50);26 restart.addActionListener(this);27 getContentPane().setLayout(null);28 getContentPane().add(restart);//getContentPane()得到一个内容画板
29 getContentPane().add(begin);30
31 String name[]={"女神吴嘉欣","迷弟一","迷弟二","迷弟三","迷弟四","迷弟五","迷弟六","迷弟七","迷弟八","迷弟九"};32 for(int k=0;k
104 man.setLocation(x,y);105 if (man.getnum()==0&&x==(t_x+l1)&&y==(t_y+3*l1)) {//游戏是否胜利
106 int res=JOptionPane.showConfirmDialog(null, "恭喜你游戏胜利", "是否继续", JOptionPane.YES_NO_OPTION);107 if(res==JOptionPane.YES_OPTION){108 dispose();109 newHua_Rong_Road();110 }111 else return;112 }113 }114 public voidactionPerformed(ActionEvent e) {115 dispose();116 newHua_Rong_Road();117 }118 }