Hi,
Ich habe eine Anwendung, dass ich Bilder in ein ImageLabel lade, die nach der Reihe angezeigt werden. Das Problem ist jetzt, dass ich verschiedene Modi von Bildübergänge verwende, jedoch wenn ich den Modi für einen Bildübergang wähle, dann wird wenn ich während der Slideshow die Fenstergröße verändere, das Bild nicht mehr entsprechend angepasst. Wenn ich keinen Übergang wähle und die Bilder anzeigen lasse, funktioniert das verändern der Fenstergröße.
Weiß vielleicht jemand, wie ich das definieren muss, damit die Bilder wenn ich einen Bildübergang verwende, bei Veränderung der Fenstergröße korrekt an die Größe angepasst werden?? :bahnhof:
danke im voraus
lg matti
Ich habe eine Anwendung, dass ich Bilder in ein ImageLabel lade, die nach der Reihe angezeigt werden. Das Problem ist jetzt, dass ich verschiedene Modi von Bildübergänge verwende, jedoch wenn ich den Modi für einen Bildübergang wähle, dann wird wenn ich während der Slideshow die Fenstergröße verändere, das Bild nicht mehr entsprechend angepasst. Wenn ich keinen Übergang wähle und die Bilder anzeigen lasse, funktioniert das verändern der Fenstergröße.
Code:
public class ImageLabel extends JLabel implements Runnable
{
private ImageIcon icon;
private Image theOldImage;
private Image theNewImage;
private int x = 0;
private int y = 0;
private int w = 0;
private int h = 0;
private int width = 0;
private int height = 0;
public ImageLabel()
{
super();
}
public void setIcon(ImageIcon icon) {
this.icon = icon;
}
public void paint( Graphics g )
{
super.paintComponent( g ); // should always call this method
Dimension d = getSize();
//the icon is directly used when the TRANSITION_MODE is set to "WithoutTransition"
if(icon != null)
{
double windowWidth = this.getWidth();
double windowHeight = this.getHeight();
double pictureWidth = icon.getIconWidth();
double pictureHeight = icon.getIconHeight();
double windowRatio = windowHeight/windowWidth;
double pictureRatio = pictureHeight/pictureWidth;
int drawWidth;
int drawHeight;
if(pictureRatio > windowRatio){
drawHeight = (int)windowHeight;
drawWidth = (int)(drawHeight/pictureRatio);
}else{
drawWidth = (int)windowWidth;
drawHeight = (int)(drawWidth*pictureRatio);
}
//center
int x = (int)(windowWidth-drawWidth)/2;
int y = (int)(windowHeight-drawHeight)/2;
d.setSize(drawWidth,drawHeight);
g.drawImage( icon.getImage(), x, y, d.width, d.height, null );
}
if(TransitionDialog.TRANSITION_MODE == "VanishToCorner")
{
if( theNewImage != null )
{
g.drawImage( theNewImage, 0, 0, width, height, null );
}
if( theOldImage != null )
{
g.drawImage( theOldImage, x, y, w, h, null );
}
}
else
{
if( theOldImage != null )
{
g.drawImage( theOldImage, 0, 0, width, height, null );
}
if( theNewImage != null )
{
g.drawImage( theNewImage, x, y, w, h, null );
}
}
}
// Need this method in order to load an image for display
public void setImage( Image i )
{
theOldImage = theNewImage;
theNewImage = i;
}
public void changeImage()
{
Thread t = new Thread( this );
t.start();
}
public void run()
{
Dimension d = this.getSize();
width = d.width;
height = d.height;
if(TransitionDialog.TRANSITION_MODE == "SlideFromRight")
{
x = width;
y = 0;
w = width;
h = height;
do
{
x-=2;
this.repaint();
try
{
Thread.sleep(1);
}
catch(InterruptedException ex)
{}
} while( x > 0 );
}
else if(TransitionDialog.TRANSITION_MODE == "ExpandFromRight")
{
x = width;
y = 0;
w = 0;
h = height;
do
{
x-=2;
w+=2;
this.repaint();
try
{
Thread.sleep(1);
}
catch(InterruptedException ex)
{}
} while( x > 0 );
}
else if(TransitionDialog.TRANSITION_MODE == "VanishToCorner")
{
x = 0;
y = 0;
w = width;
h = height;
double wInc = width/200;
double hInc = height/200;
do
{
x = (int)(x + wInc);
y = (int)(y + hInc);
w = (int)(w - wInc);
h = (int)(h - hInc);
this.repaint();
try
{
Thread.sleep(1);
}
catch(Exception ex){}
} while( x < width );
}
else if(TransitionDialog.TRANSITION_MODE == "ExpandOutwards")
{
x = width/2;
y = height/2;
w = 0;
h = 0;
double wInc = width/200;
double hInc = height/200;
do
{
x = (int)(x - wInc);
y = (int)(y - hInc);
w = (int)(w + 2*wInc);
h = (int)(h + 2*hInc);
this.repaint();
try
{
Thread.sleep(1);
}
catch(InterruptedException ex){}
} while( x > 0 );
}
}
public void update(Graphics g)
{
paint(g);
}
}
Weiß vielleicht jemand, wie ich das definieren muss, damit die Bilder wenn ich einen Bildübergang verwende, bei Veränderung der Fenstergröße korrekt an die Größe angepasst werden?? :bahnhof:
danke im voraus
lg matti