java连连看⼩游戏代码⼤全_连连看⼩游戏java源代码(1)//MainView 主界⾯
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.*;
public class MainView extends JFrame implements ActionListener{
private static final long serialVersionUID = -8711256543675730570L;
public static JLabel fractionLable=new JLabel("0"); //分数标签
public static int count =0;
private JMenuBar menuBar;
private JMenu menu;
private JMenuItem MenuItem1;
private JMenuItem MenuItem2;
private JMenuItem MenuItem3;
private JButton exitButton,newlyButton; //退出,重列,重新开始按钮
private JPanel centerPanel,pane5;
private JPanel northPanel;
private int row = 7;
private int col = 8;
private MyThread myThread;
private int time = 100; //单位为秒
private JProgressBar aJProgressBar;
public MainView(){
initView();
}
private void initView(){
centerPanel = new JPanel();
centerPanel.setLayout(new BorderLayout());
centerPanel.add(pane5,BorderLayout.SOUTH);
JPanel mainPanel=new JPanel();
setNorthPanel();
mainPanel.add(northPanel,BorderLayout.NORTH);
mainPanel.add(centerPanel,BorderLayout.SOUTH);
myThread = new MyThread(){
protected void runPersonelLogic(){
int minimum = Minimum();
Value() != minimum){
int value = Value();
System.out.println(value);
try {
Thread.sleep(1000);
代码要用什么才能打开aJProgressBar.Value() - 1);
} catch (InterruptedException e){
e.printStackTrace();
}
if(count ==row*col/2){
this.setSuspend(true);
int i= JOptionPane.showConfirmDialog
(null,"恭喜过关了,是否继续?", "游戏提⽰", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
if(i==0){
this.setSuspend(false);
pane5 =new CenterPanel(row,col);
centerPanel.add(pane5);
count = 0;
aJProgressBar.setValue(time);
}
}
}else{
int i =JOptionPane.showOptionDialog
(null,"⼤侠,时间到了!","游戏提⽰",JOptionPane.OK_CANCEL_OPTION, JOptionPane.INFORMATION_MESSAGE,null,
new String[]{"重来","取消"},"重来");
if(i==0){
restart();
}
}
}
};
myThread.start();
this.addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent e){
}
});
this.setJMenuBar();
this.setTitle("连连看");
this.setVisible(true);
this.setBounds(280,100,600,650);
this.setResizable(false);
}
private void setJMenuBar() {
MenuItem1 = new JMenuItem("重新开始");
MenuItem1.addActionListener(this);
MenuItem2 = new JMenuItem("关于");
MenuItem2.addActionListener(this);
MenuItem3 = new JMenuItem("退出");administrator已锁定怎么解除
MenuItem3.addActionListener(this);
menu = new JMenu("菜单");
menuBar = new JMenuBar();
menu.add(MenuItem1);
menu.add(MenuItem3);
menuBar.add(menu);
this.setJMenuBar(menuBar);
html空白单元格
}
private void setNorthPanel(){
northPanel=new JPanel();
northPanel.setLayout(new FlowLayout());
northPanel.add(new JLabel("分数:"));
northPanel.add(fractionLable);
northPanel.add(new JLabel("时间:"));
aJProgressBar = new JProgressBar(0,time);
aJProgressBar.setValue(time);
aJProgressBar.setStringPainted(true);
aJProgressBar.setBackground(Color.white);
aJProgressBar.d);
northPanel.add(aJProgressBar);
exitButton=new JButton("退出");
exitButton.addActionListener(this);
newlyButton=new JButton("再来⼀局");
newlyButton.addActionListener(this);
northPanel.add(exitButton);
northPanel.add(newlyButton);
}
public static void main(String args[]){
java手机游戏下载new MainView();
}
public void actionPerformed(ActionEvent e) {
Source()==exitButton||e.getActionCommand().equals("退出")){ it(0);
}
Source()==newlyButton||e.getActionCommand().equals("重新开始")){ restart();
}
private void restart() {
fractionLable.setText("0");
if(pane5 != null){
}
pane5 =new CenterPanel(row,col);
centerPanel.add(pane5);
count = 0;
aJProgressBar.setValue(time);
myThread.setSuspend(false);
}
}
//⾃写的button按钮
import java.awt.Insets;
import javax.swing.JButton;
public class MyButton extends JButton {
private static final long serialVersionUID = -7656457111448117368L; private int row;
private int col;
private int pictrueId;
private boolean isBlank;
private boolean isCleaned = false;
public MyButton(int row,int col,int pictrueId){
this.pictrueId = pictrueId;
this.setMargin(new Insets(0,0,0,0));
}
public MyButton() {
}
public int getRow() {
return row;
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论