Results 1 to 16 of 16

Thread: Method doesn't perform

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Jan 2007
    Posts
    10

    Method doesn't perform

    Hi all,

    i tried to make an application, which would simplify the proces of learning words.. I'm dutch, so I sometimes have to learn translations from english to dutch and viceversa.

    This is my application. I got rid of the compiling-errors, but the method setQuestion doesn't perform (see the picture).

    Who can help?

    Code:
    class Main {
    	public static void main(String[] arg) {
    		Words words = new Words ();
    		words.setQuestion();
    	}
    }
    Code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    
    public class Words extends JFrame implements ActionListener {
    	private JTextField tfanswer;
    	private JLabel lquestion;
    	private JLabel lempty;
    	private JLabel lanswer;
    	private JButton bsubmit;
    	private JButton bnext;
    	private JButton bstop;
    	private Random r = new Random();
    	private int i;
    
    	public Words() {
    		//Making the textfields, labels and buttons
    		tfanswer = new JTextField(20);
    		lquestion = new JLabel("", JLabel.CENTER);
    		lempty = new JLabel("", JLabel.CENTER);
    		lanswer = new JLabel("", JLabel.CENTER);
    		bsubmit = new JButton("Submit");
    		bnext = new JButton("Next");
    		bstop = new JButton("Stop");
    		bnext.addActionListener(this);
    		bsubmit.addActionListener(this);
    		bstop.addActionListener(this);
    
    
    		JPanel p1 = new JPanel();
    		p1.setLayout(new GridLayout(2, 2));
    		p1.add(lquestion);
    		p1.add(tfanswer);
    		p1.add(lempty);
    		p1.add(lanswer);
    
    		JPanel p2 = new JPanel();
    		p2.add(bsubmit);
    		p2.add(bnext);
    		p2.add(bstop);
    
    		Container c = getContentPane();
    			c.add(p1, BorderLayout.CENTER);
    			c.add(p2, BorderLayout.SOUTH);
    			setTitle("Learning Words");
    			setSize(400,150);
    			setVisible(true);
    			setDefaultCloseOperation(EXIT_ON_CLOSE);
    	}
    
    	String[] question = {
    		"question1",
    		"question2",
    		"question3",
    	};
    
    	String[] answer = {
    		"answer1",
    		"answer2",
    		"answer3"
    	};
    
    	public void setQuestion() {
    		lquestion.setText(question[0]);
    	}
    
    	public void nextQuestion() {
    		i = r.nextInt(3);
    		lquestion.setText(question[i]);
    	}
    
    	public void actionPerformed(ActionEvent e) {
    		if (e.getActionCommand().equals("Submit")) {
    
    			String temp = tfanswer.getText();
    
    			if (temp.equals(answer[i])) {
    				lanswer.setText("Correct!");
    			}
    			else {
    				lanswer.setText("Wrong, the answer is " + answer[0]);
    			}
    		}
    		else if (e.getActionCommand().equals("Next")) {
    		  this.nextQuestion();
    		}
    		else if (e.getActionCommand().equals("Stop")) {
    			System.exit(0);
    		}
    	}
    }
    Last edited by Michail; Jan 22nd, 2007 at 09:46 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width