【摘要】 一直忘了给源码 (可不是我懒~
大二上学期写的,有点菜,大佬误骂..
如果对您有帮助请点赞哦~~
123
登录界面 Login_Interface.javaimport java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagLay…
一直忘了给源码 (可不是我懒~
大二上学期写的,有点菜,大佬误骂..
如果对您有帮助请点赞哦~~
登录界面 Login_Interface.java
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
public class Login_Interface extends JFrame { private static final long serialVersionUID = 1L; //定义程序序列化,1L是默认定义 protected static String s1; protected static String s2; protected static String s3; private JLabel jl1 = new JLabel("欢迎来到考试系统"); private JLabel jl2 = new JLabel("请填写下列信息"); private JLabel jl3 = new JLabel(" "); private JLabel jl4 = new JLabel(" "); private JLabel JLName = new JLabel("姓名:"); private JLabel JLMagic = new JLabel("专业:"); private JLabel JLClass = new JLabel("班级:"); private JTextField JTName = new JTextField(10); private JTextField JTMagic = new JTextField(10); private JTextField JTClass = new JTextField(10); private JButton JB1 = new JButton("开始考试"); private JButton JB2 = new JButton("重置"); private JButton JBave = new JButton("平均分查看"); private JPanel jp1 = new JPanel(); private JPanel jp2 = new JPanel(); private JPanel jp3 = new JPanel(); private JPanel jp4 = new JPanel(); private JPanel jp5 = new JPanel(); private JPanel jp6 = new JPanel(); private JPanel jp7 = new JPanel(); private void Event() { JB1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(JTName.getText().equals("") || JTClass.getText().equals("") || JTMagic.getText().equals("")) { String s = "请输入完整信息"; JOptionPane.showMessageDialog(null, s,"提示",JOptionPane.ERROR_MESSAGE); }else { setVisible(false); dispose(); s1 = JTName.getText(); s2 = JTClass.getText(); s3 = JTMagic.getText(); new Test_Interface(); } } }); JB2.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JTName.setText(null); JTMagic.setText(null); JTClass.setText(null); } }); JBave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { new Average_Score(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }); } public Login_Interface() { this.setTitle("广州市×小学数学考试自动系统"); this.setSize(500, 450); this.setLocationRelativeTo(null); //将此窗口置于屏幕的中央 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new BorderLayout(20,20)); jl1.setFont(new Font("黑体",Font.BOLD,35)); jl1.setForeground(Color.blue); jp1.add(jl1); jp1.setLayout(new GridBagLayout()); this.add(jp1,BorderLayout.NORTH); jl2.setFont(new Font("黑体",Font.BOLD,25)); jl2.setForeground(Color.red); jp2.add(jl2); JLName.setFont(new Font("黑体",Font.BOLD,15)); jp3.add(JLName); jp3.add(JTName); JLMagic.setFont(new Font("黑体",Font.BOLD,15)); jp4.add(JLMagic); jp4.add(JTMagic); JLClass.setFont(new Font("黑体",Font.BOLD,15)); jp5.add(JLClass); jp5.add(JTClass); jp6.add(jp2); jp6.add(jp3); jp6.add(jp4); jp6.add(jp5); jp6.setLayout(new GridLayout(4,2)); this.add(jp6,BorderLayout.CENTER); jp6.setBorder(BorderFactory.createLoweredBevelBorder()); jp7.add(JBave); jp7.add(jl4); jp7.add(JB1); jp7.add(jl3); jp7.add(JB2); this.add(jp7,BorderLayout.SOUTH); //美化界面 try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } Event(); this.setVisible(true); } public static void main(String[] args) { new Login_Interface(); }
}
题目界面 Test_Interface.java
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Timer; //Timer用于管理在后台执行的延迟任务或周期性任务
import java.util.TimerTask; //其中的任务是用java.util.TimerTask表示
import javax.swing.BorderFactory;//边框
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
public class Test_Interface extends JFrame{ private static final long serialVersionUID = 1L; //定义程序序列化,1L是默认定义 private int max = 50; private int a = 0; private int b = 0; private int c = 0; private int count = 1; private JLabel JLgross = new JLabel("共10页"); private JLabel JLpage = new JLabel(); //页码控制 private JLabel jl1 = new JLabel(" "); //插两个空格进去 private JLabel JLtime = new JLabel("倒计时:"); private JLabel JLhour = new JLabel(); private JLabel JLminute = new JLabel(); private JLabel JLseconds = new JLabel(); private JButton JB1 = new JButton("提交考卷"); private JButton b1 = new JButton("首页"); private JButton b2 = new JButton("上一页"); private JButton b3 = new JButton("下一页"); private JButton b4 = new JButton("尾页"); private JLabel jl[] = new JLabel[50]; //50个题目标签 private JTextField jtf[] = new JTextField[50];//50个文本框,存储答案 private JPanel pnl1 = new JPanel(); private JPanel pnl2 = new JPanel(); private JPanel pnl3 = new JPanel(); private JPanel pnl4 = new JPanel(); static CardLayout care = new CardLayout(); int[] answer=new int[max]; String[] studentAnswer=new String[max]; private File file = null; private FileWriter fw1 = null; public long time = 5400; private void countDown() { Timer timer = new Timer(); timer.schedule(new TimerTask() { public void run() { time--; long hour = time / 3600; long minute = (time - hour * 3600) / 60; long seconds = time - hour * 3600 - minute * 60; JLhour.setText(hour + "时"); JLminute.setText(minute + "分"); JLseconds.setText(seconds + "秒"); if( time == 0 ) { JB1.doClick(); //调用提交试卷按钮 } } }, 0, 1000); } private void Event() { //提交试卷按钮 JB1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int correctAnswer=0; for(int i=0,k=0;i<max;i++,k++){ studentAnswer[i]=jtf[k].getText().trim(); try { if(Integer.parseInt(studentAnswer[i]) == answer[k]){ //将string字符串类型转换为integer整数类型 correctAnswer++; } }catch(NumberFormatException u) { } } int score = 100*(int)correctAnswer/max; setVisible(false); dispose(); String s="共50道题\n"; s=s+"答对"+correctAnswer+"道题\n"; s=s+"答错"+(max-correctAnswer)+"道题\n"; s=s+"成绩"+String.format("%d",score)+"分\n"; file = new File("信息收集.txt"); if(!file.exists()){ try { file.createNewFile(); }catch (IOException u1) { u1.printStackTrace(); } } try { fw1 = new FileWriter(file, true); fw1.write("姓名 " + Login_Interface.s1 + " 专业 " + Login_Interface.s3 + " 班级 " + Login_Interface.s2 + " 考试得分:" + score + "\n"); fw1.close(); }catch(IOException u2) { u2.printStackTrace(); } JOptionPane.showMessageDialog(null, s,"考试结束",JOptionPane.ERROR_MESSAGE); } }); //首页 b1.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ care.first(pnl3); count = 1; JLpage.setText("第" + count + "页"); } }); //前一页 b2.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ care.previous(pnl3); if ( count > 1 && count <=10) { count --; }else { count = 10 ; } JLpage.setText("第" + count + "页"); } }); //下一页 b3.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ care.next(pnl3); if ( count >= 1 && count < 10 ) { count ++; }else { count = 1 ; } JLpage.setText("第" + count + "页"); } }); //尾页 b4.addActionListener(new ActionListener(){ public void actionPerformed(ActionEvent e){ care.last(pnl3); count = 10; JLpage.setText("第" + count + "页"); } }); } public Test_Interface() { this.setTitle("开始考试"); this.setSize(550, 400); this.setLocationRelativeTo(null); //将此窗口置于屏幕的中央 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(new BorderLayout(20,20)); //设置 各组件间水平垂直间隔为20像素 countDown(); pnl1.add(JLhour); pnl1.add(JLminute); pnl1.add(JLseconds); JLpage.setText("第" + count + "页"); pnl2.setLayout(new FlowLayout()); pnl2.add(JLgross); pnl2.add(JLpage);//页数 pnl2.add(jl1); pnl2.add(JLtime); pnl2.add(pnl1); pnl2.add(JB1); this.add(pnl2,BorderLayout.NORTH); pnl3.setLayout(care); this.add(pnl3,BorderLayout.CENTER); pnl3.setBorder(BorderFactory.createLoweredBevelBorder()); //边框 for(int i = 0 , k = 0; i < 10 ; i++ ) { JPanel p = new JPanel(); p.setLayout(new GridLayout(5,2,20,20)); //网格布局5行2列,水平垂直间距都设为20像素 for(int j = 0 ; j < 5 ; j++) { a=(int)(Math.random()*100+1); b=(int)(Math.random()*100+1); c=(int)(Math.random()*100+1); jl[k] = new JLabel(a + "+" + b + "-" + c + "="); jl[k].setFont(new Font("黑体",Font.BOLD,15)); p.add(jl[k]); answer[k] = a + b - c; jtf[k] = new JTextField(6); p.add(jtf[k]); k++; } pnl3.add(p); } pnl4.setLayout(new GridLayout(1,4)); pnl4.add(b1); pnl4.add(b2); pnl4.add(b3); pnl4.add(b4); this.add(pnl4, BorderLayout.SOUTH); //美化界面 try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (Exception e) { e.printStackTrace(); } Event(); setVisible(true); }
// public static void main(String[] args){
//
// new Test_Interface();
//
// }
}
平均分统计 Average_Score.java
import java.awt.Color;
import java.awt.Font;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JLabel;
public class Average_Score { private int a; private double c = 0; private double d = 0; private int e; private String f; private static JFrame h = new JFrame( ); private static JLabel i = new JLabel(); //标签 private static JLabel j = new JLabel(); public Average_Score() throws IOException{ BufferedReader input = new BufferedReader(new FileReader("信息收集.txt")); while(( f = input.readLine() ) != null) { System.out.println(input.readLine()); String k[] = f.split(":"); a = Integer.parseInt((k[1])); c = c + a; e ++; } d = c / e; if(e == 0) { d = 0; } h.setTitle("平均分查看"); h.setLayout(null); //取消默认布局 h.setSize(400,180); //设置大小 h.setLocationRelativeTo(null); //使窗口显示在屏幕中央 h.getContentPane().setBackground(Color.YELLOW); //内容面板背景 i.setText("参加考试人数为 "+e); h.getContentPane().add(i); i.setBounds(45, 15, 120, 50); j.setText("平均分为 "+d); h.getContentPane().add(j); j.setBounds(45, 50, 120, 50); h.setVisible(true); }
}
没咯.水平有限,喜欢点赞哦~
文章来源: blog.csdn.net,作者:ZZDT0917,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/ZZDT099/article/details/116211456
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END