Advertisement
Guest User

Untitled

a guest
Jan 18th, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.27 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package ono_i_myszka;
  7.  
  8. import java.awt.Color;
  9. import java.awt.*;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseListener;
  14. import javax.swing.*;
  15.  
  16. public class Ono_i_myszka {
  17.  
  18.  
  19. public static void main(String[] args) {
  20. Okno okno = new Okno();
  21. okno.setSize(500, 600);
  22. }
  23.  
  24. }
  25.  
  26. class Okno extends JFrame implements ActionListener{
  27. JPanel ustawienia;
  28. PanelRysowanie rysowanie;
  29.  
  30. ButtonGroup group;
  31. JRadioButton aRadioButton;
  32. JRadioButton bRadioButton;
  33.  
  34. Okno()
  35. {
  36. super("Rysowanie");
  37. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  38. setVisible(true);
  39. setLayout(null);
  40.  
  41.  
  42.  
  43.  
  44.  
  45. ustawienia = new JPanel();
  46. ustawienia.setBackground(Color.YELLOW);
  47. ustawienia.setSize(500, 150);
  48. ustawienia.setLocation(0, 0);
  49. add(ustawienia);
  50.  
  51. group = new ButtonGroup();
  52. aRadioButton = new JRadioButton("Czerwony");
  53. aRadioButton.setBackground(Color.YELLOW);
  54. //aRadioButton.setLocation(20, 20);
  55. group.add(aRadioButton);
  56. ustawienia.add(aRadioButton);
  57.  
  58. bRadioButton = new JRadioButton("Czarny");
  59. group.add(bRadioButton);
  60. ustawienia.add(bRadioButton);
  61. bRadioButton.setBackground(Color.YELLOW);
  62.  
  63.  
  64. rysowanie = new PanelRysowanie();
  65. rysowanie.setSize(490, 400);
  66. rysowanie.setLocation(0, 200);
  67. rysowanie.setBackground(Color.LIGHT_GRAY);
  68. add(rysowanie);
  69.  
  70.  
  71. }
  72.  
  73. @Override
  74. public void actionPerformed(ActionEvent e) {
  75. Objec
  76. }
  77. }
  78.  
  79. class PanelRysowanie extends JPanel implements MouseListener
  80. {
  81. Point poczatek, koniec;
  82. Color kolor;
  83.  
  84. void setColor(Color n)
  85. {
  86. kolor=n;
  87. }
  88. PanelRysowanie()
  89. {
  90. kolor = Color.WHITE;
  91. poczatek=new Point(-1, -1);
  92. koniec =new Point(-1, -1);
  93. //setVisible(true);
  94. //this.setBackground(Color.BLUE);
  95. addMouseListener(this);
  96. }
  97. @Override
  98. public void paintComponent(Graphics g)
  99. {
  100. super.paintComponent(g);
  101. g.setColor(kolor);
  102. g.drawLine(poczatek.x, poczatek.y, koniec.x, koniec.y );
  103. }
  104.  
  105. @Override
  106. public void mouseClicked(MouseEvent e) {
  107. System.out.println("mouseClicked");
  108. }
  109.  
  110. @Override
  111. public void mousePressed(MouseEvent e) {
  112. System.out.println("mousePressed");
  113. this.poczatek.x=e.getX();
  114. this.poczatek.y=e.getY();
  115. }
  116.  
  117. @Override
  118. public void mouseReleased(MouseEvent e) {
  119. System.out.println("mouseReleased");
  120. this.koniec.x=e.getX();
  121. this.koniec.y=e.getY();
  122. repaint();
  123. }
  124.  
  125. @Override
  126. public void mouseEntered(MouseEvent e) {
  127. System.out.println("mouseEntered");
  128. }
  129.  
  130. @Override
  131. public void mouseExited(MouseEvent e) {
  132. System.out.println("mouseExited");
  133. }
  134. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement