Here is my code:-
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Administrator
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.event.*;
import java.awt.*;
public class MyQuiz {
int score;
JFrame frame;
String[] questions = {"Who invented the internet?", "Who invented the first space rocket?", "What is the currency of Sweden?", "Which country has the largest telescope?", "Entomology is the study of: ", "Who is the current president of South Africa?", "Who discovered oxygen?", "Which is the largest temple and where is it?", "Where is the tomb of Akbar located?", " Which state or union territory has French as an official language?"};
String[] answers = {"Tim Berners-Lee", "Joseph Godard", "Krona", "Hawaii", "Insects", "Jacob Zuma", "Joseph Priestly", "Angkor Wat In Cambodia", "Sikandra", "Pondicherry"};
String[] correctorwrong = new String[10];
public class startQuizListener implements ActionListener {
public void actionPerformed(ActionEvent ev) {
JOptionPane.showMessageDialog(null, "Welcome to the GK quiz. Your score will be\nshown at the end. Please note that this game is\ncase sensitive. So please capitalize the first\nletter of each word. Also note that spaces, hyphens,\ncolons etc are all necessary.", "GK Quiz", 1);
for (int i = 0; i < questions.length - 1; i++) {
String ans = JOptionPane.showInputDialog(frame, questions[i], "GK Quiz", 3);
if (ans.equals(answers[i])) {
correctorwrong[i] = "Correct";
}
else {
correctorwrong[i] = "Wrong";
}
}
JOptionPane.showMessageDialog(frame, "1." + correctorwrong[0] +"\n" + "2." + correctorwrong[1] +"\n" + "3." + correctorwrong[2] +"\n" + "4." + correctorwrong[3] +"\n" + "5." + correctorwrong[4] +"\n" + "6." + correctorwrong[5] +"\n" + "7." + correctorwrong[6] +"\n" + "8." + correctorwrong[7] +"\n" + "9." + correctorwrong[8] +"\n" + "10." + correctorwrong[9]);
}
}
Image im = new ImageIcon("finalstaticlogo.jpg").getImage();
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
MyQuiz mcq = new MyQuiz();
mcq.go();
}
public void go() {
frame = new JFrame("GK Quiz");
JButton button = new JButton("Start the quiz!");
button.addActionListener(new startQuizListener());
MyPanel p = new MyPanel();
frame.getContentPane().add(p);
frame.getContentPane().add("South", button);
frame.setSize(550, 412);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setResizable(false);
}
private class MyPanel extends JPanel {
public void paintComponent(Graphics g) {
g.drawImage(im, 0, 0, this);
}
}
}
When I run the program, I click the button and nothing happens. Why?
PS-The image won't work anyway, just for testing reasons, I didn't put it in the same folder as my class file ;)