public static void exercise(){
Timu();
JFrame f=new JFrame();
f.setTitle("在线答题系统(保留一位小数)");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setExtendedState(JFrame.MAXIMIZED_BOTH);
f.setVisible(true);
//设置窗口的大小和位置
f.setSize(600,500);
f.setLocation(400,100);
f.setLayout(null);
JPanel pan1=new JPanel();
JLabel name1=new JLabel("题目");
pan1.add(name1);
JTextField nameTest7=new JTextField(15);
nameTest7.setBounds(10, 10, 180, 100);
nameTest7.setText(T);
// nameTest1.setPreferredSize(new Dimension(180,100));
pan1.add(nameTest7);
JLabel name2=new JLabel("请输入答案");
pan1.add(name2);
JTextField nameTest1=new JTextField(15);
// String Answer=nameTest1.getText();
//int DaAn=Integer.parseInt(Answer);
nameTest1.setBounds(10, 10, 180, 100);
// nameTest1.setPreferredSize(new Dimension(180,100));
pan1.add(nameTest1);
pan1.setBounds(10, 10, 200, 120);
f.add(pan1);
JPanel pan2=new JPanel();
JLabel name7=new JLabel("正确答案为:");
pan2.add(name7);
JTextField nameTest2=new JTextField(15);
nameTest2.setBounds(300, 10, 180, 100);
// nameTest2.setPreferredSize(new Dimension(180,100));
pan2.add(nameTest2);
pan2.setBounds( 300,10, 200, 120);
f.add(pan2);
JPanel pan3=new JPanel();
pan3.setLayout(null);
JTextField nameTest3=new JTextField(15);
nameTest3.setBounds(10, 60, 480, 200);
nameTest3.setPreferredSize(new Dimension(300,100));
pan3.add(nameTest3);
pan3.setBounds( 10,60, 500, 220);
f.add(pan3);
JPanel pan4 = new JPanel();
JButton btnStart=new JButton("下一题");
btnStart.setBounds(30, 300,30, 30);
btnStart.setPreferredSize(new Dimension(100,80));
btnStart.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int daan=0 ;
String Answer=nameTest1.getText();
if(Answer.equals("")){
nameTest3.setFont(new Font("宋体", Font.PLAIN, 20));
nameTest3.setText(" 请先完成本题 ");
}
if(ID==2){
if(Answer.equals(d)){
nameTest2.setText(d);
Right++;
}else if(!Answer.equals(d) && !Answer.equals("")){
nameTest2.setText(d);
}
}
if(ID==1) {
daan = Integer.parseInt(Answer);
System.out.println(daan);
if (daan == DaAn) {
nameTest2.setText(String.valueOf(DaAn));
Right++;
} else {
nameTest2.setText(String.valueOf(DaAn));
}
}
int res=JOptionPane.showConfirmDialog(null,"是否结束本题","下一题",JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION){
z++;
if(z<i) {
Timu();
nameTest7.setText(T);
nameTest1.setText("");
nameTest2.setText("");
pan1.add(nameTest7);
pan1.setBounds(10, 10, 200, 120);
f.add(pan1);
}else {
nameTest3.setFont(new Font("宋体", Font.PLAIN, 20));
nameTest3.setText(" 已经是最后一题 ");
}
} else {
nameTest3.setFont(new Font("宋体", Font.PLAIN, 20));
nameTest3.setText(" 请继续做题 ");
}
}
});
pan4.add(btnStart);
pan4.setBounds(40, 350, 110, 90);
f.add(pan4);
JPanel pan5 = new JPanel();
JButton btnStart1=new JButton("提交");
btnStart1.setBounds(30, 300,30, 30);
btnStart1.setPreferredSize(new Dimension(100,80));
btnStart1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
int res=JOptionPane.showConfirmDialog(null,"是否提交","是否提交",JOptionPane.YES_NO_OPTION);
if(res==JOptionPane.YES_OPTION){
nameTest3.setFont(new Font("宋体", Font.PLAIN, 20));
nameTest3.setText(" 提交成功 ");
}else {
nameTest3.setFont(new Font("宋体", Font.PLAIN, 20));
nameTest3.setText(" 请继续做题 ");
}
}
});
pan5.add(btnStart1);
pan5.setBounds(190, 350, 110, 90);
f.add(pan5);
JPanel pan6 = new JPanel();
// pan4.setLayout(null);
JButton btnStart2=new JButton("查看分数");
btnStart2.setBounds(30, 300,30, 30);
btnStart2.setPreferredSize(new Dimension(100,80));
btnStart2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//计算用时
nameTest3.setFont(new Font("宋体", Font.PLAIN, 20));
nameTest3.setText(" 一共有"+i+"道题,共答对了:"+Right+"题,得分为:"+20*Right+"分");
}
});
pan6.add(btnStart2);
pan6.setBounds(340, 350, 110, 90);
f.add(pan6);
}