中易网

java 四则运算

答案:5  悬赏:0  
解决时间 2021-04-29 01:01
  • 提问者网友:多余借口
  • 2021-04-28 00:32
1、功能要求
该程序用GUI界面实现十道100以内加减乘除数学题(每题10分)。被测试者能根据题目计算出结果并输入答案,系统判断做题是否正确,并统计正确的题目数。最后计算分数并显示分数。
具体要求:
1) 欢迎界面:通过这里提供的选项(或按钮),进入测试界面。
2) 测试界面出现时第一道测试题同时出现,被测试者输入自己的运算结果,可以通过按回车键或者“确认”按钮完成输入。每道题前面显示题号。
3) 按“下一题”按钮,继续出题测试。
4) 十道题目做完后,系统给出测试分数及评语。

其中考核的知识点:文本框、标签框、按钮、布局、事件监听(鼠标、键盘、窗口)、对话框、随机函数,焦点设置。
2、拓展功能
1) 设计登录界面。
2) 加入图像显示功能(配合结果的正确与否,显示不同的图像)。
3) 设计版本信息窗口。
4) 为按钮设置热键。
(如果回答的好,可以追加分数的) 谢谢高手帮忙了!

我的邮箱是[email protected] ,到时候说你是哪个回答者就可以了 谢谢了
最佳答案
  • 二级知识专家网友:抱不住太阳的深海
  • 2021-04-28 02:07
GUI才好啊,不是GUI难看死了,很难普及,再者gui也不难。
全部回答
  • 1楼网友:留下所有热言
  • 2021-04-28 05:46
为什么是GUI...哎...
  • 2楼网友:万千宠爱
  • 2021-04-28 04:20
和一楼同感,为什么是gui呢,现在java的界面已经没几个人在用了。java都是搞后台的。
  • 3楼网友:魅世女王
  • 2021-04-28 03:52
public class calc extends jframe { private  jtextfield textnum1; private  jtextfield textnum2; private  jtextfield result; private  jcombobox opers; public calc() { init(); setsize(300,400); setlocationrelativeto(null); settitle("计算器"); setdefaultcloseoperation(3); setvisible(true); } private void init(){ string[] operators = "+,-,*,/".split(","); textnum1 = new jtextfield(); textnum1.setcolumns(10); textnum2 = new jtextfield(); textnum2.setcolumns(10); result = new jtextfield(); result.setcolumns(10); opers = new jcombobox(operators); opers.addactionlistener(new actionlistener() { @override public void actionperformed(actionevent e) { int operator = opers.getselectedindex(); double num1 = double.parsedouble(textnum1.gettext()); double num2 = double.parsedouble(textnum2.gettext()); switch(operator){ case 0:result.settext(num1 + num2+"");break; case 1:result.settext(num1 - num2+"");break; case 2:result.settext(num1 * num2+"");break; case 3:result.settext(num1 / num2+"");break; } } }); jpanel p = new jpanel(); p.add(textnum1); p.add(textnum2); p.add(opers); p.add(result); this.add(p); } public static void main(string[] args) { new calc(); } }
  • 4楼网友:浪者不回头
  • 2021-04-28 03:21
要做出来不难我可以帮你搞定他但是我不会管登陆页面因为个设涉及数据库的问题。。懒的搞。。还有我设计的页面可能不会太美观。。因为没时间去设计页面的问题。。。 我写了一个没有图片版的简易版本。。喜欢就拿去把。。。大多数功能已经实现其他需要调试的自己去调把。 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(); } } } } }
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息!
大家都在看
推荐信息