展开全部
Newload()
{
jf1=new JFrame("猜数游戏");
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<a.length;i++)//JPasswordField是一种特殊的类只能得到char数组,将其转成String
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())<number)
{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;
}
}
{
jf1=new JFrame("猜数游戏");
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<a.length;i++)//JPasswordField是一种特殊的类只能得到char数组,将其转成String
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())<number)
{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;
}
}
展开全部
csdn源码站,这个多的很!
晕!我刚刚在空间上传了一个"推箱子",可以去看看!
http://hi.baidu.com/shy2850/blog/item/9e198f1359518c5cf819b8ac.html
晕!我刚刚在空间上传了一个"推箱子",可以去看看!
http://hi.baidu.com/shy2850/blog/item/9e198f1359518c5cf819b8ac.html
参考资料: http://hi.baidu.com/shy2850/blog/item/9e198f1359518c5cf819b8ac.html
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询