Advertisement
TrodelHD

Untitled

Mar 11th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.41 KB | None | 0 0
  1. package Spiel;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Font;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.util.Timer;
  8. import java.util.TimerTask;
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JOptionPane;
  12. import javax.swing.JTextArea;
  13. import javax.swing.JTextField;
  14.  
  15. public class Round {
  16.  
  17.  
  18.  
  19. public Main m;
  20. private JFrame frame;
  21. private static String Wort;
  22. private JTextArea Time;
  23. private Color c = new Color(0, 0, 0);
  24. private boolean aktiv = true;
  25. private int sek = 180;
  26. private Game g;
  27. private JButton ok;
  28. private JTextField Tip;
  29. private JTextArea LOG;
  30.  
  31. Timer timer = new Timer();
  32.  
  33. public Round (String Wort, Game g) {
  34.  
  35. this.frame = new JFrame("Game");
  36. this.frame.setBounds(0,0,800,600);
  37. this.g = g;
  38. this.frame.setVisible(true);
  39. this.Wort = Wort;
  40. JOptionPane.showMessageDialog(frame, "Sie raten Nun");
  41. setRaterFrame();
  42. initraterlistener();
  43. //send client das er maler ist
  44. startZeit();
  45.  
  46.  
  47.  
  48.  
  49.  
  50.  
  51. }
  52.  
  53. private void initraterlistener() {
  54.  
  55. this.ok.addActionListener(new ActionListener() {
  56.  
  57. @Override
  58. public void actionPerformed(ActionEvent e) {
  59.  
  60. String Geraten = Tip.getText();
  61.  
  62. if(Geraten.equalsIgnoreCase(Wort)) {
  63. JOptionPane.showMessageDialog(frame, "Richtig! Das Wort war " + Wort + ".");
  64. timer.cancel();
  65. frame.getContentPane().removeAll();
  66. frame.setVisible(false);
  67. if(m.roundnuber>0){
  68. m.roundnuber--;
  69. new Round();
  70. }else{
  71. frame.dispose();
  72. Main main = new Main();
  73. }
  74. }else {
  75.  
  76. LOG.setText(LOG.getText() + "\n" + Geraten + "\n Leider Falsch");
  77.  
  78. }
  79.  
  80.  
  81.  
  82. }
  83. });
  84.  
  85.  
  86. }
  87.  
  88. public Round () {
  89.  
  90. this.frame = new JFrame("Game");
  91. this.frame.setBounds(0,0,800,600);
  92. this.frame.setContentPane(new MyPanel());
  93. JOptionPane.showMessageDialog(frame, "Sie malen Nun");
  94. this.frame.dispose();
  95. //senden das client rater ist
  96.  
  97.  
  98. }
  99.  
  100.  
  101.  
  102. public void startZeit() {
  103.  
  104.  
  105.  
  106. TimerTask task = new TimerTask() {
  107.  
  108. @Override
  109. public void run() {
  110.  
  111.  
  112.  
  113. if(aktiv==true){
  114.  
  115. if(sek==0){
  116. timer.cancel();
  117. JOptionPane.showMessageDialog(frame, "Zeit Abgelaufen");
  118. frame.getContentPane().removeAll();
  119. frame.setVisible(false);
  120. new Round();
  121. }
  122.  
  123. String anzeige = Integer.toString(sek);
  124. Time.setText(anzeige);
  125.  
  126. sek--;
  127. }else{
  128.  
  129. }
  130. }
  131. };
  132. timer.schedule(task, 0, 1000);
  133.  
  134.  
  135. }
  136.  
  137.  
  138.  
  139. public void setRaterFrame() {
  140.  
  141. this.frame.setLayout(null);
  142.  
  143. this.LOG = new JTextArea();
  144. this.frame.getContentPane().add(LOG);
  145. LOG.setEditable(false);
  146. Font f = new Font("Arial", Font.BOLD, 20);
  147. LOG.setFont(f);
  148. LOG.setForeground(c);
  149. LOG.setBounds(500, 0, 300, 500);
  150. LOG.setText("Test");
  151.  
  152. this.Tip = new JTextField();
  153. frame.getContentPane().add(Tip);
  154. this.Tip.setBounds(500, 500, 200, 25);
  155. this.Tip.setText("test");
  156.  
  157.  
  158. this.ok = new JButton("OK");
  159. frame.getContentPane().add(ok);
  160. this.ok.setBounds(700,500 , 75, 50);
  161.  
  162. this.Time = new JTextArea();
  163. this.frame.getContentPane().add(Time);
  164. Time.setEditable(false);
  165. Font fo = new Font("Arial", Font.BOLD, 30);
  166. Time.setFont(fo);
  167. Time.setForeground(c);
  168. Time.setBounds(0, 0, 50, 50);
  169. Time.setText("180");
  170.  
  171.  
  172. }
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement