R
reto
Gast
hallo
ich habe einen frame auf dem ein jcomponent sitzt auf dem etwas animiert werden soll. klappt eigentlich alles wunderbar nur sitzt darüber noch ein jdialog und wenn ich den zu schnell beweg oder sonst was mach dann friert manchmal einfach die ganze gui. hab natürlich hier schon bisschen rumgesucht und hab herausgefunden das swing nich thread sicher ist jedoch die funktion repaint() schon also dürfte das doch kein problem sein.
hier mal ein paar code ausschnitte
so ich hoffe ihr könnt mir helfen
schonmal danke im vorraus :wink:
ich habe einen frame auf dem ein jcomponent sitzt auf dem etwas animiert werden soll. klappt eigentlich alles wunderbar nur sitzt darüber noch ein jdialog und wenn ich den zu schnell beweg oder sonst was mach dann friert manchmal einfach die ganze gui. hab natürlich hier schon bisschen rumgesucht und hab herausgefunden das swing nich thread sicher ist jedoch die funktion repaint() schon also dürfte das doch kein problem sein.
hier mal ein paar code ausschnitte
Code:
public void paint( Graphics g ) {
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint( RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
g2.translate(g2.getClip().getBounds().width/2, g2.getClip().getBounds().height/2);
g2.scale(Zoom/100.0,Zoom/100.0);
g2.setColor(Color.WHITE);
g2.fill(g2.getClip()); //weisser Hintergrund
g2.setColor(Color.gray);//farbe grau
int k = g2.getClip().getBounds().width/400;
int n=1;
for (int i=0;i<=g2.getClip().getBounds().width/2;i=i+k*10){
g2.drawLine(i, -g2.getClip().getBounds().height/2, i, g2.getClip().getBounds().height/2);
n++;
if (n%3==0){
Font f = new Font(null, Font.PLAIN,900/Feld.drawArea.Zoom );
AttributedString as = new AttributedString(String.valueOf(i/100.0));
as.addAttribute( TextAttribute.FONT, f );
g2.drawString(as.getIterator(), i, 0);
}
}
n=1;
for (int i=0;i>=-g2.getClip().getBounds().width/2;i=i-k*10){
g2.drawLine(i, -g2.getClip().getBounds().height/2, i, g2.getClip().getBounds().height/2);
n++;
if (n%3==0){
Font f = new Font(null, Font.PLAIN,900/Feld.drawArea.Zoom );
AttributedString as = new AttributedString(String.valueOf(-i/100.0));
as.addAttribute( TextAttribute.FONT, f );
g2.drawString(as.getIterator(), i, 0);
}
}
n=1;
for (int i=0;i<=g2.getClip().getBounds().height/2;i=i+k*10){
g2.drawLine(-g2.getClip().getBounds().width/2,i ,g2.getClip().getBounds().width/2, i );
n++;
if (n%3==0){
Font f = new Font(null, Font.PLAIN,900/Feld.drawArea.Zoom );
AttributedString as = new AttributedString(String.valueOf(-i/100.0));
as.addAttribute( TextAttribute.FONT, f );
g2.drawString(as.getIterator(),0, i);
}
}
n=1;
for (int i=0;i>=-g2.getClip().getBounds().height/2;i=i-k*10){
g2.drawLine(-g2.getClip().getBounds().width/2,i ,g2.getClip().getBounds().width/2, i );
n++;
if (n%3==0){
Font f = new Font(null, Font.PLAIN,900/Feld.drawArea.Zoom );
AttributedString as = new AttributedString(String.valueOf(-i/100.0));
as.addAttribute( TextAttribute.FONT, f );
g2.drawString(as.getIterator(),0, i);
}
}
g2.setColor(Color.black); //Farbe wieder schwarz
Feld.feld.draw(g2);
Feld.dlgEig.refresh();
}
}
Code:
public void run(){
Feld.drawArea.repaint();
try {
if(move)Feld.sleep(100);
else Feld.sleep(500);
run();
} catch (InterruptedException e) {
// TODO Automatisch erstellter Catch-Block
e.printStackTrace();
}
}
so ich hoffe ihr könnt mir helfen
schonmal danke im vorraus :wink: