Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Trying to make Jeopardy Game

  1. #1
    Junior Member
    Join Date
    Nov 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Trying to make Jeopardy Game

    So I'm trying to make this jeopardy game for my Computer Science class and I have a few problems. I need to make the actionevent for the button click, and i need to have a text box appear with the question and a space to answer when a button is clicked. and if you get it right there needs to be a dialogue saying right, and if its incorrect it needs to say wrong.

    Its due at midnight and my TA cancelled class today!! Im screwed.

    import javax.swing.*;
    import java.awt.*;
     
    public class BasicWindow extends JFrame{
     
    	private int width = 800;
    	private int height = 800;
    	private int score;
     
    	/**  
    	 * Method:	Constructor method.
    	 * Purpose: 	Creates a new object (instance) of this class.  
    	 * 
    	 * @param	none	
    	 * @return 	none 
    	 */ 
     
    	public BasicWindow(){
    		//sets title to Jeopardy
    		super("Jeopardy!");
    		this.setVisible(true);
    		this.setSize(width, height);
    		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
     
    		//Creates Score tally
    		//Label lScore = new Label("Score", 800, 0, 200, 400, this);
    		//TextField tScore = addTextField("0", 850, 175, 100, 50, this);
    		//Creates Question Buttons
    		Container contentPane = getContentPane();
    		JButton bYoureinthis = new JButton("You're in this foreign \n country if...");
    		bYoureinthis.setLocation(0, 0); //0,0, 200, 200, this);
    		bYoureinthis.setSize(200, 200);
    		contentPane.add(bYoureinthis);
    		[exception]bYoureinthis.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				bYoureinthis();
    			}
    		});
    [/exception]
     
    		JButton bThesecretlives = new JButton("The secret lives of teachers");
    		bThesecretlives.setLocation(200, 0);
    		bThesecretlives.setSize(200, 200);
    		contentPane.add(bThesecretlives);
     
    		JButton bThesecretlives2 = new JButton("$200");
    		bThesecretlives2.setLocation(200, 200);
    		bThesecretlives2.setSize(200, 200);
    		contentPane.add(bThesecretlives2);
     
    		JButton bThesecretlives3 = new JButton("$400");
    		bThesecretlives3.setLocation(200, 400);
    		bThesecretlives3.setSize(200, 200);
    		contentPane.add(bThesecretlives3);
     
    		JButton bThesecretlives4 = new JButton("$600");
    		bThesecretlives4.setLocation(200, 600);
    		bThesecretlives4.setSize(200, 200);
    		contentPane.add(bThesecretlives4);
     
    		JButton bYoureinthis2 = new JButton("$200");
    		bYoureinthis2.setLocation(0, 200);
    		bYoureinthis2.setSize(200, 200);
    		contentPane.add(bYoureinthis2);
     
    		JButton bYoureinthis3 = new JButton ("$400");
    		bYoureinthis3.setLocation(0, 400);
    		bYoureinthis3.setSize(200, 200);
    		contentPane.add(bYoureinthis3);
     
    		JButton bYoureinthis4 = new JButton ("$600");
    		bYoureinthis4.setLocation(0, 600);
    		bYoureinthis4.setSize(200, 200);
    		contentPane.add(bYoureinthis4);
     
    		JButton bTransformed = new JButton("Transformed food");
    		bTransformed.setLocation(400,0);
    		bTransformed.setSize(200, 200);
    		contentPane.add(bTransformed);
     
    		JButton bTransformed2 = new JButton("$200");
    		bTransformed2.setLocation(400, 200);
    		bTransformed2.setSize(200, 200);
    		contentPane.add(bTransformed2);
     
    		JButton bTransformed3 = new JButton("$400");
    		bTransformed3.setLocation(400, 400);
    		bTransformed3.setSize(200, 200);
    		contentPane.add(bTransformed3);
     
    		JButton bTransformed4 = new JButton("$600");
    		bTransformed4.setLocation(400, 600);
    		bTransformed4.setSize(200, 200);
    		contentPane.add(bTransformed4);
     
    		JButton bScore = new JButton("Click to Display Score");
    		bScore.setLocation(600, 0);
    		bScore.setSize(200, 400);
    		contentPane.add(bScore);
     
    		JButton bRestart = new JButton("Restart");
    		bRestart.setLocation(600, 400);
    		bRestart.setSize(200, 400);
    		contentPane.add(bRestart);
     
     
     
     
    	}
     
     
     
    	public static void main(String[] args) {
     
    		BasicWindow myWorld = new BasicWindow();
    	}
    	public void output(String s){
    		JFrame rw = new JFrame("Are you right or wrong?");
    		rw.setVisible(true);
    		rw.setSize(200, 100);
    		rw.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    		rw.setAlwaysOnTop(true);
    		JButton brw = new JButton(s);
    		rw.getContentPane().add(brw);
    		try
    		{
    			Thread.sleep(1000);
    		}
    		catch(Exception e){};
    		rw.dispose();
    	}
     
    	//Two new text fields
    	[excpetion] public String inputString(String quest){
    		JFrame what = new JFrame("What is your Guess?");
    		what.setVisible(true);
    		what.setSize(400, 200);
    		what.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    		what.setAlwaysOnTop(true);
    		JTextField question = new JTextField(quest);
    		JTextField guess = new JTextField(50);
    		Container x = what.getContentPane();
    		x.setLayout(new FlowLayout());
    		x.add(question);
    		x.add(guess);
    		JButton enter = new JButton("Enter");
    		x.add(enter);
    		enter.addActionListener(new ActionListener(){
    			public void actionPerformed(ActionEvent e){
    				return guess.getText();
    			}
    		});
     
    	}
    [/exception]
    	public void Youreinthis2 ()
    	{
    		String guess = inputString("You're Jogging in Johannesburg");
    		if (guess.equalsIgnoreCase("south africa"))
    		{
    			score = score + 200;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 200;
    			output("Wrong!");
    		}
    		[exception] bYoureinthis2.setEnabled(false); [/exception]
    	}
    	public void Youreinthis3()
    	{
    		String guess = inputString("You're Lounging in Lima");
    		if (guess.equalsIgnoreCase("peru"))
    		{
    			score = score + 400;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 400 ;
    			output("Wrong!");
    		}
    		[exception] bYoureinthis3.setEnabled(false); [/exception]
    	}
    	public void Youreinthis4 ()
    	{
    		String guess = inputString("You're modeling in milan");
    		if (guess.equalsIgnoreCase("italy"))
    		{
    			score = score + 600;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 600;
    			output("Wrong!");
    		}
    		[exception] bYoureinthis4.setEnabled(false); [/excpetion]
    	}
    	public void Thesecretlives2 ()
    	{
    		String guess = inputString("Ms Dibbs knows a lot about Iran-I bet she works for this spy agency in Langley, VA");
    		if (guess.equalsIgnoreCase("CIA"))
    		{
    			score = score + 200;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 200;
    			output("Wrong!");
    		}
    		[excpetion] bThesecretlives2.setEnabled(false); [/exception]
    	}
    	public void Thesecretlives3 ()
    	{
    		String guess = inputString("Everyone knows Mr. Lee made $100Million working for this Bill Gates Co.");
    		if (guess.equalsIgnoreCase("microsoft"))
    		{
    			score = score + 400;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 400;
    			output("Wrong!");
    		}
    		[excpetion] bThesecretlives3.setEnabled(false); [/excpetion]
    	}
    	public void Thesecretlives4 ()
    	{
    		String guess = inputString("Mr. Conklin was a Captain when the US Navy was attacked at this site in 1941");
    		if (guess.equalsIgnoreCase("pearl harbor"))
    		{
    			score = score + 600;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 600;
    			output("Wrong!");
    		}
    		[exception] bThesecretlives4.setEnabled(false); [/exception]
    	}
    	public void Transformed2 ()
    	{
    		String guess = inputString("Dry a grape and it becomes this");
    		if (guess.equalsIgnoreCase(rasin))
    		{
    			score = score + 200;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 200;
    			output("Wrong!");
    		}
    		[exception] bTransformed2.setEnabled(false); [/exception]
    	}
    	public void Transformed3()
    	{
    		String guess = inputString("A prune is this fruit before it becomes shriveled");
    		if (guess.equalsIgnoreCase("plum"))
    		{
    			score = score + 400;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 400;
    			output("Wrong!");
    		}
    		[exception] bTransformed3.setEnabled(false); [/exception]
    	}
    	public void Transformed4 ()
    	{
    		String guess = inputString("A cucumber put in brine becomes this");
    		if (guess.equalsIgnoreCase("pickle"))
    		{
    			score = score + 600;
    			output("Right!");
    		}
    		else
    		{
    			score = score - 600;
    			output("Wrong!");
    		}
    		[exception] bTransformed4.setEnabled(false); [/exception]
    	}
    }]


  2. #2
    Banned
    Join Date
    May 2010
    Location
    North Central Illinois
    Posts
    1,631
    My Mood
    Sleepy
    Thanks
    390
    Thanked 112 Times in 110 Posts

    Default Re: Trying to make Jeopardy Game

    You could use JOptionPane.showMessageDialog(null, "message", "title", JOptionPane.QUESTION_MESSAGE);

    String str =JOptionPane.showMessageDialog(null, "message", "title", JOptionPane.QUESTION_MESSAGE);

    if (str.equalsIgnoreCase(the answer))
    question is correct

    else
    question is incorrect

  3. #3
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Trying to make Jeopardy Game

    Hello wbroman,

    There are lots of errors in your code.

    Can I ask why you have added the [exception][/exception] tags in?

    These are BBCode tags used within the forum. They work like this:

     
    Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
    The method addActionListener(ActionListener) in the type AbstractButton is not applicable for the arguments (new ActionListener(){})
    ActionListener cannot be resolved to a type


    I have updated your code to help you move forward.

    There are still lots of errors though. For a start, your button ActionListeners will not work like this.

    import javax.swing.*;
    import java.awt.*;
     
    public class BasicWindow extends JFrame{
     
        private int width = 800;
        private int height = 800;
        private int score;
        private JButton bYoureinthis2 = new JButton("$200");
        private JButton bYoureinthis3 = new JButton ("$400");
        private JButton bYoureinthis4 = new JButton ("$600");
        private JButton bTransformed = new JButton("Transformed food");
        private JButton bTransformed2 = new JButton("$200");
        private JButton bTransformed3 = new JButton("$400");
        private JButton bTransformed4 = new JButton("$600");
        private JButton bThesecretlives4 = new JButton("$600");
        private JButton bThesecretlives3 = new JButton("$400");
        private JButton bThesecretlives2 = new JButton("$200");
        private JButton bThesecretlives = new JButton("The secret lives of teachers");
     
        /**  
         * Method:  Constructor method.
         * Purpose:     Creates a new object (instance) of this class.  
         *
         * @param   none   
         * @return  none
         */
     
        public BasicWindow(){
            //sets title to Jeopardy
            super("Jeopardy!");
            this.setVisible(true);
            this.setSize(width, height);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
     
            //Creates Score tally
            //Label lScore = new Label("Score", 800, 0, 200, 400, this);
            //TextField tScore = addTextField("0", 850, 175, 100, 50, this);
            //Creates Question Buttons
            Container contentPane = getContentPane();
            JButton bYoureinthis = new JButton("You're in this foreign \n country if...");
            bYoureinthis.setLocation(0, 0); //0,0, 200, 200, this);
            bYoureinthis.setSize(200, 200);
            contentPane.add(bYoureinthis);
     
            bYoureinthis.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    bYoureinthis();
                }
            });
     
            //JButton bThesecretlives = new JButton("The secret lives of teachers");
            bThesecretlives.setLocation(200, 0);
            bThesecretlives.setSize(200, 200);
            contentPane.add(bThesecretlives);
     
            //JButton bThesecretlives2 = new JButton("$200");
            bThesecretlives2.setLocation(200, 200);
            bThesecretlives2.setSize(200, 200);
            contentPane.add(bThesecretlives2);
     
            //JButton bThesecretlives3 = new JButton("$400");
            bThesecretlives3.setLocation(200, 400);
            bThesecretlives3.setSize(200, 200);
            contentPane.add(bThesecretlives3);
     
            //JButton bThesecretlives4 = new JButton("$600");
            bThesecretlives4.setLocation(200, 600);
            bThesecretlives4.setSize(200, 200);
            contentPane.add(bThesecretlives4);
     
            //JButton bYoureinthis2 = new JButton("$200");
            bYoureinthis2.setLocation(0, 200);
            bYoureinthis2.setSize(200, 200);
            contentPane.add(bYoureinthis2);
     
            //JButton bYoureinthis3 = new JButton ("$400");
            bYoureinthis3.setLocation(0, 400);
            bYoureinthis3.setSize(200, 200);
            contentPane.add(bYoureinthis3);
     
            //JButton bYoureinthis4 = new JButton ("$600");
            bYoureinthis4.setLocation(0, 600);
            bYoureinthis4.setSize(200, 200);
            contentPane.add(bYoureinthis4);
     
            //JButton bTransformed = new JButton("Transformed food");
            bTransformed.setLocation(400,0);
            bTransformed.setSize(200, 200);
            contentPane.add(bTransformed);
     
            //JButton bTransformed2 = new JButton("$200");
            bTransformed2.setLocation(400, 200);
            bTransformed2.setSize(200, 200);
            contentPane.add(bTransformed2);
     
            //JButton bTransformed3 = new JButton("$400");
            bTransformed3.setLocation(400, 400);
            bTransformed3.setSize(200, 200);
            contentPane.add(bTransformed3);
     
            //JButton bTransformed4 = new JButton("$600");
            bTransformed4.setLocation(400, 600);
            bTransformed4.setSize(200, 200);
            contentPane.add(bTransformed4);
     
            JButton bScore = new JButton("Click to Display Score");
            bScore.setLocation(600, 0);
            bScore.setSize(200, 400);
            contentPane.add(bScore);
     
            JButton bRestart = new JButton("Restart");
            bRestart.setLocation(600, 400);
            bRestart.setSize(200, 400);
            contentPane.add(bRestart);
        }
     
     
        public static void main(String[] args) {
     
            BasicWindow myWorld = new BasicWindow();
        }
        public void output(String s){
            JFrame rw = new JFrame("Are you right or wrong?");
            rw.setVisible(true);
            rw.setSize(200, 100);
            rw.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            rw.setAlwaysOnTop(true);
            JButton brw = new JButton(s);
            rw.getContentPane().add(brw);
            try
            {
                Thread.sleep(1000);
            }
            catch(Exception e){};
            rw.dispose();
        }
     
        //Two new text fields
        public String inputString(String quest){
            JFrame what = new JFrame("What is your Guess?");
            what.setVisible(true);
            what.setSize(400, 200);
            what.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            what.setAlwaysOnTop(true);
            JTextField question = new JTextField(quest);
            JTextField guess = new JTextField(50);
            Container x = what.getContentPane();
            x.setLayout(new FlowLayout());
            x.add(question);
            x.add(guess);
            JButton enter = new JButton("Enter");
            x.add(enter);
     
            enter.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    return guess.getText();
                }
            });
     
        }
     
        public void Youreinthis2 ()
        {
            String guess = inputString("You're Jogging in Johannesburg");
            if (guess.equalsIgnoreCase("south africa"))
            {
                score = score + 200;
                output("Right!");
            }
            else
            {
                score = score - 200;
                output("Wrong!");
            }
            bYoureinthis2.setEnabled(false);
        }
        public void Youreinthis3()
        {
            String guess = inputString("You're Lounging in Lima");
            if (guess.equalsIgnoreCase("peru"))
            {
                score = score + 400;
                output("Right!");
            }
            else
            {
                score = score - 400 ;
                output("Wrong!");
            }
           bYoureinthis3.setEnabled(false);
        }
        public void Youreinthis4 ()
        {
            String guess = inputString("You're modeling in milan");
            if (guess.equalsIgnoreCase("italy"))
            {
                score = score + 600;
                output("Right!");
            }
            else
            {
                score = score - 600;
                output("Wrong!");
            }
            bYoureinthis4.setEnabled(false);
        }
        public void Thesecretlives2 ()
        {
            String guess = inputString("Ms Dibbs knows a lot about Iran-I bet she works for this spy agency in Langley, VA");
            if (guess.equalsIgnoreCase("CIA"))
            {
                score = score + 200;
                output("Right!");
            }
            else
            {
                score = score - 200;
                output("Wrong!");
            }
            bThesecretlives2.setEnabled(false);
        }
        public void Thesecretlives3 ()
        {
            String guess = inputString("Everyone knows Mr. Lee made $100Million working for this Bill Gates Co.");
            if (guess.equalsIgnoreCase("microsoft"))
            {
                score = score + 400;
                output("Right!");
            }
            else
            {
                score = score - 400;
                output("Wrong!");
            }
            bThesecretlives3.setEnabled(false);
        }
        public void Thesecretlives4 ()
        {
            String guess = inputString("Mr. Conklin was a Captain when the US Navy was attacked at this site in 1941");
            if (guess.equalsIgnoreCase("pearl harbor"))
            {
                score = score + 600;
                output("Right!");
            }
            else
            {
                score = score - 600;
                output("Wrong!");
            }
            bThesecretlives4.setEnabled(false);
        }
        public void Transformed2 ()
        {
            String guess = inputString("Dry a grape and it becomes this");
            if (guess.equalsIgnoreCase("rasin"))
            {
                score = score + 200;
                output("Right!");
            }
            else
            {
                score = score - 200;
                output("Wrong!");
            }
            bTransformed2.setEnabled(false);
        }
        public void Transformed3()
        {
            String guess = inputString("A prune is this fruit before it becomes shriveled");
            if (guess.equalsIgnoreCase("plum"))
            {
                score = score + 400;
                output("Right!");
            }
            else
            {
                score = score - 400;
                output("Wrong!");
            }
           bTransformed3.setEnabled(false);
        }
        public void Transformed4 ()
        {
            String guess = inputString("A cucumber put in brine becomes this");
            if (guess.equalsIgnoreCase("pickle"))
            {
                score = score + 600;
                output("Right!");
            }
            else
            {
                score = score - 600;
                output("Wrong!");
            }
            bTransformed4.setEnabled(false);
        }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  4. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Trying to make Jeopardy Game

    OK I have fixed the ActionListeners issue but this really is the least of your problems!

    It's going to need some more work on your part.

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
     
    public class BasicWindow extends JFrame implements ActionListener {
     
        private int width = 800;
        private int height = 800;
        private int score;
        private JButton bYoureinthis2 = new JButton("$200");
        private JButton bYoureinthis3 = new JButton ("$400");
        private JButton bYoureinthis4 = new JButton ("$600");
        private JButton bTransformed = new JButton("Transformed food");
        private JButton bTransformed2 = new JButton("$200");
        private JButton bTransformed3 = new JButton("$400");
        private JButton bTransformed4 = new JButton("$600");
        private JButton bThesecretlives4 = new JButton("$600");
        private JButton bThesecretlives3 = new JButton("$400");
        private JButton bThesecretlives2 = new JButton("$200");
        private JButton bThesecretlives = new JButton("The secret lives of teachers");
        private JButton bScore = new JButton("Click to Display Score");
        private JButton bRestart = new JButton("Restart");
     
        /**  
         * Method:  Constructor method.
         * Purpose:     Creates a new object (instance) of this class.  
         *
         * @param   none   
         * @return  none
         */
     
        public BasicWindow(){
            //sets title to Jeopardy
            super("Jeopardy!");
            this.setVisible(true);
            this.setSize(width, height);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
     
            //Creates Score tally
            //Label lScore = new Label("Score", 800, 0, 200, 400, this);
            //TextField tScore = addTextField("0", 850, 175, 100, 50, this);
            //Creates Question Buttons
            Container contentPane = getContentPane();
            JButton bYoureinthis = new JButton("You're in this foreign \n country if...");
            bYoureinthis.setLocation(0, 0); //0,0, 200, 200, this);
            bYoureinthis.setSize(200, 200);
            contentPane.add(bYoureinthis);
     
            /*
            bYoureinthis.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    bYoureinthis();
                }
            });
            */
     
            //JButton bThesecretlives = new JButton("The secret lives of teachers");
            bThesecretlives.setLocation(200, 0);
            bThesecretlives.setSize(200, 200);
            bThesecretlives.addActionListener(this);
            contentPane.add(bThesecretlives);
     
     
            //JButton bThesecretlives2 = new JButton("$200");
            bThesecretlives2.setLocation(200, 200);
            bThesecretlives2.setSize(200, 200);
            bThesecretlives2.addActionListener(this);
            contentPane.add(bThesecretlives2);
     
            //JButton bThesecretlives3 = new JButton("$400");
            bThesecretlives3.setLocation(200, 400);
            bThesecretlives3.setSize(200, 200);
            bThesecretlives3.addActionListener(this);
            contentPane.add(bThesecretlives3);
     
            //JButton bThesecretlives4 = new JButton("$600");
            bThesecretlives4.setLocation(200, 600);
            bThesecretlives4.setSize(200, 200);
            bThesecretlives4.addActionListener(this);
            contentPane.add(bThesecretlives4);
     
            //JButton bYoureinthis2 = new JButton("$200");
            bYoureinthis2.setLocation(0, 200);
            bYoureinthis2.setSize(200, 200);
            bYoureinthis2.addActionListener(this);
            contentPane.add(bYoureinthis2);
     
            //JButton bYoureinthis3 = new JButton ("$400");
            bYoureinthis3.setLocation(0, 400);
            bYoureinthis3.setSize(200, 200);
            bYoureinthis3.addActionListener(this);
            contentPane.add(bYoureinthis3);
     
            //JButton bYoureinthis4 = new JButton ("$600");
            bYoureinthis4.setLocation(0, 600);
            bYoureinthis4.setSize(200, 200);
            bYoureinthis4.addActionListener(this);
            contentPane.add(bYoureinthis4);
     
            //JButton bTransformed = new JButton("Transformed food");
            bTransformed.setLocation(400,0);
            bTransformed.setSize(200, 200);
            bTransformed.addActionListener(this);
            contentPane.add(bTransformed);
     
            //JButton bTransformed2 = new JButton("$200");
            bTransformed2.setLocation(400, 200);
            bTransformed2.setSize(200, 200);
            bTransformed2.addActionListener(this);
            contentPane.add(bTransformed2);
     
            //JButton bTransformed3 = new JButton("$400");
            bTransformed3.setLocation(400, 400);
            bTransformed3.setSize(200, 200);
            bTransformed3.addActionListener(this);
            contentPane.add(bTransformed3);
     
            //JButton bTransformed4 = new JButton("$600");
            bTransformed4.setLocation(400, 600);
            bTransformed4.setSize(200, 200);
            bTransformed4.addActionListener(this);
            contentPane.add(bTransformed4);
     
            //JButton bScore = new JButton("Click to Display Score");
            bScore.setLocation(600, 0);
            bScore.setSize(200, 400);
            bScore.addActionListener(this);
            contentPane.add(bScore);
     
            //JButton bRestart = new JButton("Restart");
            bRestart.setLocation(600, 400);
            bRestart.setSize(200, 400);
            bRestart.addActionListener(this);
            contentPane.add(bRestart);
        }
     
        // Button clicked stuff here
        public void actionPerformed(ActionEvent e){
        	if(e.getSource() == bScore){
        		System.out.println("bScore has been clicked!");
        	}
        	else if (e.getSource() == bRestart){
        		System.out.println("bRestart has been clicked!");
        	}
        	else if (e.getSource() == bTransformed4){
        		System.out.println("bTransformed4 has been clicked!");
        	}
        	// etc..
        }
     
     
        public static void main(String[] args) {
     
            BasicWindow myWorld = new BasicWindow();
        }
     
        public void output(String s){
            JFrame rw = new JFrame("Are you right or wrong?");
            rw.setVisible(true);
            rw.setSize(200, 100);
            rw.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            rw.setAlwaysOnTop(true);
            JButton brw = new JButton(s);
            rw.getContentPane().add(brw);
            try
            {
                Thread.sleep(1000);
            }
            catch(Exception e){};
            rw.dispose();
        }
     
        //Two new text fields
     
        /*
        public String inputString(String quest){
            JFrame what = new JFrame("What is your Guess?");
            what.setVisible(true);
            what.setSize(400, 200);
            what.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            what.setAlwaysOnTop(true);
            JTextField question = new JTextField(quest);
            JTextField guess = new JTextField(50);
            Container x = what.getContentPane();
            x.setLayout(new FlowLayout());
            x.add(question);
            x.add(guess);
            JButton enter = new JButton("Enter");
            x.add(enter);
         */
     
            /*
            enter.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent e){
                    return guess.getText();
                }
            });
     
     
        } */
     
        public void Youreinthis2 ()
        {
            String guess = "You're Jogging in Johannesburg";
            if (guess.equalsIgnoreCase("south africa"))
            {
                score = score + 200;
                output("Right!");
            }
            else
            {
                score = score - 200;
                output("Wrong!");
            }
            bYoureinthis2.setEnabled(false);
        }
        public void Youreinthis3()
        {
            String guess = "You're Lounging in Lima";
            if (guess.equalsIgnoreCase("peru"))
            {
                score = score + 400;
                output("Right!");
            }
            else
            {
                score = score - 400 ;
                output("Wrong!");
            }
           bYoureinthis3.setEnabled(false);
        }
        public void Youreinthis4 ()
        {
            String guess = "You're modeling in milan";
            if (guess.equalsIgnoreCase("italy"))
            {
                score = score + 600;
                output("Right!");
            }
            else
            {
                score = score - 600;
                output("Wrong!");
            }
            bYoureinthis4.setEnabled(false);
        }
        public void Thesecretlives2 ()
        {
            String guess = "Ms Dibbs knows a lot about Iran-I bet she works for this spy agency in Langley, VA";
            if (guess.equalsIgnoreCase("CIA"))
            {
                score = score + 200;
                output("Right!");
            }
            else
            {
                score = score - 200;
                output("Wrong!");
            }
            bThesecretlives2.setEnabled(false);
        }
        public void Thesecretlives3 ()
        {
            String guess = "Everyone knows Mr. Lee made $100Million working for this Bill Gates Co.";
            if (guess.equalsIgnoreCase("microsoft"))
            {
                score = score + 400;
                output("Right!");
            }
            else
            {
                score = score - 400;
                output("Wrong!");
            }
            bThesecretlives3.setEnabled(false);
        }
        public void Thesecretlives4 ()
        {
            String guess = "Mr. Conklin was a Captain when the US Navy was attacked at this site in 1941";
            if (guess.equalsIgnoreCase("pearl harbor"))
            {
                score = score + 600;
                output("Right!");
            }
            else
            {
                score = score - 600;
                output("Wrong!");
            }
            bThesecretlives4.setEnabled(false);
        }
        public void Transformed2 ()
        {
            String guess = "Dry a grape and it becomes this";
            if (guess.equalsIgnoreCase("rasin"))
            {
                score = score + 200;
                output("Right!");
            }
            else
            {
                score = score - 200;
                output("Wrong!");
            }
            bTransformed2.setEnabled(false);
        }
        public void Transformed3()
        {
            String guess = "A prune is this fruit before it becomes shriveled";
            if (guess.equalsIgnoreCase("plum"))
            {
                score = score + 400;
                output("Right!");
            }
            else
            {
                score = score - 400;
                output("Wrong!");
            }
           bTransformed3.setEnabled(false);
        }
        public void Transformed4 ()
        {
            String guess = "A cucumber put in brine becomes this";
            if (guess.equalsIgnoreCase("pickle"))
            {
                score = score + 600;
                output("Right!");
            }
            else
            {
                score = score - 600;
                output("Wrong!");
            }
            bTransformed4.setEnabled(false);
        }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. How to make a graph like this
    By sugarhigh in forum AWT / Java Swing
    Replies: 1
    Last Post: August 27th, 2010, 09:05 AM
  2. Trying to make a bot
    By ighor10 in forum Java Theory & Questions
    Replies: 1
    Last Post: June 11th, 2010, 02:07 PM
  3. make forum with EJB??!!
    By element_sole in forum Enterprise JavaBeans
    Replies: 3
    Last Post: February 12th, 2010, 02:18 PM
  4. What programs shall i make?
    By DarrenReeder in forum Java Theory & Questions
    Replies: 1
    Last Post: December 27th, 2009, 08:31 AM
  5. How to make it???
    By Subhasis Banerjee in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: October 29th, 2009, 02:49 PM

Tags for this Thread