/* * HelloWorldSwing.java is a 1.4 example that * requires no other files. */ import javax.swing.*; public class Main { public int age=0; public int intel=1; public int weight=1; public int height=1; public int hunger=0; public int energy=10; public void sleep(){ Main.say("Good Night, see you tomarrow."); age++; height++; hunger++; energy=10; } public void eat(String food){ Main.say("Mmmm. That was Good!"); energy--; if(food == "candy"){ weight++; energy=energy+3; if(hunger <= 3){ hunger=0; } else { hunger = hunger-3; } } else if(food == "milk"){ height++; energy++; if(hunger <= 3){ hunger=0; } else { hunger = hunger-3; } } } public void read(){ if(hunger >=10){ Main.say("I am to hungery to do that"); } else if (energy < 1) { Main.say("I am to tired to do that"); } else { energy--; Main.say("Hehe, I liked that story"); intel++; hunger++; } } public void play(){ if(hunger >=10){ Main.say("I am to hungery to do that"); } else if (energy < 3) { Main.say("I am to tired to do that"); } else { energy = energy-3; Main.say("Hehe, that was fun!"); if(weight >=2){ weight--; } hunger=hunger+3; } } /** * Create the GUI and show it. For thread safety, * this method should be invoked from the * event-dispatching thread. */ public void say(String pettalk) { JFrame.setDefaultLookAndFeelDecorated(true); } public void createAndShowGUI() { //Make sure we have nice window decorations. JFrame.setDefaultLookAndFeelDecorated(true); //Create and set up the window. JFrame frame = new JFrame("Pet Game"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //Add the ubiquitous "Hello World" label. JLabel stats = new JLabel("Status:"); JLabel age = new JLabel("Age: " + Pet.age); JLabel energy = new JLabel("energy: " + Pet.energy); JLabel weight = new JLabel("weight: " + Pet.weight); JLabel height = new JLabel("height: " + Pet.height); JLabel hunger = new JLabel("hunger:" + Pet.hunger); frame.getContentPane().add(stats); frame.getContentPane().add(age); frame.getContentPane().add(energy); frame.getContentPane().add(weight); frame.getContentPane().add(height); frame.getContentPane().add(hunger); //Display the window. frame.pack(); frame.setVisible(true); } public void main(String[] args) { //Schedule a job for the event-dispatching thread: //creating and showing this application's GUI. javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } }