4
Greetings dear fellow programmers.
I’m encountering a somewhat irritating error: I consider drawing a graph on the screen using circular/oval shapes. After a good number of researches, I was suggested to use a class that extends Jpanel/Jcomponent (tested with both), and used a painting method using Graphics, which was called by paintComponent.
I did it in many ways, and at the end of the day, the same thing persists: Little squares painted white.
It’s being drawn this way today. I would like the panels to become circles.
This is the code I use to do such a thing. I have described in the comments for easy viewing.
Here’s the class I created based on the 300 examples of drawOval in java.
public class Bolinha extends JPanel{
public void pintar(Graphics g){
g.setColor(Color.white);
g.fillOval(50, 50, 20, 20);
}
@Override
protected void paintComponent(Graphics g) {
pintar(g);
super.paintComponent(g);
}
Unfortunately I can not post more images, but using this code:
for (int i = 0; i < g.getListaDeVertices().size(); i++){
v1 = g.getListaDeVertices().get(i); //Pega o vértice
Bolinha bola = new Bolinha();
bola.setSize(30, 30);
bola.setLocation(v1.getPosX(), v1.getPosY() + 180);
bola.setVisible(true);
bola.setBackground(Color.white);
bola.add(new Label(Integer.toString(g.getListaDeVertices().get(i).getIdMatriz())));
PainelDesenho.add(bola);
listaDePaineis.add(p);
I end up getting the same result (squares) instead of polka dots.
I’m sorry for the lack of the other images. I thank anyone who can help! A great big hug, Momentanius.
A guess: on the overdone method paintComponent, calling super.paintComponent(g) and only then, paint(g).
– user21742
A friend of mine informed the same thing, and Nothing. Very odd. I appreciate the help, still!
– Momentanius