I prescribe a checkbox class. And in the main class, which sets a large frame, on which everything is fixed, this area is Listener. And so, he catches pressing the button in that area, everything goes as it should, I debug, a drawline is drawn on it and it is visible (see the image below). But when you click on this area again, it should disappear due to the execution of the method below, which simply recreates the object of the checkbox class. But after doing

public void FirstToDeactive(){ this.remove(first); first = new oneCheckBox(); first.setBounds(20,32, 481, 481); add(first); first.repaint(); } 

There is a drawing of the entire frame in place of a small checkbox: enter image description here

    1 answer 1

    The whole problem, as it turned out, is that I draw a cross on it not inside the class itself, but from the Main frame. Fixing this, following the basic principles of OOP, everything worked