Bonsoir, cela n'a rien avoir avec le html donc pour afficher une image au pire en utilise JLabel img =new JLabel(new ImageIcone( "path" )); ce qui est mieux c'est de redefinir un JPanel
public class ImageContainer extends JPanel{
private Image img;
/** * */ public ImageContainer(String path) { } /** * * @param image */ public ImageContainer(Image image){ this.img = image; repaint(); }
@Override protected void paintComponent(Graphics g) { Graphics2D g2d = (Graphics2D) g; g2d.drawImage(img, 0, 0, getWidth(), getHeight(), null); } }
Pour faire défiler il faut utiliser un Thread voila un exemple (execute le pour tester) dans lequel tu peut remplacer le texte par une image
import java.awt.AlphaComposite; import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Component; import java.awt.Font; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Image;
import javax.swing.JComponent; import javax.swing.JFrame; import javax.swing.JPanel;
public class NPbrogressComponent extends JPanel{
private RenderingThread renderingThread = new RenderingThread(); private Component parent; private Color backGround = Color.black; private Color forgeGround = Color.red; private Graphics2D g2d; boolean intro; int x = 0; private int height=45; private int width; private float composite;
String msg1 = "NOURI"; String msg2 = "MARWEN";
/** * */ public NPbrogressComponent(JComponent parent){ this.setBackground(backGround); this.parent= this.getParent(); this.setOpaque(false); // if(parent!=null){ // this.parent = parent; // System.out.println("zzzzzzzzzzzzzzz"); // height = parent.getHeight(); // width = parent.getWidth(); // }
}
public void start(){ renderingThread.start(); }
public void stop(){ renderingThread.stop();
}
/** * */ public void paint( Graphics g ){
int h = height+6; width = getWidth();
g2d = (Graphics2D) g; //g2d.setColor(backGround);
if(!intro){ g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, composite )); composite+=.1f;
//g2d.fillRect( 0, 0, width, height); g2d.clearRect( 0, 0, width, height); g2d.setColor(forgeGround); g2d.setStroke(new BasicStroke( 2.0f )); g2d.drawLine(0 ,h/2+5, width, h/2+5); g2d.setFont(new Font("Arial",1,16)); g2d.drawString( " NOURI 2008", x, h/2 ); try { Thread.sleep(160); } catch (InterruptedException e) { } if(composite>.9f){ intro=!intro; //g2d.clearRect(0, 0, width, height); } }else{ //g2d.fillRect( 0, 0, width, height); g2d.clearRect( 0, 0, width, height); g2d.setColor(forgeGround);
//g2d.drawString( "NOURIStyle", x, h/2 ); //g2d.setStroke(new BasicStroke( 9.0f )); g2d.setFont(new Font("Arial",1,14));
g2d.drawString( msg1, x, h/2 );
// if(x>(width/2)-10){ //g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.8f )); if(x%2 == 0){ h-=2; }else{ h+=2; } } //System.out.println(height); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.7f )); g2d.drawString(msg2, (width)-x, h/2 );
x++; if(x>width){ x = 0; String tmp = msg2; msg2=msg1; msg1=tmp; } } //g.drawImage(image, 0, 0, this); //g.drawImage(image2, (width), 0, this); }
/** * * @param compotent */ public void setParent(Component compotent){ this.parent= compotent;
}
/** * * @author NOURI * */ class RenderingThread extends Thread { /** * */ public void run(){ while(true){ try { repaint(); sleep(15); } catch ( Exception e ) {} } } }
public static void main(String[] args){
JFrame f= new JFrame(); f.setLocationRelativeTo(null); JPanel n = new JPanel(new BorderLayout()); NPbrogressComponent d =new NPbrogressComponent(n); n.add(d);
f.add(n); d.start(); f.setVisible(true); f.setSize(400, 444);
//f.pack(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
} }
|