Advertisement
Guest User

Virtual Pet GUI Main Class

a guest
Oct 30th, 2014
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.26 KB | None | 0 0
  1. /**Virtual Pet GUI
  2. * T.J. Durkin
  3. * 1st Period
  4. */
  5. import java.awt.*;
  6. import BreezySwing.*;
  7. import javax.swing.*;
  8. class VirtualPetGUI extends GBFrame{
  9. Mouse Mickey=new Mouse("Mouse",2,2,2,2,2); //initialize mouse
  10. JTextField Stats=addTextField("",1,1,4,4);//stats text field
  11. JButton Read=addButton("Read your mouse a book",5,1,1,1);//add intelligence
  12. JButton Wheel=addButton("Put your mouse on mouse wheel(increases stamina but uses energy)",5,2,1,1);//add stamina take energy
  13. JButton Feed=addButton("Feed your mouse straw(increases health and energy)",5,3,1,1);//add health and energy
  14. JButton Play=addButton("Play with your mouse(increases strength and stamina but uses energy)",5,4,1,1);//add strength take stamina
  15. JButton Workout=addButton("Work out your mouse(increases strength but uses energy)",5,5,1,1);//add strength take energy
  16. boolean actionperformed=false;//create actionperformed boolean
  17. JLabel label=addLabel("",1,1,3,3);//label for pictures
  18. JLabel mouse=addLabel("",1,5,3,3);//add a label for the picture of your cat
  19. ImageIcon book=new ImageIcon("Book.jpg");//bookimage
  20. ImageIcon wheel=new ImageIcon("wheel.jpg");//wheel image
  21. ImageIcon weights=new ImageIcon("weights.jpg");//weights image
  22. ImageIcon playing=new ImageIcon("playing.jpg");//playing image
  23. ImageIcon Mouse=new ImageIcon("Mouse.png");//mouse image
  24. ImageIcon Straw=new ImageIcon("Straw.png");//straw image
  25. ImageIcon deadmouse=new ImageIcon("deadmouse.jpg");//deadmouse image
  26. JMenuItem author=addMenuItem("File","Author");//author menu item
  27. JMenuItem instructions=addMenuItem("File","Instructions");//instrucitions menu item
  28. public VirtualPetGUI(){
  29. Stats.setText(Mickey.toString()); //sets stats text feild to read the stats of the mouse
  30. mouse.setIcon(Mouse);
  31. }
  32. public void buttonClicked(JButton button){
  33. if(button==Read&&actionperformed==false){//add intelligence
  34. Mickey.setIntelligence(Mickey.getIntelligence()+2);//increases intelligence of mouse
  35. actionperformed=true;//set actionperformed to true
  36. label.setIcon(book);//set icon to book
  37. Stats.setText(Mickey.toString()+"");//return stats
  38. }
  39. if(button==Wheel&&actionperformed==false){//add stamina take energy
  40. Mickey.setStamina(Mickey.getStamina()+3);//increases the stamina of the mouse
  41. Mickey.setEnergy(Mickey.getEnergy()-5);//decreases the energy of the mouse
  42. actionperformed=true;//set actionperformed to true
  43. label.setIcon(wheel);//set icon to wheel
  44. Stats.setText(Mickey.toString()+"");//return stats
  45. }
  46. if(button==Feed&&actionperformed==false){//add health take energy
  47. Mickey.setHealth(Mickey.getHealth()+5);//increases the health of the mouse
  48. Mickey.setEnergy(Mickey.getEnergy()+5);//increases the energy of the mouse
  49. actionperformed=true;//set actionperformed to true
  50. label.setIcon(Straw);//set icon to straw
  51. Stats.setText(Mickey.toString()+"");//return stats
  52. }
  53. if(button==Play&&actionperformed==false){//add strength and stamina take energy
  54. mouse.setStrength(mouse.getStrength()+1);//increases the strength of the mouse
  55. mouse.setStamina(mouse.getStamina()+1);//increases the stamina of the mouse
  56. mouse.setEnergy(mouse.getEnergy()-5);//decreases the energy of the mouse
  57. actionperformed=true;//set actionperformed to true
  58. label.setIcon(playing);//set icon to playing
  59. Stats.setText(Mickey.toString()+"");//return stats
  60. }
  61. if(button==Workout&&actionperformed==false){//add strength take energy
  62. mouse.setHealth(mouse.getStrength()+3);//increases the strength of the mouse
  63. mouse.setEnergy(mouse.getEnergy()-5);//decreases the energy of the mouse
  64. actionperformed=true;//set actionperformed to true
  65. label.setIcon(weights);//set icon to weights
  66. Stats.setText(Mickey.toString()+"");//return stats
  67. }
  68. }
  69. public void menuItemSelected(JMenuItem menuItem){
  70. if(menuItem==author){
  71. messageBox("By:T.J. Durkin");
  72. }
  73. if(menuItem==instructions){
  74. messageBox("Click one of the buttons to change the conditons of your mouse. Take into consideration the positve\n and negative effects of your choices. The goal is to not kill your mouse.");
  75. }
  76. }
  77. public static void main( String[] args ){
  78. VirtualPetGUI intro=new VirtualPetGUI();//create the frame
  79. intro.setTitle("Mouse");
  80. intro.setSize(1500,900);
  81. intro.setVisible(true);
  82. }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement