I am working in eclipse trying to get html to work with java code.?

Skeeter

New member
applet window keeps saying Parameters not defined but I added a folder that defines parameters just dont know if i am putting it in the right place. here is java code and htmlpackage org.QuizShow;

/*
* QuizShowApplet
* Asks a series of True and False Questions that
* are passed in as parameters and grades the results
*
*/

import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;

public class QuizShow extends Applet
implements ActionListener {

String[] questions;
char[] answers;
int score, nCorrect, currQ;
Label questionLabel, rightWrong;
Checkbox t, f;
CheckboxGroup groupTorF;
Button okButton;

public void init() {
boolean paramsOK = false;
try {
paramsOK = readParams();
} catch (Exception e) { System.out.println(e); }
if (paramsOK) {
setLayout(new BorderLayout());
setBackground(Color.blue);
nCorrect = currQ = 0;
questionLabel = new Label("1. " + questions[0], Label.CENTER);
questionLabel.setFont(new Font("TimesRoman",
Font.BOLD, 16));
questionLabel.setForeground(Color.yellow);
add(questionLabel, BorderLayout.CENTER);
Panel controlPanel = new Panel();
controlPanel.setBackground(SystemColor.control);
groupTorF = new CheckboxGroup();
t = new Checkbox("True", false, groupTorF);
controlPanel.add(t);
f = new Checkbox("False", false, groupTorF);
controlPanel.add(f);
okButton = new Button("That's my final answer!");
okButton.addActionListener(this);
controlPanel.add(okButton);
add(controlPanel, BorderLayout.SOUTH);
rightWrong = new Label("", Label.CENTER);
rightWrong.setForeground(Color.white);
add(rightWrong, BorderLayout.NORTH);
}
else {
add(new Label("Parameters not properly set"));
}
}

protected boolean readParams() throws Exception {
questions = new String[Integer.parseInt(getParameter("nQuestions"))];
answers = getParameter("key").toCharArray();

if (questions.length != answers.length) return false;

for (int i=0; i < questions.length; i++) {
questions = getParameter("Q" + (i + 1));
if (questions == null
|| answers != 'T' && answers != 'F') return false;
}
return true;
}

/*
* Parameters:
* nQuestions - number of questions
* Qn - A question: Qstands for question and n is the question #
* the question number starts at zero and has at least
* nQuestion number of questions e.g. Q1, Q2, Q3, etc.
* key - a series of T's and F's - The answer key. The length
* of the string must be >= nQuestions
*/
public String[][] getParameterInfo() {
return new String[][] {
{"nQuestions", "int", "Number of questions"},
{"Qn", "String", "A Question (n=question#)"},
{"key", "String of T's & F's in order, CAPS", "Answer Key"}
};
}

public void actionPerformed(ActionEvent e) {
Checkbox selected = groupTorF.getSelectedCheckbox();
if (selected == null) return;
if (selected == t && answers[currQ] == 'T'
|| selected == f && answers[currQ] == 'F') {
nCorrect++;
rightWrong.setText("Previous answer: CORRECT");
}
else {
rightWrong.setText("Previous answer: INCORRECT");
}
groupTorF.setSelectedCheckbox(null);
if (currQ == questions.length - 1) {
//very last question
t.setEnabled(false);
f.setEnabled(false);
okButton.setEnabled(false);
questionLabel.setText("Your Score is : "
+ Math.round( ((double)nCorrect) / questions.length * 100)
+ "%");
}
else {
currQ++;
questionLabel.setText((currQ + 1) + ". " + questions[currQ]);
}
}

}

I then placed this in a separate folder

<html>
<head>

<title>Quiz Show</title>
</head>
<body>
<h1 align=center>Quiz Show</title>
<center>
<applet code="QuizShow.class" width=500 height=200>
<param name="nQuestions" value=10>
<param name="Q1" value="This is the first question?">
<param name="Q2" value="Jason Newstead is Metallica's bass player?">
<param name="Q3" value="Dracula translates to ' Son of the Dragon'?">
<param name="Q4" value="Don Vito Corleone was born Vito Andolini?">
<param name="Q5" value="Rhode Island is an island off the coast of New York?">
<param name="Q6" value="Two bits is 25 cents?">
<param name="Q7" value="In Monopoly, Pennsylvania Ave costs $300?">
<param name="Q8" value="In Poker, a four of a kind beats a straight flush?">
<param name="Q9" value="A tomato is a vegetable?">
<param name="Q10" value="Bruce Leroy is the master?">
<param name="key" Value="TFTTFTFFFT">
</applet>
</center>
</body>
</html>
now I cant get them to work together
I was given this code from instructor, just dont know how to make them work together. I have tried to run as web and just get the title. I think it has something to to with init, but cant figure it out from the book or from eclipse help
 
Back
Top