Guest User

Untitled

a guest
Jun 5th, 2015
353
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1. import javax.swing.JButton;
  2. import javax.swing.JComponent;
  3. import java.awt.Graphics;
  4. import javax.swing.JFrame;
  5. import java.awt.image.*;
  6. import javax.swing.Icon;
  7. import javax.swing.ImageIcon;
  8. import java.awt.event.*;
  9. import java.awt.*;
  10. import javax.swing.*;
  11.  
  12. public class gameLoop extends Thread{
  13. public static boolean gameIsRunning = false;
  14. public static final int FPS = 60;
  15. public static boolean sentinel = false;
  16. public static void main(String[] Args){
  17.  
  18. getResources get = new getResources();
  19. JFrame window = new JFrame("Out from Eden");
  20. window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  21. window.setBounds(30, 30, 516, 424); // it's a 500 x 385 image idk what's up
  22.  
  23.  
  24.  
  25. Icon startButtonImg = new ImageIcon(get.getImg("Start"));
  26. Icon startButtonOverImg = new ImageIcon(get.getImg("StartOver"));
  27. Icon stopButtonImg = new ImageIcon(get.getImg("Stop"));
  28. Icon stopButtonOverImg = new ImageIcon(get.getImg("StopOver"));
  29.  
  30. JButton startButton = new JButton(startButtonImg);
  31. startButton.setRolloverIcon(startButtonOverImg);
  32. JButton stopButton = new JButton(stopButtonImg);
  33. stopButton.setRolloverIcon(stopButtonOverImg);
  34.  
  35. window.add(startButton);
  36. startButton = setButtonSize(startButton,140,115,300,50);
  37. window.add(stopButton);
  38. stopButton = setButtonSize(stopButton,121,133,300,200);
  39.  
  40. startButton.addActionListener(new ActionListener(){
  41.  
  42. public void actionPerformed(ActionEvent e) {
  43. window.dispose();
  44. gameStart();
  45. }
  46.  
  47. });
  48. stopButton.addActionListener(new Stop());
  49.  
  50.  
  51. window.getContentPane().add(new MyCanvas());
  52. window.setVisible(true);
  53.  
  54.  
  55. }
  56.  
  57. public static JButton setButtonSize(JButton button,
  58. int w, int h, int x, int y){
  59. button.setSize(w,h);
  60. button.setLocation(x,y);
  61. button.setBorderPainted(false);
  62. button.setFocusPainted(false);
  63. button.setBorder(BorderFactory.createEmptyBorder());
  64. button.setContentAreaFilled(false);
  65. return button;
  66. }
  67.  
  68. static class Stop implements ActionListener{
  69. public void actionPerformed (ActionEvent e){
  70. System.exit(0);
  71. }
  72. }
  73.  
  74. public void run(){
  75. if (gameIsRunning == true){
  76. System.out.println("This should start the game");
  77. }
  78. }
  79.  
  80. public static void gameStart(){
  81. gameIsRunning = true;
  82. (new Thread(new gameLoop())).start();
  83. }
  84.  
  85.  
  86.  
  87.  
  88. }
  89. class MyCanvas extends JComponent{
  90.  
  91. public void paint(Graphics g){
  92. getResources get = new getResources();
  93.  
  94. BufferedImage titleImg = get.getImg("Title");
  95. BufferedImage testImg = get.getImage("");
  96. g.drawImage(titleImg, 0, 0, null);
  97. g.drawImage(testImg, 0 , 0, null);
  98. }
  99.  
  100. }
Advertisement
Add Comment
Please, Sign In to add comment