当前位置: 技术问答>java相关
为何说applet没有初始化,请大家帮忙找错
来源: 互联网 发布时间:2015-02-07
本文导语: 一本书上的例子,无法通过。 源文件:Quizem.java import java.awt.*; import java.awt.event.*; import java.applet.*; import java.io.*; import java.util.*; import java.net.*; /**Quizem*/ public class Quizem extends Applet{ QuizFrame quizFrame=null; public vo...
一本书上的例子,无法通过。
源文件:Quizem.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.util.*;
import java.net.*;
/**Quizem*/
public class Quizem extends Applet{
QuizFrame quizFrame=null;
public void init(){
try{
//construct the URL of the quiz file string
URL quizURL =new URL(getCodeBase(),getParameter("QUIZFILE"));
//construct a quizFrame with a quizengime
quizFrame=new QuizFrame(new QuizEngine(quizURL),this);
//pop up the window
quizFrame.show();
quizFrame.displayNextQuizItem();
}
catch(MalformedURLException e){
showStatus("Invalid Quiz URL:"+getParameter("QUIZFILE"));
}
}
public void start(){
super.start();
quizFrame.show();
}
public void stop(){
quizFrame.setVisible(false);
}
}
class QuizEngine{
Vector quizItemVector=new Vector();
Enumeration enum=null;
int currentItem=0;
/*construct a QuizEngine,loading quiz items*/
public QuizEngine(URL quizFileURL){
try{
//open a stream to read the quiz file
InputStream inStream=quizFileURL.openStream();
BufferedReader dataStream=new BufferedReader(new InputStreamReader(inStream));
String inLine=null;
while((inLine=dataStream.readLine())!=null){
quizItemVector.addElement(new QuizItem(inLine,quizFileURL));
}
enum=quizItemVector.elements();
}
catch(IOException e){
//handle IO errors here
}
}
public QuizItem getNextQuizItem(){
if(enum.hasMoreElements()){
QuizItem q=(QuizItem)enum.nextElement();
currentItem++;
return q;
}
else{
return null;
}
}
public String getStatusString(){
return("Question"+currentItem+"of"+quizItemVector.size());
}
}
class QuizItem{
final static int ANSWERCOUNT=4;
String question=null;
String[]answerList=new String[ANSWERCOUNT];
int correctAnswer;
/*construct a quizitem from a'$' delimitted input line*/
public QuizItem(String s,URL url){
StringTokenizer t=new StringTokenizer(s,"$n");
question=t.nextToken();
for(int i=0;i
源文件:Quizem.java
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.io.*;
import java.util.*;
import java.net.*;
/**Quizem*/
public class Quizem extends Applet{
QuizFrame quizFrame=null;
public void init(){
try{
//construct the URL of the quiz file string
URL quizURL =new URL(getCodeBase(),getParameter("QUIZFILE"));
//construct a quizFrame with a quizengime
quizFrame=new QuizFrame(new QuizEngine(quizURL),this);
//pop up the window
quizFrame.show();
quizFrame.displayNextQuizItem();
}
catch(MalformedURLException e){
showStatus("Invalid Quiz URL:"+getParameter("QUIZFILE"));
}
}
public void start(){
super.start();
quizFrame.show();
}
public void stop(){
quizFrame.setVisible(false);
}
}
class QuizEngine{
Vector quizItemVector=new Vector();
Enumeration enum=null;
int currentItem=0;
/*construct a QuizEngine,loading quiz items*/
public QuizEngine(URL quizFileURL){
try{
//open a stream to read the quiz file
InputStream inStream=quizFileURL.openStream();
BufferedReader dataStream=new BufferedReader(new InputStreamReader(inStream));
String inLine=null;
while((inLine=dataStream.readLine())!=null){
quizItemVector.addElement(new QuizItem(inLine,quizFileURL));
}
enum=quizItemVector.elements();
}
catch(IOException e){
//handle IO errors here
}
}
public QuizItem getNextQuizItem(){
if(enum.hasMoreElements()){
QuizItem q=(QuizItem)enum.nextElement();
currentItem++;
return q;
}
else{
return null;
}
}
public String getStatusString(){
return("Question"+currentItem+"of"+quizItemVector.size());
}
}
class QuizItem{
final static int ANSWERCOUNT=4;
String question=null;
String[]answerList=new String[ANSWERCOUNT];
int correctAnswer;
/*construct a quizitem from a'$' delimitted input line*/
public QuizItem(String s,URL url){
StringTokenizer t=new StringTokenizer(s,"$n");
question=t.nextToken();
for(int i=0;i