The Artima Developer Community
Sponsored Link

Java Answers Forum
I made a Applet...

1 reply on 1 page. Most recent reply: Nov 19, 2002 9:43 AM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
guy

Posts: 4
Nickname: guy123123
Registered: Nov, 2002

I made a Applet... Posted: Nov 19, 2002 8:09 AM
Reply to this message Reply
Advertisement
My Applet wont work. When i hit the buttons i get this
Exception occured during event dispatching:
java.lang.NullPointerException:
then a long list of errors i guess...

this happens when i click the 2 buttons i made. i dont know why they dont work. Heres my code

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

public class EApplet extends Applet implements ActionListener
{
private Button keysArray[];
private Panel keyPad;
private TextField lcdField;
private TextField QuestionField;
private Label ScoreLabel;
private int Score;
private int i;
private String Questions[];
private int Answers[];
private boolean foundKey;

public void init()
{
foundKey = false;
int i = 1;
int[] Answers = new int[5];
String[] Questions = new String[5];
Questions[1] = "A Tomato is a vegetable.";
Answers[1] = 0;
Questions[2] = "You love this game.";
Answers[2] = 1;
Questions[3] = "Troy is an Idiot!";
Answers[3] = 1;
Questions[4] = "The sun is warm.";
Answers[4] = 1;
lcdField = new TextField(20);
QuestionField = new TextField(20);

ScoreLabel = new Label("0");
Score = 0;

keyPad = new Panel();
keysArray = new Button[3];



setLayout(new BorderLayout());

lcdField.setEditable(false);
QuestionField.setEditable(false);




keysArray[1] = new Button("YES");

keysArray[2] = new Button("NO");

keyPad.setLayout(new GridLayout(1,2));


keyPad.add(keysArray[1]);
keyPad.add(keysArray[2]);




add(lcdField, BorderLayout.NORTH);
add(QuestionField, BorderLayout.SOUTH);
add(ScoreLabel, BorderLayout.EAST);
add(keyPad, BorderLayout.CENTER);
QuestionField.setText(" " + (Questions));


keysArray[1].addActionListener(this);

keysArray[2].addActionListener(this);
i = 0;

}
public void actionPerformed(ActionEvent e)
{
while(i!=5)
{

i = i + 1;

foundKey = false;



QuestionField.setText(""+Questions);

if(e.getSource() == keysArray[1])
{
foundKey = true;

if(Answers == 1)
{

lcdField.setText("You are Correct!!");
Score += 1;
ScoreLabel.setText(" " + (Score));
}
if(Answers == 0)
{

Score -= 1;
ScoreLabel.setText(" " + (Score));
lcdField.setText("You are Incorrect!!");
}
}
if(e.getSource() == keysArray[2])
{

lcdField.setText(""+(Answers));
foundKey = true;

if(Answers == 0)
{

lcdField.setText("You are Correct!!");
Score += 1;
ScoreLabel.setText(" " + (Score));
}
if(Answers == 1)
{

Score -= 1;
ScoreLabel.setText(" " + (Score));
lcdField.setText("You are Incorrect!!");
}
}

}
if(Score == 4)
{
lcdField.setText("You WIN!!!");
}
else
{
lcdField.setText("You lose...");
}
}





}


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: I made a Applet... Posted: Nov 19, 2002 9:43 AM
Reply to this message Reply
I don't even believe this thing will compile, since you have stuff like "if(Answers == 0)" where Answers is an array.

By the way, if you use the java tag when you post, the code will be a lot more readable (see "Formatting Your Post" in the box on the right, when you are composing the post).

Flat View: This topic has 1 reply on 1 page
Topic: do while Previous Topic   Next Topic Topic: Converting integers and binary numbers

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use