So wie ich das sehe, bleiben die Werte die du in dem Schleifen ausrechnest konstant, und haben eine feste länge, du kannst die Werte als einmal ausrechnen und sie dann in ein Array packen.
Pseudeo (vieleicht auch lauffähig, habs aber ohne IDE geschrieben) Code:
Code:
import java.awt.*;
import java.util.Random;
import javax.swing.*;
public class Main extends JPanel
{
private static final long serialVersionUID = -2294685016438617741L;
private static final Random r = new Random();
int[] ax = new int[größe des Arrays]; //größe des Arrays ist die Anzahl wie viele Zahlen in den Array passen sollen, die musst du halt einmal ausrechen/ausprinten lassen
int[] ay = new int[größe des Arrays];
@Override
protected void paintComponent( Graphics g )
{
super.paintComponent( g );
g.setColor(new Color(255,0,0));
for(int i : ax){
g.drawLine(i, 0, 0, 0);
}
for(int i : ay){
g.drawLine(i, 0, 0, 0);
}
//oder wenn du es in einer Schleife willst
for (int i = 0; i < Math.max(ax.lenght, ay.lenght); i++) {
if (i < ax.lenght) {
g.drawLine(ax[i], 0, 0, 0);
}
if (i < ay.lenght) {
g.drawLine(ay[i], 0, 0, 0);
}
}
}
public static void main( String[] args )
{
JFrame f = new JFrame( "Neoplastizismus" );
f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
f.setSize( 300, 300 );
f.add( new Main() );
f.setVisible( true );
f.setResizable(false);
f.setLocationRelativeTo(null);
int i = 0;
g.setColor(new Color(255,0,0));
for(int x = 10; x < getWidth() -10; x=+10){
ax[i] = x;
i++;
}
i = 0;
for(int y = 10; y < getHeight() - 10; y=+10){
ay[i] = y;
i++;
}
}
}
Aber ich glaube nicht das du damit wirklich Leistung sparts :)