Advertisement
TrodelHD

Untitled

Mar 17th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.14 KB | None | 0 0
  1. package Spiel;
  2.  
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JTextField;
  9.  
  10. public class Main {
  11. public static int roundnuber;
  12. private JFrame frame;
  13. private JButton Joingame;
  14. private JButton Hostgame;
  15. private int Portal;
  16. private String Ip;
  17. private int Zahlderrunden;
  18.  
  19.  
  20. public Main() {
  21.  
  22. this.frame = new JFrame("Game");
  23. this.frame.setBounds(0,0,300,300);
  24. initcomps();
  25. initListeners();
  26. this.frame.setVisible(true);
  27. }
  28.  
  29. public void initcomps() {
  30.  
  31. this.frame.setLayout(null);
  32.  
  33. this.Joingame = new JButton("Join Game");
  34. this.frame.getContentPane().add(Joingame);
  35. this.Joingame.setBounds(50, 50, 200, 50);
  36.  
  37.  
  38. this.Hostgame = new JButton("Host Game");
  39. this.frame.getContentPane().add(Hostgame);
  40. this.Hostgame.setBounds(50, 120, 200, 50);
  41. }
  42.  
  43.  
  44.  
  45. public void initListeners() {
  46.  
  47. this.Joingame.addActionListener(new ActionListener() {
  48.  
  49. @Override
  50. public void actionPerformed(ActionEvent e) {
  51. frame.dispose();
  52. newFrame2();
  53.  
  54. }
  55. });
  56.  
  57. this.Hostgame.addActionListener(new ActionListener() {
  58.  
  59. @Override
  60. public void actionPerformed(ActionEvent e) {
  61.  
  62. frame.dispose();
  63. newFrame();
  64.  
  65. }
  66. });
  67.  
  68.  
  69.  
  70. }
  71.  
  72.  
  73. public void newFrame() {
  74.  
  75. JFrame initframe = new JFrame("Setup Server");
  76. initframe.setBounds(0, 0, 300,300);
  77. initframe.setLayout(null);
  78.  
  79. initframe.setLayout(null);
  80.  
  81. JTextField IP = new JTextField();
  82. initframe.getContentPane().add(IP);
  83. IP.setText("Nicht notwendig");
  84. IP.setEditable(false);
  85. IP.setBounds(50, 50, 200, 25);
  86.  
  87. JTextField Port = new JTextField();
  88. initframe.getContentPane().add(Port);
  89. Port.setText("Enter Port");
  90. Port.setBounds(50, 100, 200, 25);
  91.  
  92. JTextField Zahl = new JTextField();
  93. initframe.getContentPane().add(Zahl);
  94. Zahl.setText("Enter Rundezahl");
  95. Zahl.setBounds(50, 150, 200, 25);
  96.  
  97. JButton ok = new JButton("OK");
  98. initframe.getContentPane().add(ok);
  99. ok.setBounds(50, 175, 75, 50);
  100.  
  101. initframe.setVisible(true);
  102.  
  103. ok.addActionListener(new ActionListener() {
  104.  
  105. @Override
  106. public void actionPerformed(ActionEvent e) {
  107.  
  108. Ip = IP.getText();
  109. try {
  110. Portal = Integer.parseInt(Port.getText());
  111. } catch (Exception e2) {
  112. Portal = 3001;
  113. }
  114. try {
  115. Zahlderrunden = Integer.parseInt(Zahl.getText());
  116. } catch (Exception e2) {
  117. Zahlderrunden = 3;
  118. }
  119. initframe.dispose();
  120. new Game(Portal,Zahlderrunden);
  121. }
  122. });
  123.  
  124.  
  125.  
  126.  
  127.  
  128. }
  129. public static GetRandomWord grw;
  130. public void newFrame2() {
  131.  
  132. JFrame initframe = new JFrame("Setup Client");
  133. initframe.setBounds(0, 0, 300,300);
  134. initframe.setLayout(null);
  135.  
  136. initframe.setLayout(null);
  137.  
  138. JTextField IP = new JTextField();
  139. initframe.getContentPane().add(IP);
  140. IP.setText("IP");
  141. IP.setBounds(50, 50, 200, 25);
  142.  
  143. JTextField Port = new JTextField();
  144. initframe.getContentPane().add(Port);
  145. Port.setText("Enter Port");
  146. Port.setBounds(50, 100, 200, 25);
  147.  
  148. JTextField Zahl = new JTextField();
  149. initframe.getContentPane().add(Zahl);
  150. Zahl.setText("Nicht Notwendig");
  151. Zahl.setBounds(50, 150, 200, 25);
  152. Zahl.setEditable(false);
  153.  
  154. JButton ok = new JButton("OK");
  155. initframe.getContentPane().add(ok);
  156. ok.setBounds(50, 175, 75, 50);
  157.  
  158. initframe.setVisible(true);
  159.  
  160. ok.addActionListener(new ActionListener() {
  161.  
  162. @Override
  163. public void actionPerformed(ActionEvent e) {
  164.  
  165. Ip = IP.getText();
  166. try {
  167. Portal = Integer.parseInt(Port.getText());
  168. } catch (Exception e2) {
  169. Portal = 3001;
  170. }
  171.  
  172. Connection con = new Connection();
  173. try {
  174. if(con.clientConnection(Ip, Portal)==true){
  175. initframe.dispose();
  176. }
  177. } catch (Exception e2) {
  178. // TODO: handle exception
  179. }
  180.  
  181. }
  182. });
  183.  
  184.  
  185.  
  186.  
  187.  
  188. }
  189.  
  190.  
  191. public static void main(String[] args) {
  192. new Main();
  193. grw.setWords();
  194. //new Console().openConsole();
  195.  
  196. }
  197.  
  198. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement