Advertisement
TrodelHD

Untitled

Mar 17th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1. package Spiel;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Container;
  5. import java.awt.Font;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JColorChooser;
  11. import javax.swing.JFrame;
  12. import javax.swing.JPanel;
  13. import javax.swing.JScrollPane;
  14. import javax.swing.JSlider;
  15. import javax.swing.JTextArea;
  16. import javax.swing.event.ChangeEvent;
  17. import javax.swing.event.ChangeListener;
  18.  
  19. public class MyPanel extends JPanel {
  20.  
  21. public Connection con;
  22.  
  23. public MyPanel() {
  24.  
  25. this.show();
  26. }
  27.  
  28. DrawArea drawArea;
  29. private Color oldColor = Color.BLACK;
  30. private JButton Faben,Löschen,radirgummi;
  31. private static JTextArea log;
  32. private JScrollPane anzeige;
  33. private JSlider Big;
  34. public static JFrame frame;
  35. ActionListener actionListener = new ActionListener() {
  36. public void actionPerformed(ActionEvent e) {
  37. if (e.getSource() == Faben) {
  38. JColorChooser colorChooser = new JColorChooser();
  39. Color c = colorChooser.showDialog(null, "color", oldColor);
  40. drawArea.setColor(c);
  41. oldColor = c;
  42. }else if (e.getSource() == Löschen) {
  43. drawArea.clear();
  44. con.serversendMessage("clear");
  45. }else if (e.getSource() == radirgummi) {
  46. drawArea.setColor(new Color(255, 255, 255));
  47. }
  48. }
  49. };
  50. public void show() {
  51. // create main frame
  52. frame = new JFrame("Malen");
  53. Container content = frame.getContentPane();
  54. //Set buttons Action listener
  55.  
  56. //
  57. addLog(frame);
  58. //Faben Button
  59. Faben = new JButton("Faben");
  60. Faben.setBounds(520, 410, 200, 30);
  61. Faben.addActionListener(actionListener);
  62. frame.add(Faben);
  63. //Löschen
  64. Löschen = new JButton("Reset");
  65. Löschen.setBounds(520, 450, 200, 30);
  66. Löschen.addActionListener(actionListener);
  67. frame.add(Löschen);
  68. //Radirgummi
  69. radirgummi = new JButton("Radirgummi");
  70. radirgummi.setBounds(520, 530, 200, 30);
  71. radirgummi.addActionListener(actionListener);
  72. frame.add(radirgummi);
  73. //Größe einstellbar
  74. Big = new JSlider(JSlider.HORIZONTAL,1, 10, 4);
  75. frame.add(Big);
  76. Big.setMajorTickSpacing(9);
  77. Big.setMinorTickSpacing(1);
  78. Big.setPaintTicks(true);
  79. Big.setPaintLabels(true);
  80. Big.setForeground(new Color(0, 0, 0));
  81. Big.setBounds(520, 490, 200, 35);
  82.  
  83. Big.addChangeListener(new ChangeListener() {
  84.  
  85. @Override
  86. public void stateChanged(ChangeEvent e) {
  87.  
  88. int r = Big.getValue();
  89.  
  90. drawArea.radius = r;
  91. }
  92. });
  93. // create draw area
  94. drawArea = new DrawArea();
  95. drawArea.radius = 4;
  96. // add to content pane
  97. content.add(drawArea);
  98. //Setze Frame größe
  99. frame.setSize(740, 600);
  100. //Setze frame nicht größenverziebar
  101. frame.setResizable(false);
  102. // can close frame
  103. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  104. // show the swing paint result
  105. frame.setVisible(true);
  106.  
  107. // 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">
  108. }
  109. private void addLog(JFrame controls) {
  110. Font font = new Font("Calibri", Font.BOLD, 20);
  111.  
  112. log = new JTextArea();
  113. log.setEditable(false);
  114. log.setFont(font);
  115. log.setForeground(new Color(0, 0, 0));
  116. String Text="Rateversuche:\n";
  117. log.setText(Text);
  118. anzeige = new JScrollPane(log);
  119. anzeige.setBounds(520, 0, 200, 400);
  120. controls.add(anzeige);
  121.  
  122. }
  123. public static void addToLog(String text){
  124. log.setText(log.getText()+text+"\n");
  125. }
  126. public static void rollenswaper(){
  127.  
  128. frame.dispose();
  129. frame=null;
  130.  
  131.  
  132. }
  133.  
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement