Advertisement
Guest User

Untitled

a guest
Sep 20th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. import javax.swing.*;
  2. import java.awt.*;
  3.  
  4. import java.awt.Cursor;
  5.  
  6. import java.awt.event.*;
  7.  
  8. import java.util.*;
  9.  
  10. class Harald extends Thread implements ActionListener
  11. {
  12.  
  13. JFrame harald;
  14. JLabel Spiel;
  15. Cursor c;
  16. JButton butter;
  17. JButton butt;
  18. ActionEvent e;
  19. Windowlauscher amfenster;
  20.  
  21.  
  22.  
  23.  
  24.  
  25. int s = 0;
  26. JFrame ingame;
  27. JLabel Lars;
  28. JButton Boris;
  29. JButton Ben;
  30. JButton Bernd;
  31. JButton Bruno;
  32. JLabel Louis;
  33. Random randA;
  34. Random randB;
  35. Random randC;
  36. Random randD;
  37. ImageIcon icon2 = new ImageIcon("WoodWallpaper.jpg");
  38.  
  39.  
  40.  
  41.  
  42.  
  43. public Harald()
  44. {
  45. harald = new JFrame("Schießbude");
  46. harald.setLayout(null);
  47. harald.setBounds(500, 350,500, 250);
  48.  
  49. Spiel = new JLabel("Hallo, Ich möchte ein Spiel mit dir Spielen. Spielst du mit mir ?") ;
  50. Spiel.setBounds(80, 40, 450, 20);
  51. harald.add(Spiel);
  52.  
  53. amfenster = new Windowlauscher();
  54. harald.addWindowListener(amfenster);
  55.  
  56. butter = new JButton ("JOO");
  57. butter.setBounds(150, 80, 80, 80);
  58. butter.addActionListener(this);
  59. harald.add(butter);
  60.  
  61. butt = new JButton ("NÄH");
  62. butt.setBounds(290, 80, 80, 80);
  63. butt.addActionListener(this);
  64. harald.add(butt);
  65.  
  66. harald.setResizable(false);
  67. harald.setVisible(true);
  68.  
  69. ingame = new JFrame ("Schießbude");
  70. ingame.setLayout(null);
  71. ingame.setBounds(0,0,1280,995);
  72.  
  73. Lars = new JLabel("Score :"+s);
  74. Lars.setFont(new Font("Serif", Font.PLAIN, 30));
  75. Lars.setBackground(new Color(0,255,255));
  76. Lars.setForeground(new Color(255,0,0));
  77. Lars.setBounds(100,60,240,30);
  78. ingame.add(Lars);
  79.  
  80. Louis = new JLabel (icon2);
  81. Louis.setBounds(0,0,1280,995);
  82. ingame.add(Louis);
  83.  
  84. c = new Cursor(Cursor.CROSSHAIR_CURSOR);
  85.  
  86. ImageIcon icon1 = new ImageIcon("Gloockler.jpg");
  87. Boris = new JButton(icon1);
  88. Ben = new JButton(icon1);
  89. Bernd = new JButton(icon1);
  90. Bruno = new JButton(icon1);
  91.  
  92. InitBoris();
  93. InitBen();
  94. InitBernd();
  95. InitBruno();
  96.  
  97. ingame.add(Boris);
  98. ingame.add(Ben);
  99. ingame.add(Bernd);
  100. ingame.add(Bruno);
  101.  
  102. Boris.addActionListener(this);
  103. Ben.addActionListener(this);
  104. Bernd.addActionListener(this);
  105. Bruno.addActionListener(this);
  106.  
  107.  
  108. }
  109. public void InitBoris(){
  110. randA = new Random();
  111.  
  112.  
  113. int x = randA.nextInt(1184);
  114. int y = randA.nextInt(899);
  115.  
  116. Boris.setBounds(x, y, 96, 96);
  117.  
  118.  
  119.  
  120. }
  121. public void InitBen(){
  122. randB = new Random();
  123.  
  124. int xx = randB.nextInt(1184);
  125. int yy = randB.nextInt(899);
  126. Ben.setBounds(xx,yy,96,96);
  127.  
  128. }
  129. public void InitBernd(){
  130. randB = new Random();
  131.  
  132. int xxx = randC.nextInt(1184);
  133. int yyy = randC.nextInt(899);
  134. Bernd.setBounds(xxx,yyy,96,96);
  135.  
  136. }
  137. public void InitBruno(){
  138. randB = new Random();
  139.  
  140. int xxxx = randD.nextInt(1184);
  141. int yyyy = randD.nextInt(899);
  142. Bruno.setBounds(xxxx,yyyy,96,96);
  143.  
  144. }
  145.  
  146.  
  147. public void actionPerformed(ActionEvent e)
  148. {
  149. if(e.getSource()==butter)
  150. {
  151. ingame.setCursor(Cursor.getPredefinedCursor(Cursor.CROSSHAIR_CURSOR));
  152. harald.setVisible(false);
  153. ingame.setResizable(false);
  154. ingame.setVisible(true);
  155.  
  156. }
  157. if(e.getSource()==butt)
  158. {
  159. System.exit(0);
  160. }
  161.  
  162.  
  163.  
  164. if(e.getSource()==Boris)
  165.  
  166. {
  167. s++;
  168. Lars.setText("Score :"+s);
  169. InitBoris();
  170. ingame.add(Boris);
  171. }
  172. if(e.getSource()==Ben)
  173.  
  174. {
  175. s++;
  176. Lars.setText("Score :"+s);
  177. InitBen();
  178. ingame.add(Ben);
  179. }
  180. if(e.getSource()==Bernd)
  181.  
  182. {
  183. s++;
  184. Lars.setText("Score :"+s);
  185. InitBernd();
  186. ingame.add(Bernd);
  187. }
  188. if(e.getSource()==Bruno)
  189.  
  190. {
  191. s++;
  192. Lars.setText("Score :"+s);
  193. InitBruno();
  194. ingame.add(Bruno);
  195. }
  196.  
  197. }
  198.  
  199. public void run()
  200. {
  201. for(int i = 0; i < 10; i++)
  202. {
  203. try
  204. {
  205. sleep(5000);
  206. }
  207. catch(InterruptedException e)
  208. {
  209.  
  210. }
  211.  
  212. }
  213. }
  214.  
  215.  
  216. public static void main(String[] args)
  217. {
  218.  
  219. Harald blub = new Harald();
  220. blub.run();
  221. }
  222.  
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement