So basically, my aim it to create a program like the MS Paint software, where I can draw shapes with mouse dragging and change its colors. This is a very long script of mine
It is hard to evaluate the correctness of your code without seeing the main method. Your 'main' class is set up in such a way that it appears the method mousePressed() is intended to poll the buttons and set the drawing mode based on their state.
It is impossible for me to know if you are polling the buttons correctly, however, without viewing the main method.
If you are looking to use an Object-Oriented approach, you are going to want to use the Observer pattern. In essence, your buttons will all have a reference to the 'main' object which has a buttonClicked(Button btn) method. When a button is clicked, it runs the 'main' object's buttonClicked(Button btn) method. The argument provided will be a reference to the button that is clicked so that the main can choose the appropriate mode to use. Demo code follows:
In Main class:
//Give the button a reference to the main object
button1 = new button(this);
//receive notifications from the button
public buttonClicked(Button btn) {
if(btn.equals(button1))
mode = 1;
if(...)
...
}