Hallo,
ein ImgShowComponent-Objekt liefert ein Canvas:
____________________________________________________________________import java.awt.*;
public class ImgShowComponent extends Canvas
{
private Image img = null;ImgShowComponent( String sFile )
{
img = getToolkit().getImage( sFile );
^und das verwendest Du als Objekt in einem Applet?
Das funktioniert auch überall.
Das glaube ich nicht. Zeige mal ;-).
Was dagegen nicht funktioniert, ist die Darstellung von Buttons im Firefox.
Doch, das funktioniert:
import java.applet.*;
import java.awt.*;
public class Stromkreis extends Applet
{
Image MyImage;
Canvas Grafik;
public void init()
{
this.setBounds ( 0, 0, 600, 600 );
this.setLayout( new BorderLayout () );
Container buttonFrame1 = new Container ();
buttonFrame1.setBounds ( 0, 0, 300, 300 );
buttonFrame1.setLayout ( new FlowLayout () );
Container buttonFrame2 = new Container ();
buttonFrame2.setBounds ( 0, 0, 300, 300 );
buttonFrame2.setLayout ( new FlowLayout () );
Grafik = new ImgShowComponent (this, "Beispiel.jpg" );
this.add ( BorderLayout.CENTER, Grafik );
String labeled1 = new String ( "Farbe wechseln 1" );
Button click1 = new Button(labeled1);
buttonFrame1.add ( click1 );
String labeled2 = new String ( "Farbe wechseln 2" );
Button click2 = new Button(labeled2);
buttonFrame2.add ( click2 );
this.add ( BorderLayout.NORTH, buttonFrame1 );
this.add ( BorderLayout.SOUTH, buttonFrame2 );
this.setVisible ( true );
}
}
class ImgShowComponent extends Canvas
{
private Image img = null;
ImgShowComponent(Applet a, String sFile )
{
img = a.getImage( a.getDocumentBase(), sFile );
MediaTracker mt = new MediaTracker( this );
mt.addImage( img, 0 );
try { mt.waitForAll(); } catch( InterruptedException ex ) { }
}
public void paint( Graphics g )
{
g.drawImage( img, 0, 0, this );
g.drawString( "Hallo Welt", 100, 100 );
}
public Dimension getPreferredSize()
{
return new Dimension( img.getWidth( this ), img.getHeight( this ) );
}
public Dimension getMinimumSize()
{
return getPreferredSize();
}
}
viele Grüße
Axel