一道有问题的小java
来源:互联网 发布:和男友逛街知乎 编辑:程序博客网 时间:2024/06/10 05:56
这是一个考试系统,有一点点令我头痛的小错误.希望有人能帮我
package demo;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.*;
import java.util.*;
public class iodemo2 extends JFrame implements ActionListener{
JPanel p1,p2,p3,p4;
JLabel lab;
JRadioButton r[]=new JRadioButton[4];
JButton b1,b2,b3,b4;
String str="";
//StringTokenizer str_sub;
File f;
BufferedReader in;
public iodemo2() {
super("考试系统");
this.setSize(300,180);
this.setDefaultCloseOperation(3);
p1=new JPanel();
p1.add(new JLabel("题目"));
lab=new JLabel();
p1.add(lab);
p2=new JPanel();
JRadioButton r[]=new JRadioButton[4];
ButtonGroup rbg=new ButtonGroup();//编组
for(int i=0;i<4;i++){
r[i]=new JRadioButton();
rbg.add(r[i]);
p2.add(r[i]);
}
p3=new JPanel();
b1=new JButton("上一题");
b1.setEnabled(false);
b2=new JButton("下一题");
p3.add(b1);
b2.addActionListener(this);
p3.add(b2);
p4=new JPanel();
b3=new JButton("交卷");
b4=new JButton("查看");
b4.setEnabled(false);
p4.add(b3);
p4.add(b4);
this.getContentPane().setLayout(new GridLayout(4,1));
this.getContentPane().add(p1);
this.getContentPane().add(p2);
this.getContentPane().add(p3);
this.getContentPane().add(p4);
this.setResizable(false);
File f=new File("/a.txt");
try {
BufferedReader in = new BufferedReader(new FileReader(f));
str=in.readLine();
StringTokenizer str_sub=new StringTokenizer(str,"#");
lab.setText(str_sub.nextToken());
for(int i=0;i<4;i++){
r[i].setText(str_sub.nextToken());
}
//str=in.readLine();
} catch (IOException ex) {
}
this.setVisible(true);
}
public static void main(String[] args) {
iodemo2 iodemo2 = new iodemo2();
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b2){
try {
/*
File f=new File("/a.txt");
BufferedReader in = new BufferedReader(new FileReader(f));
if((str=in.readLine())!=null){
StringTokenizer str_sub = new StringTokenizer(str, "#");
this.lab.setText(str_sub.nextToken());
for (int i=0; i<4; i++) {
this.r[i].setText(str_sub.nextToken());
}
}*/
Scanner c = new Scanner(f);
str=c.nextLine();
StringTokenizer str_sub = new StringTokenizer(str, "#");
this.lab.setText(str_sub.nextToken());
for (int i=0; i<4; i++) {
this.r[i].setText(str_sub.nextToken());
}
}
catch (IOException ex) {
javax.swing.JOptionPane.showMessageDialog(null,"有错");
}
catch (NullPointerException ex) {
javax.swing.JOptionPane.showMessageDialog(null,"空对象");
}
}
}
}
说我有个空对象,可我是不知道空对象是哪个.我都晕了
- 一道有问题的小java
- 一道经典的小端存储问题
- 解决一道C++编程的小问题
- 一道Java相关的小程序题(一个无序数组里有99个不重复正整数,范围从......)
- 【JAVA基础小问题】面向对象的特征有哪些方面
- java--一道简单的括号匹配问题
- 一道小题引出的php数据类型转换问题
- 一道DFS的小题: 部分和问题
- Java小白必须会的一道算法题
- 来自电商师妹的一道Java小题
- 一道有争议的智力题
- 一道有挑战性的题
- 一道有挑战性的题
- 一道小的算法题
- 一道自动机的小题
- python的一道小习题
- MySql的一道小练习
- 多重for循环。在马克思手稿中有一道趣味的数学问题。吃饭的问题
- 《西游记》与《红楼梦》之五行学说(z)
- 鲁棒的数据库持久层设计(白皮书)
- 最简单的设计模式—Singleton
- 将VC6的项目转换成VC.Net2003
- javascript高级程序设计读书笔记(一)
- 一道有问题的小java
- ftp客户端库(C编写,平台Linux,Win)
- 删除临时对象
- ASP常用函数介绍
- 什么是框架?
- 接收二进制码流的服务端基本上做出来了
- .Net平台下开发中文语音应用程序
- jaxb 简介
- FCKEdtior初步集成