資源簡介
Java聯網雙人對戰的簡單翻牌游戲,具有全屏的gui,awt繪圖,IO流,EXPECTION,
代碼片段和文件信息
package?remembergame;
import?javax.swing.Jframe;
import?javax.swing.JPanel;
import?javax.swing.JLabel;
import?javax.swing.JOptionPane;
import?javax.swing.JTextField;
import?java.awt.Font;
import?java.awt.Graphics;
import?java.awt.Image;
import?java.awt.event.ActionEvent;
import?java.awt.event.ActionListener;
import?java.util.ArrayList;
import?java.util.Collections;
import?java.awt.Color;
import?java.awt.Container;
import?javax.swing.ImageIcon;
import?javax.swing.JButton;
public?class?GameGUI?extends?Jframe?{
private?static?final?long?serialVersionUID?=?5407298675903095654L;
Container?container;
//插入背景圖片
BackgroundPanel?bgd;
JPanel?contentPane;
//計時框
JTextField?textField;
public?JButton?buttonbutton1button2button3button4button5button6button7button8button9button10button11;
//對圖片進行編號
public?int[]?picture?=?{123450012345};
//存入圖片
public?ImageIcon[]?image?=?new?ImageIcon[12];
//初始卡牌背面圖片
public?ImageIcon?nul?=?new?ImageIcon(“picture//99.jpg“);
//當前翻開的卡牌數
private?int?choose?=?0;
//當前已翻開的卡牌
private?int?per1per2;
//記錄已完成的數目以判斷游戲結束
int?win=0;
//當前翻開的卡牌對應的按鈕
public?JButton?buttonXbuttonY;
//記錄卡牌路勁以判斷配對與否
public?String[]?ss?=?new?String[12];
//記錄開始的系統時間
long?starttime?=?System.currentTimeMillis();
//游戲對局信息
public?JTextField?textField_1;
//開局
public?void?start()?{
try?{
//計時
time();
setVisible(true);
}?catch?(Exception?e)?{
e.printStackTrace();
}
}
@SuppressWarnings({?“unchecked“?“rawtypes“?})
//以列表打亂順序
public?int[]?daluan(){
ArrayList?list?=?new?ArrayList();
for(int?i?=?0;i?????????????list.add(picture[i]);???
}
????????????Collections.shuffle(list);
for(int?i?=?0;i? //重新寫入圖片順序
picture[i]?=?(int)?list.get(i);
}
?return?picture;
}
public?void?time(){
//新的線程用于計時,直至游戲結束
new?Thread(){
public?void?run(){
while?(true)?{
textField.setText(“???“+((System.currentTimeMillis()?-?starttime)?/?1000));
}}
}.start();
}
@SuppressWarnings(“static-access“)
//繪制對局界面
public?GameGUI()?{
setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
contentPane?=?new?JPanel();
setContentPane(contentPane);
contentPane.setLayout(null);
bgd?=?new?BackgroundPanel((new?ImageIcon(“picture\\98.jpg“)).getImage());
bgd.setBounds(0020201100);
//將背景添加到底層
contentPane.add(bgd-1);
JLabel?label?=?new?JLabel(“用時:“);
label.setFont(new?Font(“楷體“?Font.BOLD?60));
label.setForeground(Color.GRAY);
label.setBounds(264?67?211?105);
contentPane.add(label0);
textField?=?new?JTextField();
textField.setFont(new?Font(“楷體“?Font.PLAIN?60));
textField.setEditable(false);
textField.setOpaque(false);
textField.setBounds(466?90?225?59);
contentPane.add(textField);
textField.setColumns(10);
getContentPane().add(textField0);
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件??????????0??2017-11-28?16:06??Online_game\.me
?????文件??????76174??2017-12-24?11:28??Online_game\.me
?????文件?????????20??2017-11-28?16:07??Online_game\.me
?????文件?????????32??2017-11-28?16:07??Online_game\.me
?????文件????????235??2017-12-24?13:49??Online_game\.me
?????文件????????561??2017-11-28?16:08??Online_game\.me
?????文件????????235??2017-12-24?14:11??Online_game\.me
?????文件??????10478??2017-12-24?04:38??Online_game\.me
?????文件???????5845??2017-12-24?05:25??Online_game\.me
?????文件??????11053??2017-12-24?04:27??Online_game\.me
?????文件??????10494??2017-12-24?05:24??Online_game\.me
?????文件??????10588??2017-12-24?05:30??Online_game\.me
?????文件???????7026??2017-12-24?12:45??Online_game\.me
?????文件??????10630??2017-12-24?11:37??Online_game\.me
?????文件???????6967??2017-12-24?11:58??Online_game\.me
?????文件???????6543??2017-12-24?05:42??Online_game\.me
?????文件??????10471??2017-12-24?04:41??Online_game\.me
?????文件???????5849??2017-12-24?05:27??Online_game\.me
?????文件???????7020??2017-12-24?12:11??Online_game\.me
?????文件??????10741??2017-12-24?04:36??Online_game\.me
?????文件??????11085??2017-12-24?04:31??Online_game\.me
?????文件??????10922??2017-12-24?04:09??Online_game\.me
?????文件???????8147??2017-12-24?14:12??Online_game\.me
?????文件??????11482??2017-12-24?13:11??Online_game\.me
?????文件???????7914??2017-12-24?13:11??Online_game\.me
?????文件??????10695??2017-12-24?04:58??Online_game\.me
?????文件??????11482??2017-12-24?13:11??Online_game\.me
?????文件???????7940??2017-12-24?13:05??Online_game\.me
?????文件???????7070??2017-12-24?12:50??Online_game\.me
?????文件??????11455??2017-12-24?12:23??Online_game\.me
............此處省略587個文件信息
- 上一篇:Java程序性能優化
- 下一篇:Swing實現的QQ最終版
評論
共有 條評論