Witam postanowiłem zrobić mini programik w Javie na zaliczenie semestru. Skopiowałem gotowy program który maluje na ekranie za pomocą myszki.
Zmodyfikowałem go dodając zmianę wielkości rozmiaru "Pędzla" lecz mam problem ze zmianą koloru malowania nie umiem sobie z tym poradzić. Chciałbym zrobić zmianę koloru na buttonach lecz nie wiem jak się od tego zabrać. Dodaje kod całego programu, może ktoś będzie tak uprzejmy i mi pomoże.
Chciałbym dodać że próbowałem zmieniać getGraphics().setColor(Color.red); lecz nie działa.

 
package javaapplication5;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;

public class rysunek extends JApplet implements MouseMotionListener, MouseListener
{
   Button bl= new Button("CZYSC");
   Button b2= new Button("ROZMIAR MALY");
   Button b3= new Button("ROZMIAR SREDNI");
   Button b4= new Button("ROZMIAR DUZY");
  
    int x=0; int y=0; int a=0;
    int q=0;
   public void init()
   {
       
       setSize(482,500);
       setLayout(null);
       bl.setLocation(2,1); // LOKALIZACJA BATONU
       bl.setSize(120,20);
       bl.setBackground(Color.white);
       add(bl);
       bl.addActionListener(new rysunek.B1());
       
       b2.setLocation(122,1); // LOKALIZACJA BATONU
       b2.setSize(120,20);
       b2.setBackground(Color.white);
       add(b2);
       b2.addActionListener(new rysunek.B2());
       
       b3.setLocation(242,1); // LOKALIZACJA BATONU
       b3.setSize(120,20);
       b3.setBackground(Color.white);
       add(b3);
       b3.addActionListener(new rysunek.B3());
       
       b4.setLocation(362,1); // LOKALIZACJA BATONU
       b4.setSize(120,20);
       b4.setBackground(Color.white);
       add(b4);
       b4.addActionListener(new rysunek.B4());
       
      
       
      addMouseMotionListener(this); addMouseListener(this);
    }

   public void mouseMoved (MouseEvent e) {}
   public void mouseDragged(MouseEvent e) {
       if (a==1)
       {
           x=e.getX();
           y=e.getY();
           getGraphics().setColor(Color.red); 
           getGraphics().fillOval(x,y,3,3);
       }
       
       if (a==2)
       {
           x=e.getX();
           y=e.getY();
           getGraphics().setColor(Color.red); 
           getGraphics().fillOval(x,y,5,5);
       }
         
       if (a==3)
       {
           x=e.getX();
           y=e.getY();
           getGraphics().setColor(Color.red); 
           getGraphics().fillOval(x,y,8,8);
       }
    }
    public void mouseClicked (MouseEvent e)
    {
        int button = e.getButton();
        if (button == MouseEvent.BUTTON3) {repaint();}
    }
    public void mouseEntered (MouseEvent e){}
    public void mouseExited (MouseEvent e){}
    public void mousePressed (MouseEvent e)
    {
        int button = e.getButton();
        if (button == MouseEvent.BUTTON1) {a=q;}
    }
    public void mouseReleased(MouseEvent e){}

    public void paint(Graphics g)
    {
        g.setColor(Color.white); g.fillRect(0,0,482,500);
     }
    
    // BUTTONY BUTTONY BUTTONY BUTTONY BUTTONY
    
    class B4 implements ActionListener {
        private int button;

        public B4() {
        }
            
        @Override
        public void actionPerformed(ActionEvent ae) {
        q = 3;
        
        }
    }
    class B3 implements ActionListener {
        private int button;

        public B3() {
        }
            
        @Override
        public void actionPerformed(ActionEvent ae) {
        q = 2;
        
        }
    }
    class B2 implements ActionListener {
        private int button;

        public B2() {
        }
            
        @Override
        public void actionPerformed(ActionEvent ae) {
        q = 1;
        
        }
    }
    class B1 implements ActionListener {

        public B1() {
        }

        @Override
        public void actionPerformed(ActionEvent ae) {
          a=0; repaint();  
            
        }
    }
}