正文

随机出题2006-06-07 07:30:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/tankboy/15513.html

分享到:

import java.awt.*;import java.awt.event.*;import javax.swing.ImageIcon;class Ks2 extends Frame implements ActionListener{ Label  lab1,lab2,lab3,lab4,lab5; Button but1,but2; public Ks2 () {  super("             随       机      出       题");  addWindowListener(new WindowAdapter()  {public void windowClosing(WindowEvent e)  {System.exit(0);}});        initialize(); } public void initialize() {  setSize(300,200);        this.setLayout(null);        lab1=new Label("");  lab1.setAlignment(Label.CENTER);  lab1.setBounds(20,60,30,25);  lab1.setBackground(Color.blue);  lab1.setForeground(Color.red);        add(lab1);        lab2=new Label("");  lab2.setAlignment(Label.CENTER);  lab2.setBounds(75,60,30,25);  lab2.setBackground(Color.blue);  lab2.setForeground(Color.red);        add(lab2);        lab3=new Label("");        lab3.setAlignment(Label.CENTER);        lab3.setBounds(130,60,30,25);        lab3.setBackground(Color.blue);        lab3.setForeground(Color.red);        add(lab3);        lab4=new Label("〓");  lab4.setAlignment(Label.CENTER);  lab4.setBounds(185,60,30,25);  lab4.setBackground(Color.blue);  lab4.setForeground(Color.red);        add(lab4);        lab5=new Label("");  lab5.setAlignment(Label.CENTER);  lab5.setBounds(240,60,30,25);  lab5.setBackground(Color.blue);  lab5.setForeground(Color.red);        add(lab5);        but1=new Button("出 题");  but1.setBounds(60,130,50,25);  but1.addActionListener(this);        add(but1);        but2=new Button("评 分");     but2.setBounds(170,130,50,25);  but2.addActionListener(this);        add(but2);        setVisible(true); } public void actionPerformed(ActionEvent e) {  if(e.getSource()==but1)  {   int a=(int)(4*Math.random()+1);      switch(a)      {       case 1:        lab2.setText("╋");break;       case 2:        lab2.setText("━");break;       case 3:        lab2.setText("★");break;       case 4:        lab2.setText("/");break;      }      lab1.setText(String.valueOf((int)(99*Math.random()+1)));                lab3.setText(String.valueOf((int)(99*Math.random()+1)));  }  if(e.getSource()==but2)    {     int result=0;     String s;     s=lab2.getText();     if(s.equals("╋")) result=Integer.parseInt(lab1.getText())+Integer.parseInt(lab3.getText());     if(s.equals("━")) result=Integer.parseInt(lab1.getText())-Integer.parseInt(lab3.getText());     if(s.equals("★")) result=Integer.parseInt(lab1.getText())*Integer.parseInt(lab3.getText());     if(s.equals("/")) result=Integer.parseInt(lab1.getText())/Integer.parseInt(lab3.getText());     //if(result==Integer.parseInt(tf.getText()));   /*  JOptionPane.showInputDialog("回答正确");     else     JOptionPane.showInputDialog("不正确")  */  } } public static void main(String args[]) {  new Ks2(); } }

阅读(1708) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册