mashine-obf
Mitglied
ich möchte in im jpanel (im mittleren Rechteck)ein bild ausgeben (_ImgBild), das sich im sekunden takt änder mit der farbe ändert
bekomme es aber nicht ausgegeben bitte um hilfe danke
bekomme es aber nicht ausgegeben bitte um hilfe danke
Code:
/*
package gui;
import java.awt.*;
import javax.swing.*;
public class ColorFrameMitImage extends JFrame {
JPanel _panel = null;
Color _colRed = null;
Color _colGreen = null;
Color _colBlue = null;
ImageIcon _ImgBild = null;
public class ColorThread extends Thread {
public void run() {
for ( int i = 1; i < 256; i += 1 ) {
try {
_ImgBild = new ImageIcon("c:\\"+i+".jpg");
_colRed = new Color(i,0,0);
_colGreen = new Color(0,i,0);
_colBlue = new Color(0,0,i);
_panel.repaint();
sleep(1);
} catch (InterruptedException e) {}
}
System.out.println("Fertig");
}
}
public class ColorPanel extends JPanel {
public ColorPanel() {
//setDoubleBuffered(false);
}
public void paintComponent(Graphics graphics) {
super.paintComponent(graphics);
int width = getWidth();
int height = getHeight();
Graphics g = getGraphics();
g.setColor(_colRed);
g.fillRect(0,0,width,height);
if ( width > 100 && height > 100 )
{
g.setColor(_colGreen);
g.fillRect(50,50,width-100,height-100);
}
if ( width > 200 && height > 200 )
{
g.setColor(_colBlue);
g.fillRect(100,100,width-200,height-200);
}
// graphics.drawImage(_ImgBild,0,0,this);
}
}
public ColorFrameMitImage() {
_panel = new ColorPanel();
getContentPane().add(_panel,BorderLayout.CENTER);
setTitle("Frame mit wechselnder Farbe");
setSize(600, 600);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
new ColorThread().start();
}
public static void main(String[] args) {
new ColorFrameMitImage();
}
}