Advertisement
TrodelHD

Untitled

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