//随机四则运算类 public class 随机四则运算 { public static void main(String[] args) { new 界面();//进入随机四则运算的首界面 } } //进入随机思则运算的首界面设置 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.LayoutStyle.ComponentPlacement; public class 界面 { private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 界面 window = new 界面(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 界面() { initialize(); } private void initialize() { //设置界面的相应布局 frame = new JFrame(); frame.setTitle("每天一练"); frame.setBounds(100, 100, 339, 390); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("初级版"); button.setFont(new Font("宋体", Font.PLAIN, 26)); JButton button_1 = new JButton("中级版"); button_1.setFont(new Font("宋体", Font.PLAIN, 26)); JButton button_2 = new JButton("高级版"); button_2.setFont(new Font("宋体", Font.PLAIN, 26)); JButton button_3 = new JButton("帮助"); button_3.setFont(new Font("宋体", Font.PLAIN, 18)); JButton button_4 = new JButton("退出"); button_4.setFont(new Font("宋体", Font.PLAIN, 18)); GroupLayout groupLayout = new GroupLayout(frame.getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(48) .addComponent(button_3, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE) .addGap(55) .addComponent(button_4, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createSequentialGroup() .addGap(102) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(button_2) .addComponent(button_1) .addComponent(button)))) .addContainerGap(72, Short.MAX_VALUE)) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup() .addContainerGap(75, Short.MAX_VALUE) .addComponent(button) .addGap(37) .addComponent(button_1, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE) .addGap(36) .addComponent(button_2, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE) .addGap(50) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addComponent(button_4, GroupLayout.PREFERRED_SIZE, 29, GroupLayout.PREFERRED_SIZE) .addComponent(button_3)) .addGap(30)) ); //当按初级版按钮时,进入初级版的选题界面 button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 每天一练初级版题型选择(); } }); //当按中级版按钮时,进入中级版的选题界面 button_1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 每天一练中级版题型选择(); } }); //当按高级版按钮时,进入高级版的实战界面 button_2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 实战界面高级版(); } }); //当按帮助按钮时,弹出一个界面解释初级版、中级版以及高级版的相关解释 button_3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { new 帮助(); } }); //当按退出按钮时,退出整个随机四则运算系统 button_4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { System.exit(0); } }); //设置窗口的位置,使其尽量居中 Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.getContentPane().setLayout(groupLayout); frame.setVisible(true);//设置窗口的可见性 frame.setResizable(false);//设置窗口大小的不可改变性 } } //每天一练初级版题型选择界面 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.LayoutStyle.ComponentPlacement; public class 每天一练初级版题型选择 { private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 每天一练初级版题型选择 window = new 每天一练初级版题型选择(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 每天一练初级版题型选择() { initialize(); } private void initialize() { //设置界面的布局 frame = new JFrame(); frame.setTitle("每天一练初级版题型选择"); frame.setBounds(100, 100, 325, 397); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton btnNewButton = new JButton("整数与整数型"); btnNewButton.setFont(new Font("宋体", Font.PLAIN, 22)); JButton button = new JButton("整数与分数型"); button.setFont(new Font("宋体", Font.PLAIN, 22)); JButton button_1 = new JButton("分数与分数型"); button_1.setFont(new Font("宋体", Font.PLAIN, 22)); JButton btnNewButton_1 = new JButton("退出"); btnNewButton_1.setFont(new Font("宋体", Font.PLAIN, 18)); GroupLayout groupLayout = new GroupLayout(frame.getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addContainerGap(57, Short.MAX_VALUE) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) .addGroup(groupLayout.createSequentialGroup() .addPreferredGap(ComponentPlacement.RELATED) .addComponent(btnNewButton, GroupLayout.DEFAULT_SIZE, 194, Short.MAX_VALUE)) .addComponent(button, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button_1, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) .addGap(68)) .addGroup(groupLayout.createSequentialGroup() .addGap(118) .addComponent(btnNewButton_1, GroupLayout.PREFERRED_SIZE, 82, GroupLayout.PREFERRED_SIZE) .addContainerGap(119, Short.MAX_VALUE)) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(42) .addComponent(btnNewButton) .addGap(57) .addComponent(button, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE) .addGap(57) .addComponent(button_1, GroupLayout.PREFERRED_SIZE, 35, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, 53, Short.MAX_VALUE) .addComponent(btnNewButton_1) .addGap(26)) ); //当按退出按钮时,将该窗口设置成不可见性并且返回到首界面窗口 btnNewButton_1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { frame.setVisible(false); new 界面(); } }); //当按整数与整数按钮时,将该窗口设置成不可见性并且进入实战界面初级版整数与整数型界面 btnNewButton.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { frame.setVisible(false); new 实战界面初级版整数与整数型(); } }); //当按整数与分数按钮时,将该窗口设置成不可见性并且进入实战界面初级版整数与分数型界面 button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { frame.setVisible(false); new 实战界面初级版整数与分数型(); } }); //当按分数与分数按钮时,将该窗口设置成不可见性并且进入实战界面初级版分数与分数型界面 button_1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { frame.setVisible(false); new 实战界面初级版分数与分数型(); } }); frame.getContentPane().setLayout(groupLayout); //设置窗口的位置 Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true);//设置窗口的可见性 frame.setResizable(false);//设置窗口大小的不可变性 } } //实战界面初级版整数与整数型 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面初级版整数与整数型 { float sum;//记录当前答题的答案 int dadui=0;//记录总答对题数 int dacuo=0;//记录总答错题数 int tishu;//记录总题数 int noanswer=0;//记录未答题数 int summary=0;//记录当前的答题题号 //设置答案的输出形式 String parten = "0.00"; DecimalFormat decimal = new DecimalFormat(parten); String str; //设计计时器 static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss");//设置计时器的格式 long starttime;//记录每题的开始时间 long finishtime;//记录每题的结束时间 long duration;//记录每题的答题时间 long allduration=0;//记录总共答题时间 private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面初级版整数与整数型 window = new 实战界面初级版整数与整数型(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面初级版整数与整数型() { initialize(); } private void initialize() { //设置界面的布局 frame = new JFrame(); frame.setTitle("实战界面初级版整数与整数型"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); //当按退出按钮时,弹出对话框(答题总题数、答对题数、答错题数以及未答题数),把当前窗口设置成不可见性,再返回到每天一练初级版题型选择 B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 每天一练初级版题型选择(); } }); //当按开始按钮时,执行以下步骤 B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText());//获取总题数 noanswer=tishu-dadui-dacuo;//算出未答题数 summary++;//记录当前答题题号 //设置每题的计时,时间为10s,超时会提示时间到,弹出对话框(答题总题数、答对题数、答错题数、未答题数以及答题时间),把当前窗口设置成不可见性,再返回到每天一练初级版题型选择 timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==10&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+(tishu-dacuo-dadui)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration;//记录全程算法所用的时间 //生成一个随机算术 char a[]={'+','-','×','÷'}; int b=(int)(Math.random()*4); int c=(int)(Math.random()*100); int d=(int)(Math.random()*99+1); if(a[b]==a[0]) { T2.setText(c+String.valueOf(a[b])+d); sum=c+d; } else if(a[b]==a[1]) { T2.setText(c+String.valueOf(a[b])+d); sum=c-d; } else if(a[b]==a[2]) { T2.setText(c+String.valueOf(a[b])+d); sum=c*d; } else if(a[b]==a[3]) { T2.setText(c+String.valueOf(a[b])+d); sum=(float)c/d; } } }); //监听答题者的答案是否与正确答案一致,并作出相应的判断 T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { str= decimal.format(sum); if(Float.parseFloat(str)==Float.parseFloat(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+Float.parseFloat(str)); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dacuo-dadui;//及时更新未答题题数 } }); //当按下一题按钮时,先判断是否到最后一题,是则弹出对话框,否则清空各框的内容 B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); //设置窗口的位置 Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true);//设置窗口的可见性 frame.setResizable(false);//设置窗口大小的不可变性 } } //实战界面初级版整数与分数型 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面初级版整数与分数型 { float sum; int dadui=0; int dacuo=0; int tishu; int noanswer=0; int summary=0; String parten = "0.00"; DecimalFormat decimal = new DecimalFormat(parten); String str; static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss"); long starttime; long finishtime; long duration; long allduration; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面初级版整数与分数型 window = new 实战界面初级版整数与分数型(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面初级版整数与分数型() { initialize(); } private void initialize() { frame = new JFrame(); frame.setTitle("实战界面初级版整数与分数型"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 每天一练初级版题型选择(); } }); B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText()); noanswer=tishu-dadui-dacuo; summary++; timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==25&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",为答题题数"+(tishu-dacuo-dadui)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration; char a[]={'+','-','×','÷'}; int b=(int)(Math.random()*4); int c=(int)(Math.random()*100); int d=(int)(Math.random()*99+1); int f=(int)(Math.random()*100); if(a[b]==a[0]) { T2.setText(c+String.valueOf(a[b])+f+"/"+d); sum=c+(float)f/d; } else if(a[b]==a[1]) { T2.setText(c+String.valueOf(a[b])+f+"/"+d); sum=c-(float)f/d; } else if(a[b]==a[2]) { T2.setText(c+String.valueOf(a[b])+"("+f+"/"+d+")"); sum=c*((float)f/d); } else if(a[b]==a[3]) { T2.setText(c+String.valueOf(a[b])+"("+f+"/"+d+")"); sum=(float)c/((float)f/d); } } }); T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { str= decimal.format(sum); if(Float.parseFloat(str)==Float.parseFloat(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+Float.parseFloat(str)); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dadui-dacuo; } }); B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",为答题题数"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true); frame.setResizable(false); } } //实战界面初级版分数与分数型 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面初级版分数与分数型 { float sum; int dadui=0; int dacuo=0; int tishu; int noanswer=0; int summary=0; String parten = "0.00"; DecimalFormat decimal = new DecimalFormat(parten); String str; static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss");//倒计时时间的格式 long starttime; long finishtime; long duration; long allduration; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面初级版分数与分数型 window = new 实战界面初级版分数与分数型(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面初级版分数与分数型() { initialize(); } private void initialize() { frame = new JFrame(); frame.setTitle("实战界面初级版分数与分数型"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 每天一练初级版题型选择(); } }); B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText()); noanswer=tishu-dadui-dacuo; summary++; timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==10&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+(tishu-dacuo-dadui)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration; char a[]={'+','-','×','÷'}; int b=(int)(Math.random()*4); int c=(int)(Math.random()*100); int d=(int)(Math.random()*99+1); int g=(int)(Math.random()*100); int f=(int)(Math.random()*99+1); if(a[b]==a[0]) { T2.setText(d+"/"+c+String.valueOf(a[b])+g+"/"+f); sum=(float)d/c+(float)g/f; } else if(a[b]==a[1]) { T2.setText(d+"/"+c+String.valueOf(a[b])+g+"/"+f); sum=(float)d/c-(float)g/f; } else if(a[b]==a[2]) { T2.setText(+d+"/"+c+String.valueOf(a[b])+"("+g+"/"+f+")"); sum=((float)d/c)*((float)g/f); } else if(a[b]==a[3]) { T2.setText(d+"/"+c+String.valueOf(a[b])+"("+g+"/"+f+")"); sum=((float)d/c)/((float)g/f); } } }); T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { str= decimal.format(sum); if(Float.parseFloat(str)==Float.parseFloat(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+Float.parseFloat(str)); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dadui-dacuo; } }); B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true); frame.setResizable(false); } } //每天一练中级版题型选择界面 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.Toolkit; import javax.swing.JFrame; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JButton; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.LayoutStyle.ComponentPlacement; public class 每天一练中级版题型选择 { private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 每天一练中级版题型选择 window = new 每天一练中级版题型选择(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 每天一练中级版题型选择() { initialize(); } private void initialize() { //设置界面的布局 frame = new JFrame(); frame.setTitle("每天一练中级版题型选择"); frame.setBounds(100, 100, 349, 422); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JButton button = new JButton("全整数型"); button.setFont(new Font("宋体", Font.PLAIN, 20)); JButton button_1 = new JButton("两个整数与一个分数型"); button_1.setFont(new Font("宋体", Font.PLAIN, 20)); JButton button_2 = new JButton("一个整数与两个分数型"); button_2.setFont(new Font("宋体", Font.PLAIN, 20)); JButton button_3 = new JButton("全分数型"); button_3.setFont(new Font("宋体", Font.PLAIN, 20)); JButton button_4 = new JButton("退出"); button_4.setFont(new Font("宋体", Font.PLAIN, 18)); GroupLayout groupLayout = new GroupLayout(frame.getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addContainerGap(39, Short.MAX_VALUE) .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING, false) .addComponent(button_2, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE) .addComponent(button_1, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) .addComponent(button_3, Alignment.TRAILING, GroupLayout.DEFAULT_SIZE, 233, Short.MAX_VALUE) .addComponent(button, Alignment.TRAILING, GroupLayout.PREFERRED_SIZE, 262, GroupLayout.PREFERRED_SIZE)) .addGap(42)) .addGroup(Alignment.TRAILING, groupLayout.createSequentialGroup() .addComponent(button_4, GroupLayout.PREFERRED_SIZE, 80, GroupLayout.PREFERRED_SIZE) .addGap(131)))) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(50) .addComponent(button) .addGap(37) .addComponent(button_1, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE) .addGap(44) .addComponent(button_2, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE) .addGap(45) .addComponent(button_3, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, 36, Short.MAX_VALUE) .addComponent(button_4) .addGap(21)) ); //当按全整数按钮时,将该窗口设置成不可见性并且进入实战界面中级版全整数型界面 button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 实战界面中级版全整数型(); } }); //当按两个整数与一个分数按钮时,将该窗口设置成不可见性并且进入实战界面中级版两个整数与一个分数型界面 button_1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 实战界面中级版两个整数与一个分数型(); } }); //当按一个整数两个分数按钮时,将该窗口设置成不可见性并且进入实战界面中级版一个整数与两个分数型界面 button_2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 实战界面中级版一个整数与两个分数型(); } }); //当按全分数按钮时,将该窗口设置成不可见性并且进入实战界面中级版全分数型界面 button_3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 实战界面中级版全分数型(); } }); //当按退出按钮时,将该窗口设置成不可见性并且返回到首界面 button_4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); new 界面(); } }); frame.getContentPane().setLayout(groupLayout); //设置窗口的位置 Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true);//设置窗口的可见性 frame.setResizable(false);//设置窗口大小的不可变性 } } //实战界面中级版全整数型 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面中级版全整数型 { float sum; int dadui=0; int dacuo=0; int tishu; int noanswer=0; int summary=0; String parten = "0.00"; DecimalFormat decimal = new DecimalFormat(parten); String str; static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss"); long starttime; long finishtime; long duration; long allduration; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面中级版全整数型 window = new 实战界面中级版全整数型(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面中级版全整数型() { initialize(); } private void initialize() { frame = new JFrame(); frame.setTitle("实战界面中级版全整数型"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 每天一练中级版题型选择(); } }); B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText()); noanswer=tishu-dadui-dacuo; summary++; timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==25&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+(tishu-dadui-dacuo)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration; char a[]={'+','-','×','÷'}; char b[]={'+','-','×','÷'}; int c=(int)(Math.random()*4); int d=(int)(Math.random()*4); int f=(int)(Math.random()*100); int g=(int)(Math.random()*99+1); int h=(int)(Math.random()*99+1); if(a[c]==a[0]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f+g+h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f+g-h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f+g*h; } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f+(float)g/h; } } else if(a[c]==a[1]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f-g+h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f-g-h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f-g*h; } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f-(float)g/h; } } else if(a[c]==a[2]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f*g+h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f*g-h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=f*g*h; } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=(float)f*g/h; } } else if(a[c]==a[3]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=(float)f/g+h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=(float)f/g-h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=(float)f/g*h; } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+h); sum=(float)f/g/h; } } } }); T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { str= decimal.format(sum); if(Float.parseFloat(str)==Float.parseFloat(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+Float.parseFloat(str)); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dacuo-dadui; } }); B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 每天一练中级版题型选择(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true); frame.setResizable(false); } } //实战界面中级版两个整数与一个分数型 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面中级版两个整数与一个分数型 { float sum; int dadui=0; int dacuo=0; int tishu; int noanswer=0; int summary=0; String parten = "0.00"; DecimalFormat decimal = new DecimalFormat(parten); String str; static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss"); long starttime; long finishtime; long duration; long allduration; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面中级版两个整数与一个分数型 window = new 实战界面中级版两个整数与一个分数型(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面中级版两个整数与一个分数型() { initialize(); } private void initialize() { frame = new JFrame(); frame.setTitle("实战界面中级版两个整数与一个分数型"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 每天一练中级版题型选择(); } }); B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText()); noanswer=tishu-dadui-dacuo; summary++; timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==27&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+(tishu-dacuo-dadui)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration; char a[]={'+','-','×','÷'}; char b[]={'+','-','×','÷'}; int c=(int)(Math.random()*4); int d=(int)(Math.random()*4); int f=(int)(Math.random()*100); int g=(int)(Math.random()*99+1); int h=(int)(Math.random()*99+1); int l=(int)(Math.random()*99+1); if(a[c]==a[0]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=f+g+(float)l/h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=f+g-(float)l/h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=f+g*((float)l/h); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=f+(float)g/((float)l/h); } } else if(a[c]==a[1]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=f-g+(float)l/h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=f-g-(float)l/h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=f-g*((float)l/h); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=f-(float)g/((float)l/h); } } else if(a[c]==a[2]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=f*g+(float)l/h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=f*g-(float)l/h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=f*g*((float)l/h); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=(float)f*g/((float)l/h); } } else if(a[c]==a[3]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=(float)f/g+(float)l/h; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+l+"/"+h); sum=(float)f/g-(float)l/h; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=(float)f/g*((float)l/h); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+g+String.valueOf(b[d])+"("+l+"/"+h+")"); sum=(float)f/g/((float)l/h); } } } }); T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { str= decimal.format(sum); if(Float.parseFloat(str)==Float.parseFloat(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+Float.parseFloat(str)); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dadui-dacuo; } }); B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 每天一练中级版题型选择(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true); frame.setResizable(false); } } //实战界面中级版一个整数与两个分数型 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面中级版一个整数与两个分数型 { float sum; int dadui=0; int dacuo=0; int tishu; int noanswer=0; int summary=0; String parten = "0.00"; DecimalFormat decimal = new DecimalFormat(parten); String str; static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss"); long starttime; long finishtime; long duration; long allduration; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面中级版一个整数与两个分数型 window = new 实战界面中级版一个整数与两个分数型(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面中级版一个整数与两个分数型() { initialize(); } private void initialize() { frame = new JFrame(); frame.setTitle("实战界面中级版一个整数与两个分数型"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 每天一练中级版题型选择(); } }); B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText()); noanswer=tishu-dadui-dacuo; summary++; timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==35&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+(tishu-dacuo-dadui)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration; char a[]={'+','-','×','÷'}; char b[]={'+','-','×','÷'}; int c=(int)(Math.random()*4); int d=(int)(Math.random()*4); int f=(int)(Math.random()*100); int g=(int)(Math.random()*99+1); int h=(int)(Math.random()*99+1); int l=(int)(Math.random()*99+1); int s=(int)(Math.random()*99+1); if(a[c]==a[0]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+s+"/"+l); sum=f+(float)h/g+(float)s/l; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+s+"/"+l); sum=f+(float)h/g-(float)s/l; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f+((float)h/g)*((float)s/l); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f+((float)h/g)/((float)s/l); } } else if(a[c]==a[1]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+s+"/"+l); sum=f-(float)h/g+(float)s/l; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+s+"/"+l); sum=f-(float)h/g-(float)s/l; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f-((float)h/g)*((float)s/l); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+h+"/"+g+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f-((float)h/g)/((float)s/l); } } else if(a[c]==a[2]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+s+"/"+l); sum=f*((float)h/g)+(float)s/l; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+s+"/"+l); sum=f*((float)h/g)-(float)s/l; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f*((float)h/g)*((float)s/l); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f*((float)h/g)/((float)s/l); } } else if(a[c]==a[3]) { if(b[d]==b[0]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+s+"/"+l); sum=f/((float)h/g)+(float)s/l; } else if(b[d]==b[1]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+s+"/"+l); sum=f/((float)h/g)-(float)s/l; } else if(b[d]==b[2]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f/((float)h/g)*((float)s/l); } else if(b[d]==b[3]) { T2.setText(f+String.valueOf(a[c])+"("+h+"/"+g+")"+String.valueOf(b[d])+"("+s+"/"+l+")"); sum=f/((float)h/g)/((float)s/l); } } } }); T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { str= decimal.format(sum); if(Float.parseFloat(str)==Float.parseFloat(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+Float.parseFloat(str)); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dadui-dacuo; } }); B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 每天一练中级版题型选择(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true); frame.setResizable(false); } } //实战界面中级版全分数型 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面中级版全分数型 { float sum; int dadui=0; int dacuo=0; int tishu; int noanswer=0; int summary=0; String parten = "0.00"; DecimalFormat decimal = new DecimalFormat(parten); String str; static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss"); long starttime; long finishtime; long duration; long allduration; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面中级版全分数型 window = new 实战界面中级版全分数型(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面中级版全分数型() { initialize(); } private void initialize() { frame = new JFrame(); frame.setTitle("实战界面中级版全分数型"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 每天一练中级版题型选择(); } }); B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText()); noanswer=tishu-dadui-dacuo; summary++; timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==50&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+(tishu-dadui-dacuo)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration; char a[]={'+','-','×','÷'}; char b[]={'+','-','×','÷'}; int c=(int)(Math.random()*4); int d=(int)(Math.random()*4); int f=(int)(Math.random()*100); int g=(int)(Math.random()*99+1); int h=(int)(Math.random()*99+1); int l=(int)(Math.random()*99+1); int s=(int)(Math.random()*99+1); int p=(int)(Math.random()*99+1); if(a[c]==a[0]) { if(b[d]==b[0]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+p+"/"+s); sum=(float)g/f+(float)l/h+(float)p/s; } else if(b[d]==b[1]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+p+"/"+s); sum=(float)g/f+(float)l/h-(float)p/s; } else if(b[d]==b[2]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=(float)g/f+((float)l/h)*((float)p/s); } else if(b[d]==b[3]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=(float)g/f+((float)l/h)/((float)p/s); } } else if(a[c]==a[1]) { if(b[d]==b[0]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+p+"/"+s); sum=(float)g/f-(float)l/h+(float)p/s; } else if(b[d]==b[1]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+p+"/"+s); sum=(float)g/f-(float)l/h-(float)p/s; } else if(b[d]==b[2]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=(float)g/f-((float)l/h)*((float)p/s); } else if(b[d]==b[3]) { T2.setText(g+"/"+f+String.valueOf(a[c])+l+"/"+h+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=(float)g/f-((float)l/h)/((float)p/s); } } else if(a[c]==a[2]) { if(b[d]==b[0]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+p+"/"+s); sum=((float)g/f)*((float)l/h)+(float)p/s; } else if(b[d]==b[1]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+p+"/"+s); sum=((float)g/f)*((float)l/h)-(float)p/s; } else if(b[d]==b[2]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=((float)g/f)*((float)l/h)*((float)p/s); } else if(b[d]==b[3]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=((float)g/f)*((float)l/h)/((float)p/s); } } else if(a[c]==a[3]) { if(b[d]==b[0]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+p+"/"+s); sum=((float)g/f)/((float)l/h)+(float)p/s; } else if(b[d]==b[1]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+p+"/"+s); sum=((float)g/f)/((float)l/h)-(float)p/s; } else if(b[d]==b[2]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=((float)g/f)/((float)l/h)*((float)p/s); } else if(b[d]==b[3]) { T2.setText(g+"/"+f+String.valueOf(a[c])+"("+l+"/"+h+")"+String.valueOf(b[d])+"("+p+"/"+s+")"); sum=((float)g/f)/((float)l/h)/((float)p/s); } } } }); T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { str= decimal.format(sum); if(Float.parseFloat(str)==Float.parseFloat(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+Float.parseFloat(str)); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dadui-dacuo; } }); B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 每天一练中级版题型选择(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true); frame.setResizable(false); } } //实战界面高级版 import java.awt.Dimension; import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.GridLayout; import java.awt.Label; import java.awt.Toolkit; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.Date; import java.text.SimpleDateFormat; import java.util.Timer; import java.util.TimerTask; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextField; public class 实战界面高级版 { int sum; int dadui=0; int dacuo=0; int tishu; int noanswer=0; int summary=0; static Timer timer = null; static SimpleDateFormat df=new SimpleDateFormat("mm:ss"); long starttime; long finishtime; long duration; long allduration; private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 实战界面高级版 window = new 实战界面高级版(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 实战界面高级版() { initialize(); } private void initialize() { frame = new JFrame(); frame.setTitle("实战界面高级版"); frame.setSize(750,230); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Label L1=new Label("总题数:",Label.RIGHT); Label L2=new Label("题目:",Label.RIGHT); Label L3=new Label("请输入答案:",Label.RIGHT); Label L4=new Label("答题情况:",Label.RIGHT); Label L5=new Label("答对题数:",Label.RIGHT); Label L6=new Label("答错题数:",Label.RIGHT); Label L7=new Label("答题时间:",Label.RIGHT); final JButton B1=new JButton("开始"); final JButton B2=new JButton("下一题"); final JButton B3=new JButton("退出"); final JTextField T1=new JTextField(5); final JTextField T2=new JTextField(10); final JTextField T3=new JTextField(5); final JTextField T4=new JTextField(20); final JTextField T5=new JTextField(10); final JTextField T6=new JTextField(10); final JTextField T7=new JTextField(10); JPanel panel=new JPanel(); JPanel panel0=new JPanel(); JPanel panel1=new JPanel(); JPanel panel2=new JPanel(); JPanel panel3=new JPanel(); panel.add(panel0); panel.add(panel1); panel0.add(panel2); panel0.add(panel3); frame.getContentPane().add(panel,"Center"); L1.setFont(new java.awt.Font("宋体", 1, 14)); L2.setFont(new java.awt.Font("宋体", 1, 14)); L3.setFont(new java.awt.Font("宋体", 1, 14)); L4.setFont(new java.awt.Font("宋体", 1, 14)); L5.setFont(new java.awt.Font("宋体", 1, 14)); L6.setFont(new java.awt.Font("宋体", 1, 14)); L7.setFont(new java.awt.Font("宋体", 1, 14)); panel.setLayout(new FlowLayout()); panel0.setLayout(new GridLayout(1,2)); panel2.setLayout(new GridLayout(4,2,5,10)); panel3.setLayout(new GridLayout(4,2,10,10)); panel2.add(L1); panel2.add(T1); panel2.add(L2); panel2.add(T2); panel2.add(L3); panel2.add(T3); panel2.add(L4); panel2.add(T4); panel3.add(L5); panel3.add(T5); panel3.add(L6); panel3.add(T6); panel3.add(L7); panel3.add(T7); panel1.add(B1); panel1.add(B2); panel1.add(B3); B3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { JOptionPane.showMessageDialog(null, "答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",未答题题数为"+noanswer+"。"); frame.setVisible(false); new 界面(); } }); B1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { tishu=Integer.parseInt(T1.getText()); noanswer=tishu-dadui-dacuo; summary++; timer = new Timer(); finishtime=System.currentTimeMillis(); starttime=finishtime; timer.schedule(new TimerTask() { public void run() { finishtime=System.currentTimeMillis(); duration=finishtime-starttime; if(duration/1000==40&&summary<tishu) { JOptionPane.showMessageDialog(null, "答题时间已到。答题总题数为"+(dadui+dacuo)+",答对题数为"+dadui+",答错题数为"+dacuo+",为答题题数为"+(tishu-dadui-dacuo)+",答题使用时间:"+(allduration+duration)/1000+"秒。"); frame.setVisible(false); new 每天一练初级版题型选择(); } String str=df.format(new Date(duration)); T7.setText(str); } }, 1000, 1000); allduration=allduration+duration; int a=(int)(Math.random()*10); T2.setText(a+"!"); if(a==0) { sum=1; } else { sum=fun(a); } } private int fun(int a) { if(a==1) return 1; else return a*fun(a-1); } }); T3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(sum==Integer.parseInt(T3.getText())) { T4.setText("恭喜你!答对了!"); dadui++; T5.setText(String.valueOf(dadui)); } else { T4.setText("真遗憾!答错了!正确答案是"+sum); dacuo++; T6.setText(String.valueOf(dacuo)); } noanswer=tishu-dacuo-dadui; } }); B2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e) { if(summary==tishu) { JOptionPane.showMessageDialog(null, "答题已完成。答题总题数为"+tishu+",答对题数为"+dadui+",答错题数为"+dacuo+",为答题题数为"+noanswer+",答题使用时间:"+allduration/1000+"秒。"); frame.setVisible(false); new 界面(); } else { T2.setText(null); T3.setText(null); T4.setText(null); } } }); Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true); frame.setResizable(false); } } //帮助界面的设置 import java.awt.Dimension; import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.GroupLayout; import javax.swing.GroupLayout.Alignment; import javax.swing.JPanel; import javax.swing.JTextPane; import java.awt.Font; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.LayoutStyle.ComponentPlacement; import java.awt.Toolkit; public class 帮助 { private JFrame frame; public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { try { 帮助 window = new 帮助(); window.frame.setVisible(true); } catch (Exception e) { e.printStackTrace(); } } }); } public 帮助() { initialize(); } private void initialize() { //界面界面的布局设置 frame = new JFrame(); frame.setTitle("帮助"); frame.setBounds(100, 100, 560, 399); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); JButton button = new JButton("退出"); button.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent arg0) { frame.setVisible(false); } }); GroupLayout groupLayout = new GroupLayout(frame.getContentPane()); groupLayout.setHorizontalGroup( groupLayout.createParallelGroup(Alignment.TRAILING) .addGroup(groupLayout.createSequentialGroup() .addGroup(groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(21) .addComponent(panel, GroupLayout.PREFERRED_SIZE, 495, GroupLayout.PREFERRED_SIZE)) .addGroup(groupLayout.createSequentialGroup() .addGap(242) .addComponent(button))) .addContainerGap(28, Short.MAX_VALUE)) ); groupLayout.setVerticalGroup( groupLayout.createParallelGroup(Alignment.LEADING) .addGroup(groupLayout.createSequentialGroup() .addGap(18) .addComponent(panel, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE) .addPreferredGap(ComponentPlacement.RELATED, 36, Short.MAX_VALUE) .addComponent(button) .addGap(25)) ); JTextPane textPane = new JTextPane(); textPane.setFont(new Font("宋体", Font.PLAIN, 23)); textPane.setText(" \u6BCF\u5929\u4E00\u7EC3\r\n \u6BCF\u5929\u4E00\u7EC3\u4E3B\u8981\u5206\u6210\u4E09\u4E2A\u7EA7\u522B\uFF0C\u5206\u522B\u662F\u521D\r\n\u7EA7\u7248\u3001\u4E2D\u7EA7\u7248\u548C\u9AD8\u7EA7\u7248\u3002\u521D\u7EA7\u7248\u4E3B\u8981\u662F\u4E24\u9879\r\n\u7684\u56DB\u5219\u8FD0\u7B97\uFF0C\u5305\u542B\u6574\u6570\u4E0E\u6574\u6570\u578B\u3001\u6574\u6570\u4E0E\u5206\r\n\u6570\u578B\u3001\u5206\u6570\u4E0E\u5206\u6570\u578B\u4E09\u79CD\u9898\u578B\u3002\u4E2D\u7EA7\u7248\u4E3B\u8981\r\n\u662F\u4E09\u9879\u7684\u56DB\u5219\u8FD0\u7B97\uFF0C\u5305\u542B\u5168\u6574\u6570\u578B\u3001\u4E00\u4E2A\u6574\r\n\u6570\u4E0E\u4E24\u4E2A\u5206\u6570\u578B\u3001\u4E24\u4E2A\u6574\u6570\u4E0E\u4E00\u4E2A\u5206\u6570\u578B\u3001\r\n\u5168\u5206\u5206\u6570\u578B\u56DB\u79CD\u9898\u578B\u3002\u9AD8\u7EA7\u7248\u4E3B\u8981\u662F\u5355\u4E2A\u6570\r\n\u7684\u9636\u4E58\u8FD0\u7B97\u3002"); panel.add(textPane); frame.getContentPane().setLayout(groupLayout); //设置窗口的位置 Toolkit kit = Toolkit.getDefaultToolkit(); Dimension screenSize = kit.getScreenSize(); int w1 = screenSize.width; int h = screenSize.height; int x1 = w1/3; int y1 = h/5; frame.setLocation(x1,y1); frame.setVisible(true);//设置窗口的可见性 frame.setResizable(false);//设置窗口大小的不可变性 } }
程序流程图如下:
实现界面截图:
首次登陆的用户界面:
当点击初级版时,进入初级版题型选择界面:
当点击整数与整数型时,进入实战界面初级版整数与整数型界面:
当输入总题数时,就可以点击开始做题(时间以及相应的答对错提数也会相应的计算):
答错题目的情况:
答对题目的情况亦如上(只是答对了就不会显示正确答案)
当答题结束后弹出答题结束的对话框(当答题超时或答题者自动退出时也会弹出类似的对话框):
其他版本以及实战界面同上所述。
结对同伴:201306114353 李豌湄 博客:http://www.cnblogs.com/leewanmei/
结伴分工情况:豌湄和我先一起讨论界面如何设置以及该程序需要实现怎样的功能,然后豌湄主要做中级版和高级版的算法,我主要做界面以及初级版的内容,最后一起讨论未能实现的功能,并加以改善和完成该程序。
随机四则运算(带界面)的主要功能
①可以分级别进行实战(初级版、中级版、高级版);
②当用户不懂三个级别的内容可以通过帮助来解决;
③实战界面中有如下功能:
(1)答题者可以输入答题数;
(2)当每做一题都有计时,当时间到达就提示答题者,并弹出相应的对话框来告诉答题者的答题情况;
(3)答题过程中答题者可以随时观察到自己答该题的时间情况以及之前答对错题目的个数;
(4)做完题时,答题者可以知道总答题时间,以及答题的情况;
(5)当答题者中途退出时,答题者也可以知道答题的相应情况;
(6)当答题者输入该题答案时,通过键盘的回车符,可以显示该题的对错,如果答错还会有相应的正确答案的提示。
程序的优点:
①可以让答题者根据自身的情况选择相应的实战模块;
②可以提高答题者的计算能力,检测答题者的答题时间;
③答题者可以随时观察自己在答题过程中答对题数以及答错的题数,还有本题的答题时间;
④可以让答题者输入答题的题数;
⑤答题者答题过程中程序可以监测到答题者所用的时间是否超时、是否出现由于太难而未答的题目以及是否答题者中断答题;
⑥每答一道题目都会有相应的提示答题者是否做对错,如果错了还会有相应的正确答案。
程序缺点:
①统计答题时间时,把按按钮的时间都算上到答题时间上了;
②没有弄一个综合版本的,只能是在规定的选项题型中随机生成题目。弄一个综合版本对答题者可能更加好。(看了别人的程序后想到)
③答题完成后没有出答题的分数;
本次实验总结:
通过本次实验,不仅让我复习到了以前Java遗漏的知识,更重要的是明白到了一个人的想法是非常的局限的,只有通过和别人的交流和沟通后,才会知道自己的程序存在一些怎样的错误和不足,如何去进行改善。还有就是解决问题的方法和方式都有一定程度的改进,不会那么盲目,还可以培养一种当困难向你迎来时,能具有挑战接受它的精神。