I have a class named Foo that extends a class named Bar that extends JPanel and implements ActionListener. When I select Circle and click the draw button, I draw a circle, and w
Suggestions:
super.paintComponent(g)
as it has a necessary important role to play.paintComponent(...)
method override.As an aside, don't compare Strings using ==
. Use the equals(...)
or the equalsIgnoreCase(...)
method instead. Understand that == checks if the two objects are the same which is not what you're interested in. The methods on the other hand check if the two Strings have the same characters in the same order, and that's what matters here. So instead of
if (fu == "bar") {
// do something
}
do,
if ("bar".equals(fu)) {
// do something
}
or,
if ("bar".equalsIgnoreCase(fu)) {
// do something
}