A simple Global Warming Game in Java.

import javax.swing.*;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Main {
public static void main(String[] args){
JFrame Window = new JFrame("Global Warming Game");

JFrame Window_Wrong_Answer = new JFrame("Wrong answer");
JPanel Panel1 = new JPanel();
final JPanel Panel3 = new JPanel();
JButton Button = new JButton ("20 Lbs");
JButton Button2 = new JButton ("20 Ounces");
JButton Button3 = new JButton ("20 Kilograms");
JButton Button4 = new JButton ("20 Tons");
JTextField textField = new JTextField(20);
JPanel Panel2 = new JPanel(new FlowLayout());
JLabel label = new JLabel("Aprox. how much CO2 is produced per mile?");

Panel2.add(label);
Panel1.add(Button);
Panel1.add(Button2);
Panel1.add(Button3);
Panel1.add(Button4);
Window.add(Panel2);
Window.add(Panel1);
Window.setLayout(new FlowLayout());
Window.setSize(400,350);
Window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Window.setVisible(true);

Button.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame Window_Correct = new JFrame("Correct");
Window_Correct.setLayout(new FlowLayout());
Window_Correct.setSize(400,350);
Window_Correct.setVisible(true);
JLabel label2 = new JLabel("You are correct.");
Window_Correct.add(Panel3);
Panel3.add(label2);
}
});

Button2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame Window_Wrong = new JFrame("Wrong Answer");
Window_Wrong.setLayout(new FlowLayout());
Window_Wrong.setSize(400,350);
Window_Wrong.setVisible(true);
JLabel label3 = new JLabel("You are wrong.");
Window_Wrong.add(Panel3);
JPanel Panel4 = new JPanel();
Panel4.add(label3);
}
});

Button3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame Wrong_Answer = new JFrame("Wrong Answer");
Wrong_Answer.setLayout(new FlowLayout());
Wrong_Answer.setSize(400,350);
Wrong_Answer.setVisible(true);
JLabel label4 = new JLabel("You are wrong.");
Wrong_Answer.add(Panel3);
JPanel Panel5 = new JPanel();
Panel5.add(label4);
}
});

Button4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame Wrong_Answer = new JFrame("Wrong Answer");
Wrong_Answer.setLayout(new FlowLayout());
Wrong_Answer.setSize(400,350);
Wrong_Answer.setVisible(true);
JLabel label5 = new JLabel("You are wrong.");
JPanel Panel6 = new JPanel();
Panel6.add(label5);
}
});
}
}
Posted by Unknown On Sunday, May 26, 2013 1 comment

1 comment:

  • RSS
  • Delicious
  • Digg
  • Facebook
  • Twitter
  • Linkedin
  • Youtube

Like us

    as

    Contact Form

    Name

    Email *

    Message *