導航:首頁 > 編程語言 > 21點游戲java

21點游戲java

發布時間:2023-01-03 14:38:26

java課程設計源代碼(急!!!!)

import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.SwingConstants;
import javax.swing.border.LineBorder;

public class game21 extends JFrame {
private JLabel label_2;
private int number;
private int sum;
final JLabel label = new JLabel();
final JLabel label_1 = new JLabel();

public static void main(String[] args) {
new game21();
}

public game21() {
super("21點?!");
getContentPane().setLayout(null);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JButton button = new JButton();
button.addActionListener(new ActionListener() {
public void actionPerformed(final ActionEvent arg0) {
onClick();
}
});
button.setText("出牌");
button.setBounds(170, 350, 106, 28);
getContentPane().add(button);
label.setBorder(new LineBorder(Color.black, 1, false));
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setFont(new Font("", Font.BOLD, 26));
label.setText("背面");
label.setBounds(158, 81, 137, 153);
getContentPane().add(label);

label_1.setText("你已經擁有的牌:");
label_1.setBounds(109, 22, 270, 45);
getContentPane().add(label_1);
this.setBounds(200, 300, 501, 528);
this.setVisible(true);
getContentPane().add(getLabel_2());
}

public int randNumber() {
try {
Thread.sleep(10);
} catch (InterruptedException e) {
e.printStackTrace();
}
return (int) (Math.random() * 10 + 1);
}

public void onClick() {
number = this.randNumber();
this.sum += number;
label.setText("" + number);
String strTemp = this.label_1.getText();
strTemp += "" + number + " ";
label_1.setText(strTemp);
String temp = "合計:" + sum;
label_2.setText(temp);
isWin();
}

public void isWin() {
if (sum > 21) {
JOptionPane.showMessageDialog(this, "你輸了");
clear();
return;
} else if (sum == 21) {
JOptionPane.showMessageDialog(this, "你贏了");
clear();
return;
} else {
int i = JOptionPane.showOptionDialog(this, "是否繼續?", "提示",
JOptionPane.OK_CANCEL_OPTION,
JOptionPane.INFORMATION_MESSAGE, null, null, null);
if (i == JOptionPane.OK_OPTION) {
onClick();
} else
return;
}
}

private void clear() {
label_2.setText("合計:");
sum = 0;
number = 0;
label_1.setText("你已經擁有的牌:");
}

/**
* @return
*/
protected JLabel getLabel_2() {
if (label_2 == null) {
label_2 = new JLabel();
label_2.setText("合計:");
label_2.setBounds(313, 35, 66, 18);
}
return label_2;
}

}
真好無聊中。。

㈡ 需要用Java編一個模擬21點紙牌游戲程序

rock [英] [rɒk] [美] [rɑk] n.岩石; 岩; 巨石; 礫石; 卵石; 強壯的人; 堅如磐石的事物; 可靠的人; 冷酷無情的人; 強硬的事物; 錢財; 搖滾樂; 輕輕搖動; 輕輕搖擺; 輕輕搖晃 v.輕輕搖動; 使輕輕擺動; 使輕輕晃動; 跳搖滾舞; 奏搖滾樂; 穿; 炫耀地表現出; 很好; 劇烈震動 [例句] Many types of rock are ejected from volcanoes as solid, fragmentary material. 多種岩石以固體碎屑形式從火山中噴發出來。 [變形] 過去分詞:rocked 現在分詞:rocking 過去式:rocked 第三人稱單數:rocks

㈢ 用Java做21點游戲

就這么點分、還匿名、見得人的東西!~

閱讀全文

與21點游戲java相關的資料

熱點內容
安卓系統藍牙耳機如何用 瀏覽:719
為什麼微信不能給appstore充值 瀏覽:493
程序員的保護動物 瀏覽:272
程序員遇到問題去哪個網站 瀏覽:529
安卓手機空格鍵連續輸入怎麼取消 瀏覽:518
壓縮空氣管道流量計 瀏覽:562
ug編程高級教程 瀏覽:175
什麼叫做伺服器已滿 瀏覽:37
暑假哪有教演算法的 瀏覽:136
密碼學的根基是加密 瀏覽:662
stata方差檢驗命令 瀏覽:337
解壓後文件夾里的內容丟失 瀏覽:715
解壓無敵視頻 瀏覽:690
什麼是伺服器辨認不了 瀏覽:129
java如何調用類方法 瀏覽:483
管理孩子的app叫什麼 瀏覽:546
壓縮活動軌跡 瀏覽:674
6米梁加密筋 瀏覽:79
怎麼學好ps如何學好編程 瀏覽:301
c編譯器廠商 瀏覽:114