推箱子 java 代码_急需Java推箱子游戏代码

展开全部

Newload()

{

jf1=new JFrame("猜数游32313133353236313431303231363533e59b9ee7ad9431333262363063戏");

jf2=new JFrame("猜数游戏");

jf3=new JFrame("猜数游戏");

jf1_title=new JLabel("猜数游戏-欢迎进入");

jf1_title.setFont(new Font("仿宋体",Font.BOLD,40));//设置字体大小,及文字字体

jf1_title.setHorizontalAlignment(JLabel.CENTER);

JLabel jf2title=new JLabel("猜数游戏");

jf2title.setFont(new Font("仿宋体",Font.BOLD,40));//设置字体大小,及文字字体

jf2title.setHorizontalAlignment(JLabel.CENTER);

jf1_username=new JLabel("用户名");

jf1_userpass=new JLabel("密码");

jf2_question=new JLabel("There is question which needs you to guess!");

jf2_question.setFont(new Font("仿宋体",Font.BOLD,20));//设置字体大小,及文字字体

jf2_question.setHorizontalAlignment(JLabel.CENTER);

jf2_rightface=new JLabel(iron1);

jf2_wrongface=new JLabel(iron2);

jf2_rightface.setVisible(false);

jf2_wrongface.setVisible(false);

jf2_reelresult=new JLabel();

jf3_pinyu=new JLabel("your result is");

jf1_usernameT=new JTextField(6);

jf2_anwser=new JTextField(6);

jf2_anwser.addActionListener(this);

jf1_password=new JPasswordField(6);

jf1_password.addActionListener(this);

jf1_ok=new JButton("确定");

jf1_ok.addActionListener(this);

jf1_quit=new JButton("退出");

jf1_quit.addActionListener(this);

jf2_newgame=new JButton("新游戏(k)");

jf2_newgame.setMnemonic(KeyEvent.VK_K);

jf2_newgame.addActionListener(this);

jf2_ok=new JButton("确定");

jf2_ok.addActionListener(this);

jf1.setLayout(new BorderLayout());

jf2.setLayout(new BorderLayout());

JPanel jf1p1=new JPanel(),jf2p1=new JPanel(),jf2p2=new JPanel(),jf2p3=new JPanel();

jf2p1.setLayout(new BorderLayout());

jf1p1.setLayout(new FlowLayout());

jf2p2.setLayout(new FlowLayout());

jf2p3.setLayout(new FlowLayout());

jf1.add(jf1_title,"Center");

jf1p1.add(jf1_username);jf1p1.add(jf1_usernameT);

jf1p1.add(jf1_userpass);jf1p1.add(jf1_password);

jf1p1.add(jf1_ok);jf1p1.add(jf1_quit);

jf1.add(jf1p1,"South");

jf2p2.add(jf2_rightface);

jf2p2.add(jf2_wrongface);

jf2p2.add(jf2_reelresult);

jf2p1.add(jf2p2,"South");

jf2p1.add(jf2_question);

jf2.add(jf2title,"North");

jf2.add(jf2p1,"Center");

jf2p3.add(jf2_ans);jf2p3.add(jf2_anwser);jf2p3.add(jf2_ok);jf2p3.add(jf2_newgame);

jf2.add(jf2p3,"South");

jf3.add(jf3_pinyu);

jf1.setSize(700,400);

jf2.setSize(700,400);

jf3.setSize(700,400);

jf1.setLocation(300,150);

jf2.setLocation(300,150);

jf3.setLocation(300,150);

jf1.setVisible(true);

jf2.setVisible(false);

jf3.setVisible(false);

jf1.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

jf2.addWindowListener(new WindowAdapter() {

public void windowClosing(WindowEvent e) {

System.exit(0);

}

});

}

public void actionPerformed(ActionEvent e) {

if(e.getSource()==jf1_ok||e.getSource()==jf1_password)

{char[] a=jf1_password.getPassword();String paas="";

for(int i=0;i

paas=paas+a[i];

if(jf1_usernameT.getText().equals("user")&&paas.equals("pass"))

{jf2.setVisible(true);jf1.setVisible(false);

number=returnquestion();

jf2_anwser.requestFocus();

}

else

JOptionPane.showMessageDialog(null,"用户名不正确或密码错误!");

}

if(e.getSource()==jf1_quit)

{

System.exit(0);

}

if(e.getSource()==jf2_ok||e.getSource()==jf2_anwser)

{

if(times<=5){

if(Integer.parseInt(jf2_anwser.getText())==number)

{

jf2_rightface.setVisible(true);

jf2_wrongface.setVisible(false);

jf2_reelresult.setText("you are right! and your have used "+times+" times!"

+((times<=3)?"very good!":"pleas do more work for it"));

}

else

if(Integer.parseInt(jf2_anwser.getText())>number)

{times++;

jf2_wrongface.setVisible(true);

jf2_rightface.setVisible(false);

jf2_reelresult.setText("your answer is bigger than the one produced by computer!"

+"and your have used "+times+" times!");

}

else

if(Integer.parseInt(jf2_anwser.getText())

{times++;

jf2_wrongface.setVisible(true);

jf2_rightface.setVisible(false);

jf2_reelresult.setText("your answer is smaller than the one produced by computer!"

+"and your have used "+times+" times!");

}

}

else

{JOptionPane.showMessageDialog(null,"你已经超过六次了,请重新开始吧!");}

jf2_anwser.requestFocus();

jf2_anwser.setText("");

}

if(e.getSource()==jf2_newgame)

{

number=returnquestion();

times=0;

jf2_rightface.setVisible(false);

jf2_wrongface.setVisible(false);

jf2_anwser.setText("");

jf2_reelresult.setText("");

jf2_anwser.requestFocus();

}

}

public static void main(String args[])

{

new Newload();

}

int returnquestion()

{

double db=Math.random()*100;

return (int)db;

}

}

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值