Advertisement
TrodelHD

Untitled

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