java吧 关注:1,235,989贴子:12,704,038
  • 0回复贴,共1

求助,连连看方法怎么写

只看楼主收藏回复

package UI;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.sound.midi.InvalidMidiDataException;
import javax.sound.midi.MidiUnavailableException;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
//这个是主界面的
public class Jiemian extends JFrame {
JButton 设置按钮;
JButton 帮助按钮;
JButton 关于按钮;
JButton 开始按钮;
JButton 刷新按钮;
JButton 提示按钮;
JButton 炸弹按钮;
JButton 演示按钮;
JLabel 界面标签;
public Jiemian(){
//设置窗体***********************************************
this.setTitle("连连看");
this.setSize(830,500);
this.setLocationRelativeTo(null);
this.setLayout(null);
this.setResizable(false);
this.getContentPane().setBackground(Color.lightGray);//
wj();
this.setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//监听****************************************************
设置按钮.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
try {
new Shezhi();
} catch (InvalidMidiDataException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (MidiUnavailableException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
});
帮助按钮.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Bangzhu();
}
});
关于按钮.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
new Guanyu();
}
});
开始按钮.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
dispose();
new Startgame();
}
});
//****************************************************
}
public void wj()
{
设置按钮=new JButton();
this.getContentPane().add(设置按钮);
设置按钮.setBounds(0, 10, 87,30);
帮助按钮=new JButton();
this.getContentPane().add(帮助按钮);
帮助按钮.setBounds(90, 10, 87,30);
关于按钮=new JButton();
this.getContentPane().add(关于按钮);
关于按钮.setBounds(180, 10, 87,30);
开始按钮=new JButton();
this.getContentPane().add(开始按钮);
开始按钮.setBounds(665, 50, 156,48);
刷新按钮=new JButton();
this.getContentPane().add(刷新按钮);
刷新按钮.setBounds(665, 130, 156,48);
提示按钮=new JButton();
this.getContentPane().add(提示按钮);
提示按钮.setBounds(665, 220, 156,48);
炸弹按钮=new JButton();
this.getContentPane().add(炸弹按钮);
炸弹按钮.setBounds(665, 310, 156,48);
演示按钮=new JButton();
this.getContentPane().add(演示按钮);
演示按钮.setBounds(665, 400, 156,48);
界面标签=new JLabel();
this.getContentPane().add(界面标签);
界面标签.setBounds(0, 45, 655,423);
界面标签.setBorder(BorderFactory.createLineBorder(Color.blue));
Icon imgshezhi = new ImageIcon(ClassLoader.getSystemResource("images/setup.gif"));
设置按钮.setIcon(imgshezhi);
Icon imgbangzhu = new ImageIcon(ClassLoader.getSystemResource("images/help.gif"));
帮助按钮.setIcon(imgbangzhu);
Icon imgguanyu = new ImageIcon(ClassLoader.getSystemResource("images/about.gif"));
关于按钮.setIcon(imgguanyu);
Icon kaishi = new ImageIcon(ClassLoader.getSystemResource("images/start.gif"));
开始按钮.setIcon(kaishi);
Icon shuaxin = new ImageIcon(ClassLoader.getSystemResource("images/refresh.gif"));
刷新按钮.setIcon(shuaxin);
Icon tishi = new ImageIcon(ClassLoader.getSystemResource("images/hint.gif"));
提示按钮.setIcon(tishi);
Icon zhadan = new ImageIcon(ClassLoader.getSystemResource("images/bomb.gif"));
炸弹按钮.setIcon(zhadan);
Icon yanshi = new ImageIcon(ClassLoader.getSystemResource("images/demo.gif"));
演示按钮.setIcon(yanshi);
}
public static void main(String args []){
new Jiemian();
}
}
//这个是点开始游戏按钮后的
package UI;
import java.awt.Color;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
public class Startgame extends JFrame {
JButton a;
int index;
JButton wj[][] = new JButton[9][11];//游戏按钮数组
int w [][] = new int [9][11];
public Startgame()
{
Jiemian jm = new Jiemian();
jm.界面标签=new JLabel();
jm.getContentPane().add(jm.界面标签);
jm.界面标签.setBounds(1, 47, 650,418);
jm.界面标签.setBorder(BorderFactory.createLineBorder(Color.yellow));
for(int i=0;i<9;i++)
{
for(int j=0;j<11;j++)
{
wj[i][j]=new JButton();
jm.getContentPane().add(wj[i][j]);
wj[i][j].setBounds(j*50+60,i*45+50,31,34);
}
}
//声明图片**********************************************
for(int i=0;i<9;i++)
{
for(int j=0;j<11;j++)
{
final int randoms=(int)(Math.random()*25+1); //产生随机数
Icon imga = new ImageIcon(ClassLoader.getSystemResource("images/"+(randoms)+".gif"));
wj[i][j].setIcon(imga);
wj[i][j].setName(randoms+"");
//***************************************************
wj[i][j].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JButton jb = (JButton)e.getSource();
String n = jb.getName();
System.out.println(n);
bijiao(Integer.parseInt(n));
}
});
}
}
}
public void bijiao(int f)
{
for(int i=0;i<9;i++)
{
for(int j=0;j<11;j++)
{
if(wj[i][j].getName().equals(f+""))
{
wj[i][j].setVisible(false);
}
}
}
}
public static void main(String [] args)
{
new Startgame();
}
}
求助 这个Startgame 我该怎么写这个游戏的方法


来自iPhone客户端1楼2015-05-19 09:36回复