Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.*;
- import java.awt.event.*;
- import java.io.*;
- import javax.swing.*;
- public class KBowlChallenge implements ActionListener{
- JButton startBtn = new JButton("Start");
- JButton answerBtn = new JButton("Answer");
- JButton nextBtn = new JButton("Next");
- TextArea questionTA = new TextArea("Welcome to the challenge Mode", 4,30, TextArea.SCROLLBARS_VERTICAL_ONLY);
- TextField answerTF = new TextField(10);
- TextField responseTF = new TextField(10);
- TextField rightTF =new TextField("0", 2);
- TextField wrongTF = new TextField("0", 2);
- TextField scoreTF = new TextField(3);
- int numRight = 0;
- int numWrong = 0;
- int questionNumber = 0;
- static QuestionAnswer[] questAns = new QuestionAnswer[60];
- @SuppressWarnings("unused")
- public static void main(String[] args){
- KBowlOpps.fillArrays();
- for(int i=0;i<questAns.length;i++){
- questAns[i] = new QuestionAnswer();
- }
- KBowlChallenge k = new KBowlChallenge();
- }
- public KBowlChallenge(){
- JFrame w = new JFrame();
- JPanel p = new JPanel();
- JLabel scoreLbl= new JLabel("Score: ");
- JLabel rightLbl = new JLabel("Correct: ");
- JLabel wrongLbl = new JLabel("Wrong: ");
- w.setSize(300,350);
- w.setTitle("Challenge Mode");
- w.setLocationRelativeTo(null);
- w.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- w.setVisible(true);
- p.setLayout(new FlowLayout());
- p.add(startBtn);
- startBtn.addActionListener(this);
- //p.add(Box.createHorizontalStrut(80));
- //break
- p.add(questionTA);
- questionTA.setEditable(false);
- //p.add(Box.createHorizontalStrut(80));
- //break
- p.add(answerTF);
- //p.add(Box.createHorizontalStrut(90));
- //break
- p.add(answerBtn);
- answerBtn.addActionListener(this);
- p.add(Box.createHorizontalStrut(60));
- p.add(responseTF);
- p.add(nextBtn);
- nextBtn.addActionListener(this);
- p.add(Box.createHorizontalStrut(50));
- //break
- p.add(scoreLbl);
- p.add(scoreTF);
- p.add(rightLbl);
- p.add(rightTF);
- p.add(wrongLbl);
- p.add(wrongTF);
- w.add(p);
- }
- public void actionPerformed(ActionEvent e){
- if(e.getSource() == this.startBtn){
- questionTA.setText("");
- questionTA.append(questAns[questionNumber].getQuestion());
- System.out.print("Test");
- questAns = KBowlOpps.getChallengeQuestions();
- }
- if(e.getSource() == this.nextBtn){
- questionNumber++;
- questionTA.setText("");
- answerTF.setText("");
- questionTA.append(questAns[questionNumber].getQuestion());
- }
- if(e.getSource() == this.answerBtn){
- String answer = questAns[questionNumber].getAnswer();
- String input = answerTF.getText();
- System.out.println(answer);
- System.out.println(answerTF.getText());
- if(answer == input){
- responseTF.setText("Correct!");
- numRight++;
- }else{
- responseTF.setText("Incorrect!");
- numWrong++;
- }
- rightTF.setText(numRight+"");
- wrongTF.setText(numWrong+"");
- }
- }
- }
- ============================================================================================
- Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: null string
- at sun.awt.windows.WTextAreaPeer.insertText(Native Method)
- at sun.awt.windows.WTextAreaPeer.insert(Unknown Source)
- at java.awt.TextArea.insertText(Unknown Source)
- at java.awt.TextArea.appendText(Unknown Source)
- at java.awt.TextArea.append(Unknown Source)
- at KBowlChallenge.actionPerformed(KBowlChallenge.java:86)
- at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
- at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
- at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
- at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
- at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
- at java.awt.Component.processMouseEvent(Unknown Source)
- at javax.swing.JComponent.processMouseEvent(Unknown Source)
- at java.awt.Component.processEvent(Unknown Source)
- at java.awt.Container.processEvent(Unknown Source)
- at java.awt.Component.dispatchEventImpl(Unknown Source)
- at java.awt.Container.dispatchEventImpl(Unknown Source)
- at java.awt.Component.dispatchEvent(Unknown Source)
- at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
- at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
- at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
- at java.awt.Container.dispatchEventImpl(Unknown Source)
- at java.awt.Window.dispatchEventImpl(Unknown Source)
- at java.awt.Component.dispatchEvent(Unknown Source)
- at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
- at java.awt.EventQueue.access$200(Unknown Source)
- at java.awt.EventQueue$3.run(Unknown Source)
- at java.awt.EventQueue$3.run(Unknown Source)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
- at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
- at java.awt.EventQueue$4.run(Unknown Source)
- at java.awt.EventQueue$4.run(Unknown Source)
- at java.security.AccessController.doPrivileged(Native Method)
- at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
- at java.awt.EventQueue.dispatchEvent(Unknown Source)
- at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
- at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
- at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
- at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
- at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
- at java.awt.EventDispatchThread.run(Unknown Source)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement