Advertisement
TrodelHD

Untitled

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