import java.awt.Cursor;
import java.awt.Font;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.*;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import org.jvnet.substance.skin.SubstanceGreenMagicLookAndFeel;
import org.jvnet.substance.skin.SubstanceGreenMagicLookAndFeel;
public class Game extends JFrame {
/**
*
*/
private static final long serialVersionUID = -1038922514275248123L;
/**
* @param args
*/
public JButton pButtonOne,pButtonTwo,pButtonThree,pButtonFour;
public JButton fButtonJia,fButtonJian,fButtonCheng,fButtonChu,fButtonZKuo,fButtonYKuo;
public JTextField text;
public JButton okButton,cancelButton;
public Icon icon1,icon2,icon3,icon4;
public String path1=null,path2=null,path3=null,path4=null;
public String s=""; //定义输出的字符串
public JButton startButton,nextButton; //定义确定,撤销按钮
public int a,b,c,d; //定义四个随机数
String aPath="",bPath="",cPath="",dPath=""; //定义四张图片的路径
Thread thread;
boolean isClicked=false;
////////////////////////////////////////////////////////////////////////////////////////////////
public void init(){
/*////////////////////////////////////////////////////////
try{
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
SwingUtilities.updateComponentTreeUI(this);
}catch(Exception exe){
exe.printStackTrace();
}*/
////////////////////////////////////////
try {
UIManager.setLookAndFeel(new SubstanceGreenMagicLookAndFeel());
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
this.setTitle("24点");
this.setBounds(300,50,800,600);
this.setVisible(true);
path1="first.jpg";
path2="first.jpg";
path3="first.jpg";
path4="first.jpg";
Image img=Toolkit.getDefaultToolkit().getImage("10.JPG");
this.setIconImage(img);
icon1 = new ImageIcon(path1);
icon2 = new ImageIcon(path2);
icon3 = new ImageIcon(path3);
icon4 = new ImageIcon(path4);
this.addTextField();
this.addpButton();
this.addfButton();
this.addOCButton();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setResizable(false);
}
public void addpButton(){ //添加扑克牌按钮
pButtonOne = new JButton();
pButtonTwo = new JButton();
pButtonThree = new JButton();
pButtonFour = new JButton();
pButtonOne.setBounds(50,25,100,150);
pButtonTwo.setBounds(250,25,100,150);
pButtonThree.setBounds(450,25,100,150);
pButtonFour.setBounds(650,25,100,150);
pButtonOne.setIcon(icon1);
pButtonTwo.setIcon(icon2);
pButtonThree.setIcon(icon3);
pButtonFour.setIcon(icon4);
pButtonOne.addActionListener(new pButtonEvent());
pButtonTwo.addActionListener(new pButtonEvent());
pButtonThree.addActionListener(new pButtonEvent());
pButtonFour.addActionListener(new pButtonEvent());
this.add(pButtonOne);
this.add(pButtonTwo);
this.add(pButtonThree);
this.add(pButtonFour);
}
public void addfButton(){ //添加符号按钮
fButtonJia = new JButton();
fButtonJian = new JButton();
fButtonCheng = new JButton();
fButtonChu = new JButton();
fButtonZKuo = new JButton();
fButtonYKuo = new JButton();
fButtonJia.setBounds(60,220,60,60);
fButtonJian.setBounds(180,220,60,60);
fButtonCheng.setBounds(300,220,60,60);
fButtonChu.setBounds(420,220,60,60);
fButtonZKuo.setBounds(540,220,60,60);
fButtonYKuo.setBounds(660,220,60,60);
fButtonJia.setIcon(new ImageIcon("Jia.png"));
fButtonJian.setIcon(new ImageIcon("jian.png"));
fButtonCheng.setIcon(new ImageIcon("cheng.png"));
fButtonChu.setIcon(new ImageIcon("chu.png"));
fButtonZKuo.setIcon(new ImageIcon("ZuoKuoHao.png"));
fButtonYKuo.setIcon(new ImageIcon("YouKuoHao.png"));
fButtonJia.setContentAreaFilled(false);
fButtonJian.setContentAreaFilled(false);
fButtonCheng.setContentAreaFilled(false);
fButtonChu.setContentAreaFilled(false);
fButtonZKuo.setContentAreaFilled(false);
fButtonYKuo.setContentAreaFilled(false);
fButtonJia.addActionListener(new fButtonEvent());
fButtonJian.addActionListener(new fButtonEvent());
fButtonCheng.addActionListener(new fButtonEvent());
fButtonChu.addActionListener(new fButtonEvent());
fButtonZKuo.addActionListener(new fButtonEvent());
fButtonYKuo.addActionListener(new fButtonEvent());
this.add(fButtonJia);
this.add(fButtonJian);
this.add(fButtonCheng);
this.add(fButtonChu);
this.add(fButtonZKuo);
this.add(fButtonYKuo);
}
public void addTextField(){ //添加文本框
text = new JTextField();
text.setOpaque(false); //设置文本框透明
text.setEditable(false); //设置文本框不可编辑
text.setBounds(100,350,620,100);
Font font = new Font("宋体",Font.BOLD,100);
text.setFont(font);
this.add(text);
}
public void addOCButton(){ //添加确定取消按钮
okButton = new JButton("确定");
cancelButton = new JButton("撤销");
startButton = new JButton("开始");
nextButton = new JButton("停止");
okButton.setFont(new Font("楷体",Font.BOLD,22));
cancelButton.setFont(new Font("楷体",Font.BOLD,22));
startButton.setFont(new Font("楷体",Font.BOLD,22));
nextButton.setFont(new Font("楷体",Font.BOLD,22));
okButton.setBounds(130,500,200,50);
cancelButton.setBounds(470,500,200,50);
startButton.setBounds(350,500,100,50);
nextButton.setBounds(350,500,100,50);
this.add(okButton);
this.add(startButton);
this.add(nextButton);
this.add(cancelButton);
nextButton.setVisible(false);
JButton answerButton = new JButton("想知道答案?点击我!");
answerButton.setBounds(300, 300, 200, 40);
answerButton.setContentAreaFilled(false);
answerButton.setBorderPainted(false);
answerButton.setFont(new Font("楷体",Font.BOLD,15));
answerButton.addMouseListener(new MouseAdapter(){
public void mouseEntered(MouseEvent e){
setCursor(new Cursor(Cursor.HAND_CURSOR));
}
public void mouseExited(MouseEvent e){
setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
}
});
answerButton.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ee){
int op1,op2,op3;
for(op1=1;op1<=4;op1++)
for(op2=1;op2<=4;op2++)
for(op3=1;op3<=4;op3++){
if(calculate_model1(a,b,c,d,op1,op2,op3)==24)
System.out.println("(("+a+showFuHao(op1)+b+")"+showFuHao(op2)+c+")"+showFuHao(op3)+d); /*对应表达式类型:((A□B)□C)□D*/
if(calculate_model2(a,b,c,d,op1,op2,op3)==24)
System.out.println("("+a+showFuHao(op1)+"("+b+showFuHao(op2)+c+")"+")"+showFuHao(op3)+d);/*对应表达式类型:(A□(B□C))□D */
if(calculate_model3(a,b,c,d,op1,op2,op3)==24)
System.out.println(a+showFuHao(op1)+"("+b+showFuHao(op2)+"("+c+showFuHao(op3)+d+"))");/*对应表达式类型:A□(B□(C□D))*/
if(calculate_model4(a,b,c,d,op1,op2,op3)==24)
System.out.println(a+showFuHao(op1)+"(("+b+showFuHao(op2)+c+")"+showFuHao(op3)+d+")");/*对应表达式类型:A□((B□C)□D)*/
if(calculate_model5(a,b,c,d,op1,op2,op3)==24)
System.out.println("("+a+showFuHao(op1)+b+")"+showFuHao(op2)+"("+c+showFuHao(op3)+d+")");/*对应表达式类型:(A□B)□(C□D)*/
}
}
});
this.add(answerButton);
startButton.addActionListener(new ActionListener(){ //"开始"按钮实
没有合适的资源?快使用搜索试试~ 我知道了~
JavaSE24点游戏
共32个文件
jpg:11个
class:10个
png:6个
5星 · 超过95%的资源 需积分: 13 19 下载量 105 浏览量
2015-04-13
19:03:35
上传
评论
收藏 1.54MB RAR 举报
温馨提示
这是我用javaSE也就是用Frame类来写的一个小游戏,不求好玩,只是能够用来练练手罢了,不过,也用到了不少知识,比如24点算法,我感觉就不错
资源推荐
资源详情
资源评论
收起资源包目录
24点.rar (32个子文件)
24点
bin
Game$1.class 749B
Game.class 9KB
Game$5.class 2KB
Game$pButtonEvent.class 2KB
Game$3.class 1KB
Game$3$1.class 1KB
Game$6.class 3KB
Game$fButtonEvent.class 2KB
Game$4.class 802B
Game$2.class 2KB
8.JPG 28KB
jia.PNG 7KB
2.JPG 23KB
5.JPG 25KB
10.JPG 29KB
6.JPG 25KB
4.JPG 24KB
.settings
org.eclipse.jdt.core.prefs 629B
src
Game.java 17KB
first.jpg 22KB
.project 381B
chu.png 8KB
1.JPG 22KB
substance.jar 1.54MB
9.JPG 28KB
.classpath 376B
cheng.PNG 8KB
zuokuohao.png 8KB
youkuohao.png 8KB
3.JPG 24KB
jian.PNG 7KB
7.JPG 27KB
共 32 条
- 1
资源评论
- 阴阳两界的探索者2018-07-17对我挺有帮助的
潘建成
- 粉丝: 136
- 资源: 82
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功