Advertisement
TrodelHD

Untitled

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