java判断加减结果正确否者_java 四则运算

展开全部

要做出来不难我可以62616964757a686964616fe78988e69d8331333238653236帮你搞定他但是我不会管登陆页面因为个设涉及数据库的问题。。懒的搞。。还有我设计的页面可能不会太美观。。因为没时间去设计页面的问题。。。

我写了一个没有图片版的简易版本。。喜欢就拿去把。。。大多数功能已经实现其他需要调试的自己去调把。

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

public class testMath extends Frame {

public static final int W_WIDTH=800,W_HEIGHT=600;

public static final int X_LOCATION=0,Y_LOCATION=0;

Image offScreemImage = null;

Font myFont = new Font("Arial",Font.CENTER_BASELINE,14);

boolean started = false,resulted=false;

boolean [] answer = new boolean [10];

String [] questions = {

"10+10*10 =",

"i'm the quesiton 2",

"i'm the quesiton 3",

"i'm the quesiton 4",

"i'm the quesiton 5",

"i'm the quesiton 6",

"i'm the quesiton 7",

"i'm the quesiton 8",

"i'm the quesiton 9",

"i'm the quesiton 10"

};

int [] questionA = {110,2,3,4,5,6,7,8,9,10};

int questionNo=0;

int finalresult=0;

TextField answerArea;

public void lanchFram(){

this.setLocation(X_LOCATION,Y_LOCATION);

this.setSize(W_WIDTH, W_HEIGHT);

setVisible(true);

this.setTitle("数学测验");

this.setResizable(false);

this.setBackground(Color.white);

new Thread(new PaintThread()).start();

this.setFont(myFont);

//closing window's event

this.addWindowListener(new WindowAdapter(){

public void windowClosing(WindowEvent a) {

System.exit(0);

}

});

this.setLayout(null);

answerArea = new TextField(10);

Panel toolBar = new Panel();

Panel answerText = new Panel();

Label notify = new Label("输入你的答案:");

answerText.add(notify);

answerText.add(answerArea);

Button start=new Button("start");

Button next = new Button("next");

Button last = new Button("last");

Button result = new Button("result");

answerArea.addActionListener(new answers());

start.addActionListener(new started());

last.addActionListener(new lastQuestion());

next.addActionListener(new nextQuestion());

result.addActionListener(new results());

toolBar.add(start);

toolBar.add(next);

toolBar.add(last);

toolBar.add(result);

answerText.setBounds(300,350,200,60);

toolBar.setBounds(250,450, 300, 30);

add(answerText);

add(toolBar);

}

class answers implements ActionListener{

public void actionPerformed(ActionEvent e){

try{

if(questionA[questionNo]==Integer.parseInt(answerArea.getText())){

answer[questionNo]=true;

}

else{

answer[questionNo]=false;

}

answerArea.setText("");

}

catch(Exception x){

answerArea.setText("");

}

}

}

class started implements ActionListener{

public void actionPerformed(ActionEvent e){

started=true;

}

}

class nextQuestion implements ActionListener{

public void actionPerformed(ActionEvent e){

if(questionNo<9&&started&&!resulted){

questionNo++;

}

}

}

class lastQuestion implements ActionListener{

public void actionPerformed(ActionEvent e){

if(questionNo>0&&started&&!resulted){

questionNo--;

}

}

}

class results implements ActionListener{

public void actionPerformed(ActionEvent e){

if(started){

for(int i=0;i<10;i++){

if(answer[i]){

finalresult +=10;

}

}

resulted=true;

}

}

}

public static void main(String[] args) {

testMath a = new testMath();

a.lanchFram();

}

public void paint(Graphics g)

{

if(started){

g.drawString("Question:"+(questionNo+1)+" "+questions [questionNo], 300, 250);

}

if(resulted&&started){

int x=600,y=50;

for(int i = 0;i<10;i++){

g.drawString("Question"+i+": "+answer[i], x, y);

y+=30;

}

g.drawString("Final result:"+finalresult, x, y);

}

}

public void update(Graphics g) {

if(offScreemImage == null){

offScreemImage=this.createImage(W_WIDTH,W_HEIGHT);

}

Graphics gOffScreem = offScreemImage.getGraphics();

Color c = gOffScreem.getColor();

gOffScreem.setColor(Color.white);

gOffScreem.fillRect(0, 0, W_WIDTH,W_HEIGHT);

gOffScreem.setColor(c);

paint(gOffScreem);

g.drawImage(offScreemImage,0,0,null);

}

//set up the Frame update time

private class PaintThread implements Runnable{

public void run() {

while(true){

repaint();

try {

Thread.sleep(50);

} catch (InterruptedException e) {

e.printStackTrace();

}

}

}

}

}

2Q==

已赞过

已踩过<

你对这个回答的评价是?

评论

收起

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值