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);
}
}