Hallo Java Community,
Ich bin dabei ein Bild in mein JFrame einzufügen.
Dabei kriege ich aber diese Compiler Fehler
Ich bin dabei ein Bild in mein JFrame einzufügen.
Dabei kriege ich aber diese Compiler Fehler
Code:
java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.checkNotAWindow(Unknown Source)
at java.awt.Container.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at javax.swing.JFrame.addImpl(Unknown Source)
at java.awt.Container.add(Unknown Source)
at main.MainUserInterface.<init>(MainUserInterface.java:67)
at main.MainUserInterface$1.run(MainUserInterface.java:54)
at java.awt.event.InvocationEvent.dispatch(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$500(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.awt.EventQueue$3.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.ProtectionDomain$JavaSecurityAccessImpl.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
Java:
package main;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class GuiBackground extends JFrame {
Image background;
public GuiBackground(){
setFocusable(true);
ImageIcon u = new ImageIcon("C:\\Users\\Cedric\\workspace\\LOTS\\Images\\startBackground.jpg");
background = u.getImage();
}
public void paint(Graphics g){
super.paint(g);
Graphics2D backgroundDraw = (Graphics2D)g;
backgroundDraw.drawImage(background, 0, 0, null);
}
}
Zuletzt bearbeitet von einem Moderator: