Advertisement
TrodelHD

Untitled

Mar 17th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. package Spiel;
  2.  
  3. import java.awt.BasicStroke;
  4. import java.awt.Color;
  5. import java.awt.Container;
  6. import java.awt.Font;
  7. import java.awt.event.ActionEvent;
  8. import java.awt.event.ActionListener;
  9.  
  10. import javax.swing.JButton;
  11. import javax.swing.JColorChooser;
  12. import javax.swing.JFrame;
  13. import javax.swing.JOptionPane;
  14. import javax.swing.JPanel;
  15. import javax.swing.JScrollPane;
  16. import javax.swing.JSlider;
  17. import javax.swing.JTextArea;
  18. import javax.swing.JTextField;
  19. import javax.swing.event.ChangeEvent;
  20. import javax.swing.event.ChangeListener;
  21.  
  22. public class MyPanelRater extends JPanel {
  23.  
  24. public Main m;
  25. public Connection con;
  26.  
  27. public MyPanelRater() {
  28.  
  29. this.show();
  30. }
  31. public GetRandomWord randomword;
  32. private static DrawAreaRater drawArea;
  33. private Color oldColor = Color.BLACK;
  34. private JButton send;
  35. private JTextArea log;
  36. private JScrollPane anzeige;
  37. private JTextField eingabe;
  38. private static String word;
  39. public static JFrame frame;
  40. public void show() {
  41. // create main frame
  42. frame = new JFrame("Raten");
  43. Container content = frame.getContentPane();
  44. //Set buttons Action listener
  45. ActionListener actionListener = new ActionListener() {
  46. public void actionPerformed(ActionEvent e) {
  47. if (e.getSource() == send) {
  48. addToLog(eingabe.getText().replaceAll(" ", "_"));
  49. con.serversendMessage("ratewort "+eingabe.getText().replaceAll(" ", "_"));
  50. if(eingabe.getText().equalsIgnoreCase(word)){
  51. JOptionPane.showMessageDialog(frame, "Das Wort war richtig!");
  52. rollenswaper();
  53. con.serversendMessage("rollenswaper");
  54. String random = randomword.getRandomWord();
  55. JOptionPane.showMessageDialog(frame, "Bitte male "+random);
  56. con.serversendMessage("start rate "+random);
  57. }
  58. }
  59. }
  60. };
  61. //
  62. JPanel controls = new JPanel();
  63. addLog(frame);
  64. //Rate feld
  65. eingabe = new JTextField();
  66. frame.add(eingabe);
  67. eingabe.setText("Das wort hier Raten");
  68. eingabe.setBounds(520, 410, 200, 30);
  69. //send Button
  70. send = new JButton("send");
  71. send.setBounds(520, 450, 200, 30);
  72. send.addActionListener(actionListener);
  73. frame.add(send);
  74. // create draw area
  75. drawArea = new DrawAreaRater();
  76. drawArea.radius = 4;
  77. // add to content pane
  78. content.add(drawArea);
  79. //Setze Frame größe
  80. frame.setSize(740, 600);
  81. //Setze frame nicht größenverziebar
  82. frame.setResizable(false);
  83. // can close frame
  84. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  85. // show the swing paint result
  86. frame.setVisible(true);
  87.  
  88. // Now you can try our Swing Paint !!! Enjoy <img draggable="false" class="emoji" alt="😀" src="https://s.w.org/images/core/emoji/2.3/svg/1f600.svg">
  89. }
  90. private void addLog(JFrame controls) {
  91. Font font = new Font("Calibri", Font.BOLD, 20);
  92.  
  93. log = new JTextArea();
  94. log.setEditable(false);
  95. log.setFont(font);
  96. log.setForeground(new Color(0, 0, 0));
  97. String Text="Rateverlauf:\n";
  98. log.setText(Text);
  99. anzeige = new JScrollPane(log);
  100. anzeige.setBounds(520, 0, 200, 400);
  101. controls.add(anzeige);
  102.  
  103. }
  104. public void setword(String word){
  105. this.word = word;
  106. }
  107. public static void drawLine(int radius, int oldX, int oldY, int currentX, int currentY,int r ,int g, int b){
  108. drawArea.drawLine(radius, oldX, oldY, currentX, currentY, r, g, b);
  109. }
  110. public static void clear(){
  111. drawArea.clear();
  112. }
  113. private void addToLog(String text){
  114. log.setText(log.getText()+text+"\n");
  115. }
  116. public static void rollenswaper(){
  117.  
  118. frame.dispose();
  119. MyPanel MyP = new MyPanel();
  120.  
  121.  
  122. }
  123.  
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement