Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ono_i_myszka;
- import java.awt.Color;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.MouseEvent;
- import java.awt.event.MouseListener;
- import javax.swing.*;
- public class Ono_i_myszka {
- public static void main(String[] args) {
- Okno okno = new Okno();
- okno.setSize(500, 600);
- }
- }
- class Okno extends JFrame implements ActionListener{
- JPanel ustawienia;
- PanelRysowanie rysowanie;
- ButtonGroup group;
- JRadioButton aRadioButton;
- JRadioButton bRadioButton;
- Okno()
- {
- super("Rysowanie");
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setVisible(true);
- setLayout(null);
- ustawienia = new JPanel();
- ustawienia.setBackground(Color.YELLOW);
- ustawienia.setSize(500, 150);
- ustawienia.setLocation(0, 0);
- add(ustawienia);
- group = new ButtonGroup();
- aRadioButton = new JRadioButton("Czerwony");
- aRadioButton.setBackground(Color.YELLOW);
- //aRadioButton.setLocation(20, 20);
- group.add(aRadioButton);
- ustawienia.add(aRadioButton);
- bRadioButton = new JRadioButton("Czarny");
- group.add(bRadioButton);
- ustawienia.add(bRadioButton);
- bRadioButton.setBackground(Color.YELLOW);
- rysowanie = new PanelRysowanie();
- rysowanie.setSize(490, 400);
- rysowanie.setLocation(0, 200);
- rysowanie.setBackground(Color.LIGHT_GRAY);
- add(rysowanie);
- }
- @Override
- public void actionPerformed(ActionEvent e) {
- Objec
- }
- }
- class PanelRysowanie extends JPanel implements MouseListener
- {
- Point poczatek, koniec;
- Color kolor;
- void setColor(Color n)
- {
- kolor=n;
- }
- PanelRysowanie()
- {
- kolor = Color.WHITE;
- poczatek=new Point(-1, -1);
- koniec =new Point(-1, -1);
- //setVisible(true);
- //this.setBackground(Color.BLUE);
- addMouseListener(this);
- }
- @Override
- public void paintComponent(Graphics g)
- {
- super.paintComponent(g);
- g.setColor(kolor);
- g.drawLine(poczatek.x, poczatek.y, koniec.x, koniec.y );
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- System.out.println("mouseClicked");
- }
- @Override
- public void mousePressed(MouseEvent e) {
- System.out.println("mousePressed");
- this.poczatek.x=e.getX();
- this.poczatek.y=e.getY();
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- System.out.println("mouseReleased");
- this.koniec.x=e.getX();
- this.koniec.y=e.getY();
- repaint();
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- System.out.println("mouseEntered");
- }
- @Override
- public void mouseExited(MouseEvent e) {
- System.out.println("mouseExited");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement