I'm trying to create a tool similar to Visual Paradigm. This is what I did so far
For the next step, I want a circle to be drawn on the white plain panel when the "Host" button is clicked. However, it's not working.
This method is for the Host button action:
private void hostButtonActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("Host button clicked.");
final JPanel center = new JPanel();
center.setLayout(null);
JPanel drawingPanel = new CircleDraw();
drawingPanel.setLocation(100,100);
drawingPanel.setSize(100,100);
center.add(drawingPanel);
center.repaint();
}
and this is the CircleDraw Class
import java.awt.*;
import java.awt.geom.*;
import javax.swing.JPanel;
public class CircleDraw extends JPanel {
Ellipse2D.Double circle;
public CircleDraw() {
circle = new Ellipse2D.Double(100, 100, 100, 100);
setOpaque(false);
System.out.println("I'm inside CIRCLEDRAW constructor");
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D ga = (Graphics2D) g;
// ga.draw(circle);
ga.setPaint(Color.green);
ga.fill(circle);
ga.setPaint(Color.red);
System.out.println("I'm inside method PAINT");
}
}
However, it never prints "I'm inside method PAINT". I tried following the steps provided here, but I still can't get it to work. Any help would be appreciated.