MNov
07-23-2007, 01:04 AM
Okay, I have had it with this stupid thing I'm trying to code. What I'm trying to do is make an Applet that is like a study game. If you get it right, then the question is removed, else it stays and you randomly get another question. I coded it before but it had to access txt files. Now I want to stick the questions into the code itself but ArrayList and Arrays don't seem to want to run with the main method which I can't use because it's an Applet. here's the code, hopefully someone smart with a lot of time and find the error and fix it (or provide an alternative).
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Random;
public class Quiz extends JApplet
{
private int WIDTH = 400;
private int HEIGHT = 200;
private JFrame frame;
private JPanel panel;
private JLabel inputLabel, outputLabel, resultLabel;
private JButton nextQ, Ans, WQues;
private JTextField question;
ArrayList questionA = new ArrayList();
ArrayList answerA = new ArrayList();
questionA.add(Abhor);
questionA.add(Bigot);
questionA.add(Counterfeit);
questionA.add(Enfranchise);
questionA.add(Hamper);
questionA.add(Kindle);
questionA.add(Noxious);
questionA.add(Placid);
questionA.add(Remuneration);
questionA.add(Talisman);
questionA.add(Abrasive);
questionA.add(Bilk);
questionA.add(Covert);
questionA.add(Engender);
questionA.add(Hangar);
questionA.add(Knotty);
questionA.add(Nuance);
questionA.add(Plagiarism);
questionA.add(Renown);
questionA.add(Tangent);
questionA.add(Abrasiveness);
questionA.add(Billowing);
questionA.add(Cower);
questionA.add(Enhance);
questionA.add(Harangue);
questionA.add(Labyrinth);
questionA.add(Nullify);
questionA.add(Plaintiff);
questionA.add(Replete);
questionA.add(Tangible);
questionA.add(Abrogate);
questionA.add(Blasphemy);
questionA.add(Credible);
questionA.add(Enigma);
questionA.add(Harbingers);
questionA.add(Labyrinthine);
questionA.add(Nuzzle);
questionA.add(Plaudit);
questionA.add(Reprehensible);
questionA.add(Tardy);
questionA.add(Absolution);
questionA.add(Blatant);
questionA.add(Creditable);
questionA.add(Ensconce);
questionA.add(Hasten);
questionA.add(Laceration);
questionA.add(Obdurate);
questionA.add(Plausible);
questionA.add(Reprieve);
questionA.add(Tawdry);
questionA.add(Abstain);
questionA.add(Blighted);
questionA.add(Credulous);
questionA.add(Enshroud);
questionA.add(Haughtiness);
questionA.add(Lachrymose);
questionA.add(Obfuscate);
questionA.add(Plethora);
questionA.add(Repudiate);
questionA.add(Tedium);
questionA.add(Abstemious);
questionA.add(Blithe);
questionA.add(Crepuscular);
questionA.add(Enunciation);
questionA.add(Headstrong);
questionA.add(Lackluster);
questionA.add(Objective);
questionA.add(Pliable);
questionA.add(Rescind);
questionA.add(Temper);
questionA.add(Abstruse);
questionA.add(Blunderbuss);
questionA.add(Cringe);
questionA.add(Envenom);
questionA.add(Hedonism);
questionA.add(Laconic);
questionA.add(Oblique);
questionA.add(Plumage);
questionA.add(Resignation);
questionA.add(Tenacious);
questionA.add(Accolade);
questionA.add(Bolster);
questionA.add(Cryptic);
questionA.add(Ephemeral);
questionA.add(Lamentation);
questionA.add(Obliterate);
questionA.add(Plummet);
questionA.add(Resolution);
questionA.add(Tentative);
questionA.add(Acquiesce);
questionA.add(Bombast);
questionA.add(Curtail);
questionA.add(Epicure);
questionA.add(Heed);
questionA.add(Lampoon);
questionA.add(Oblivious);
questionA.add(Podium);
questionA.add(Resonant);
questionA.add(Tenuous);
answerA.add(hate);
answerA.add(narrow);
answerA.add(fake, false);
answerA.add(giving voting rights);
answerA.add(hinder, obstruct);
answerA.add(to start a fire);
answerA.add(harmful, poisonous, lethal);
answerA.add(calm, peaceful);
answerA.add(payment for work done);
answerA.add(lucky charm);
answerA.add(rough, coarse, harsh);
answerA.add(cheat, defraud);
answerA.add(hidden, undercover);
answerA.add(cause);
answerA.add(storage area (like garage) for a plane);
answerA.add(complex, difficult to solve);
answerA.add(something subtle, a fine shade of meaning);
answerA.add(taking credit for someone else?s writing or ideas);
answerA.add(fame);
answerA.add(going off the main subject);
answerA.add(harshness, coarseness);
answerA.add(swelling, fluttering, waving);
answerA.add(recoil in fear or servility, shrink away from);
answerA.add(improve, make better or clearer);
answerA.add(noisy attacking speech);
answerA.add(a maze);
answerA.add(to counter, make unimportant);
answerA.add(applicant, petitioner);
answerA.add(full);
answerA.add(can be touched);
answerA.add(cancel, deny, repeal);
answerA.add(speech which offends religious sentiments);
answerA.add(believable);
answerA.add(puzzle, mystery);
answerA.add(indicators, bringers of warnings);
answerA.add(complicated, highly convoluted);
answerA.add(cuddle, snuggle);
answerA.add(statement giving strong praise);
answerA.add(shameful, very bad);
answerA.add(slow, late, overdue, delayed);
answerA.add(forgiveness, pardon, release);
answerA.add(obvious);
answerA.add(praiseworthy);
answerA.add(establish firmly in a position);
answerA.add(hurry, accelerate, rush);
answerA.add(a cut);
answerA.add(stubborn);
answerA.add(can be believed, reasonable);
answerA.add(a respite: postponement of a sentence);
answerA.add(a little value, gaudy);
answerA.add(desist, go without, withdraw);
answerA.add(damaged, destroyed, ruined);
answerA.add(gullible, ready to believe anything);
answerA.add(cover);
answerA.add(arrogance, pride);
answerA.add(tearful, sad);
answerA.add(deliberately make something difficult to understand);
answerA.add(an excess);
answerA.add(shun, eschew);
answerA.add(boredom);
answerA.add(self denying, refraining from indulging );
answerA.add(free);
answerA.add(active at dawn and dusk);
answerA.add(clear pronunciation, accent, articulation);
answerA.add(stubborn, willful);
answerA.add(dull, monotonous, bland);
answerA.add(unbiased, not subjective);
answerA.add(flexible, not stubborn);
answerA.add(retract, repeal);
answerA.add(to moderate, soften );
answerA.add(difficult to understand, obscure );
answerA.add(ancient weapon (type of gun); a clumsy person);
answerA.add(recoil, flinch, shy away);
answerA.add(to cause bitterness and bad feeling);
answerA.add(self indulgence, pleasure);
answerA.add(using few words, brief, short to the point);
answerA.add(indirect, slanting);
answerA.add(feathers of a bird);
answerA.add(acceptance of fate);
answerA.add(stubborn, resolute, holding firm to a purpose);
answerA.add(tribute, honor, praise);
answerA.add(support, prop up);
answerA.add(puzzling, enigmatic);
answerA.add(short);
answerA.add(expression of regret or sorrow);
answerA.add(destroy, demolish, eradicate);
answerA.add(fall suddenly and steeply);
answerA.add(determination);
answerA.add(not certain);
answerA.add(to agree to, give in to);
answerA.add(arrogant, pompous language);
answerA.add(cut short);
answerA.add(someone who appreciates good food and drink);
answerA.add(listens to);
answerA.add(ridicule, spoof);
answerA.add(totally unaware);
answerA.add(raised platform);
answerA.add(echoing);
answerA.add(flimsy, not solid);
Random gen = new Random();
int qnum=gen.nextInt(questionA.size());
public void init()
{
frame = new JFrame ("Quizzer");
Container contentPane = frame.getContentPane();
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
inputLabel = new JLabel ("");
inputLabel.setMaximumSize(new Dimension(500, 130));
inputLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
Font f =new Font("Serif", Font.ITALIC, 20);
inputLabel.setFont(f);
inputLabel.setText("Question: "+questionA.get(qnum).toString());
resultLabel = new JLabel ("Answer: ");
nextQ = new JButton ("I got it Right");
nextQ.addActionListener (new TempListener2());
Ans = new JButton ("Answer");
Ans.addActionListener (new TempListener());
resultLabel.setMaximumSize(new Dimension(500, 200));
resultLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
resultLabel.setFont(f);
WQues = new JButton ("I got it Wrong");
WQues.addActionListener (new TempListener3());
panel = new JPanel();
panel.setPreferredSize (new Dimension(WIDTH, HEIGHT));
panel.setBackground (Color.yellow);
SpringLayout layout = new SpringLayout();
panel.setLayout( layout);
panel.add (inputLabel);
panel.add (Ans);
panel.add (resultLabel);
panel.add (nextQ);
panel.add (WQues);
layout.putConstraint(SpringLayout.WEST, inputLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.EAST, inputLabel, 5, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, inputLabel, 15, SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.NORTH, Ans, 30, SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.EAST, Ans, -5, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, resultLabel, 30, SpringLayout.SOUTH, inputLabel);
layout.putConstraint(SpringLayout.WEST, resultLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, nextQ, 10, SpringLayout.SOUTH, Ans);
layout.putConstraint(SpringLayout.EAST, nextQ, -5, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, WQues, 10, SpringLayout.SOUTH, nextQ);
layout.putConstraint(SpringLayout.EAST, WQues, -5, SpringLayout.EAST, contentPane);
frame.getContentPane().add (panel);
}
public void display()
{
frame.pack();
frame.show();
}
private class TempListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
resultLabel.setText ("Answer: "+answerA.get(qnum).toString());
}
}
private class TempListener2 implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
questionA.remove(qnum);
answerA.remove(qnum);
qnum=gen.nextInt(questionA.size());
inputLabel.setText ("Question: "+questionA.get(qnum).toString());
resultLabel.setText ("Answer: ");
}
}
private class TempListener3 implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
qnum=gen.nextInt(questionA.size());
inputLabel.setText ("Question: "+questionA.get(qnum).toString());
resultLabel.setText ("Answer: ");
}
}
}
This is how it's supposed to look like
http://img.photobucket.com/albums/v299/YRPNova/e41eaf8f.jpg
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.ArrayList;
import java.util.Random;
public class Quiz extends JApplet
{
private int WIDTH = 400;
private int HEIGHT = 200;
private JFrame frame;
private JPanel panel;
private JLabel inputLabel, outputLabel, resultLabel;
private JButton nextQ, Ans, WQues;
private JTextField question;
ArrayList questionA = new ArrayList();
ArrayList answerA = new ArrayList();
questionA.add(Abhor);
questionA.add(Bigot);
questionA.add(Counterfeit);
questionA.add(Enfranchise);
questionA.add(Hamper);
questionA.add(Kindle);
questionA.add(Noxious);
questionA.add(Placid);
questionA.add(Remuneration);
questionA.add(Talisman);
questionA.add(Abrasive);
questionA.add(Bilk);
questionA.add(Covert);
questionA.add(Engender);
questionA.add(Hangar);
questionA.add(Knotty);
questionA.add(Nuance);
questionA.add(Plagiarism);
questionA.add(Renown);
questionA.add(Tangent);
questionA.add(Abrasiveness);
questionA.add(Billowing);
questionA.add(Cower);
questionA.add(Enhance);
questionA.add(Harangue);
questionA.add(Labyrinth);
questionA.add(Nullify);
questionA.add(Plaintiff);
questionA.add(Replete);
questionA.add(Tangible);
questionA.add(Abrogate);
questionA.add(Blasphemy);
questionA.add(Credible);
questionA.add(Enigma);
questionA.add(Harbingers);
questionA.add(Labyrinthine);
questionA.add(Nuzzle);
questionA.add(Plaudit);
questionA.add(Reprehensible);
questionA.add(Tardy);
questionA.add(Absolution);
questionA.add(Blatant);
questionA.add(Creditable);
questionA.add(Ensconce);
questionA.add(Hasten);
questionA.add(Laceration);
questionA.add(Obdurate);
questionA.add(Plausible);
questionA.add(Reprieve);
questionA.add(Tawdry);
questionA.add(Abstain);
questionA.add(Blighted);
questionA.add(Credulous);
questionA.add(Enshroud);
questionA.add(Haughtiness);
questionA.add(Lachrymose);
questionA.add(Obfuscate);
questionA.add(Plethora);
questionA.add(Repudiate);
questionA.add(Tedium);
questionA.add(Abstemious);
questionA.add(Blithe);
questionA.add(Crepuscular);
questionA.add(Enunciation);
questionA.add(Headstrong);
questionA.add(Lackluster);
questionA.add(Objective);
questionA.add(Pliable);
questionA.add(Rescind);
questionA.add(Temper);
questionA.add(Abstruse);
questionA.add(Blunderbuss);
questionA.add(Cringe);
questionA.add(Envenom);
questionA.add(Hedonism);
questionA.add(Laconic);
questionA.add(Oblique);
questionA.add(Plumage);
questionA.add(Resignation);
questionA.add(Tenacious);
questionA.add(Accolade);
questionA.add(Bolster);
questionA.add(Cryptic);
questionA.add(Ephemeral);
questionA.add(Lamentation);
questionA.add(Obliterate);
questionA.add(Plummet);
questionA.add(Resolution);
questionA.add(Tentative);
questionA.add(Acquiesce);
questionA.add(Bombast);
questionA.add(Curtail);
questionA.add(Epicure);
questionA.add(Heed);
questionA.add(Lampoon);
questionA.add(Oblivious);
questionA.add(Podium);
questionA.add(Resonant);
questionA.add(Tenuous);
answerA.add(hate);
answerA.add(narrow);
answerA.add(fake, false);
answerA.add(giving voting rights);
answerA.add(hinder, obstruct);
answerA.add(to start a fire);
answerA.add(harmful, poisonous, lethal);
answerA.add(calm, peaceful);
answerA.add(payment for work done);
answerA.add(lucky charm);
answerA.add(rough, coarse, harsh);
answerA.add(cheat, defraud);
answerA.add(hidden, undercover);
answerA.add(cause);
answerA.add(storage area (like garage) for a plane);
answerA.add(complex, difficult to solve);
answerA.add(something subtle, a fine shade of meaning);
answerA.add(taking credit for someone else?s writing or ideas);
answerA.add(fame);
answerA.add(going off the main subject);
answerA.add(harshness, coarseness);
answerA.add(swelling, fluttering, waving);
answerA.add(recoil in fear or servility, shrink away from);
answerA.add(improve, make better or clearer);
answerA.add(noisy attacking speech);
answerA.add(a maze);
answerA.add(to counter, make unimportant);
answerA.add(applicant, petitioner);
answerA.add(full);
answerA.add(can be touched);
answerA.add(cancel, deny, repeal);
answerA.add(speech which offends religious sentiments);
answerA.add(believable);
answerA.add(puzzle, mystery);
answerA.add(indicators, bringers of warnings);
answerA.add(complicated, highly convoluted);
answerA.add(cuddle, snuggle);
answerA.add(statement giving strong praise);
answerA.add(shameful, very bad);
answerA.add(slow, late, overdue, delayed);
answerA.add(forgiveness, pardon, release);
answerA.add(obvious);
answerA.add(praiseworthy);
answerA.add(establish firmly in a position);
answerA.add(hurry, accelerate, rush);
answerA.add(a cut);
answerA.add(stubborn);
answerA.add(can be believed, reasonable);
answerA.add(a respite: postponement of a sentence);
answerA.add(a little value, gaudy);
answerA.add(desist, go without, withdraw);
answerA.add(damaged, destroyed, ruined);
answerA.add(gullible, ready to believe anything);
answerA.add(cover);
answerA.add(arrogance, pride);
answerA.add(tearful, sad);
answerA.add(deliberately make something difficult to understand);
answerA.add(an excess);
answerA.add(shun, eschew);
answerA.add(boredom);
answerA.add(self denying, refraining from indulging );
answerA.add(free);
answerA.add(active at dawn and dusk);
answerA.add(clear pronunciation, accent, articulation);
answerA.add(stubborn, willful);
answerA.add(dull, monotonous, bland);
answerA.add(unbiased, not subjective);
answerA.add(flexible, not stubborn);
answerA.add(retract, repeal);
answerA.add(to moderate, soften );
answerA.add(difficult to understand, obscure );
answerA.add(ancient weapon (type of gun); a clumsy person);
answerA.add(recoil, flinch, shy away);
answerA.add(to cause bitterness and bad feeling);
answerA.add(self indulgence, pleasure);
answerA.add(using few words, brief, short to the point);
answerA.add(indirect, slanting);
answerA.add(feathers of a bird);
answerA.add(acceptance of fate);
answerA.add(stubborn, resolute, holding firm to a purpose);
answerA.add(tribute, honor, praise);
answerA.add(support, prop up);
answerA.add(puzzling, enigmatic);
answerA.add(short);
answerA.add(expression of regret or sorrow);
answerA.add(destroy, demolish, eradicate);
answerA.add(fall suddenly and steeply);
answerA.add(determination);
answerA.add(not certain);
answerA.add(to agree to, give in to);
answerA.add(arrogant, pompous language);
answerA.add(cut short);
answerA.add(someone who appreciates good food and drink);
answerA.add(listens to);
answerA.add(ridicule, spoof);
answerA.add(totally unaware);
answerA.add(raised platform);
answerA.add(echoing);
answerA.add(flimsy, not solid);
Random gen = new Random();
int qnum=gen.nextInt(questionA.size());
public void init()
{
frame = new JFrame ("Quizzer");
Container contentPane = frame.getContentPane();
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
inputLabel = new JLabel ("");
inputLabel.setMaximumSize(new Dimension(500, 130));
inputLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
Font f =new Font("Serif", Font.ITALIC, 20);
inputLabel.setFont(f);
inputLabel.setText("Question: "+questionA.get(qnum).toString());
resultLabel = new JLabel ("Answer: ");
nextQ = new JButton ("I got it Right");
nextQ.addActionListener (new TempListener2());
Ans = new JButton ("Answer");
Ans.addActionListener (new TempListener());
resultLabel.setMaximumSize(new Dimension(500, 200));
resultLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
resultLabel.setFont(f);
WQues = new JButton ("I got it Wrong");
WQues.addActionListener (new TempListener3());
panel = new JPanel();
panel.setPreferredSize (new Dimension(WIDTH, HEIGHT));
panel.setBackground (Color.yellow);
SpringLayout layout = new SpringLayout();
panel.setLayout( layout);
panel.add (inputLabel);
panel.add (Ans);
panel.add (resultLabel);
panel.add (nextQ);
panel.add (WQues);
layout.putConstraint(SpringLayout.WEST, inputLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.EAST, inputLabel, 5, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, inputLabel, 15, SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.NORTH, Ans, 30, SpringLayout.NORTH, contentPane);
layout.putConstraint(SpringLayout.EAST, Ans, -5, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, resultLabel, 30, SpringLayout.SOUTH, inputLabel);
layout.putConstraint(SpringLayout.WEST, resultLabel, 5, SpringLayout.WEST, contentPane);
layout.putConstraint(SpringLayout.NORTH, nextQ, 10, SpringLayout.SOUTH, Ans);
layout.putConstraint(SpringLayout.EAST, nextQ, -5, SpringLayout.EAST, contentPane);
layout.putConstraint(SpringLayout.NORTH, WQues, 10, SpringLayout.SOUTH, nextQ);
layout.putConstraint(SpringLayout.EAST, WQues, -5, SpringLayout.EAST, contentPane);
frame.getContentPane().add (panel);
}
public void display()
{
frame.pack();
frame.show();
}
private class TempListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
resultLabel.setText ("Answer: "+answerA.get(qnum).toString());
}
}
private class TempListener2 implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
questionA.remove(qnum);
answerA.remove(qnum);
qnum=gen.nextInt(questionA.size());
inputLabel.setText ("Question: "+questionA.get(qnum).toString());
resultLabel.setText ("Answer: ");
}
}
private class TempListener3 implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
qnum=gen.nextInt(questionA.size());
inputLabel.setText ("Question: "+questionA.get(qnum).toString());
resultLabel.setText ("Answer: ");
}
}
}
This is how it's supposed to look like
http://img.photobucket.com/albums/v299/YRPNova/e41eaf8f.jpg