Przy tworzeniu panela netbeans generuje taki kod:
private javax.swing.JPanel jPanel1;
jPanel1 = new javax.swing.JPanel();
i nie można tego edytować ale znalazłem że można to zmienić w custom creation code.
Więc stworzyłem klasę GeometricStructureTest i ustawiłem ją w costom creation code.
Class:
public class GeometricStructureTest extends JPanel{
public void funkcja()
{
}
private void doDrawing(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(Color.blue);
Dimension size = getSize();
Insets insets = getInsets();
int w = size.width - insets.left - insets.right;
int h = size.height - insets.top - insets.bottom;
System.out.println("przerysowalo");
Random r = new Random();
for (int i = 0; i < 1000; i++) {
int x = Math.abs(r.nextInt()) % w;
int y = Math.abs(r.nextInt()) % h;
g2d.drawLine(x, y, x, y);
}
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
doDrawing(g);
}
}
Teraz pytanie jak wywołać funkcje z tej klasy bo to nie dziala
jPanel1.funkcja();