i wanted an image background on a Jpanel, so I got a programm that overrides the paint function. Now i have a code that draws the image as a background and also enabled me to have some buttons on it...now i want to add more images (or animations) on my screen. the problem is I try to paint an image , i dont see it..or it is repainted by the initial arrangments of the screen...here is the code

import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import java.awt.event.*;
import java.awt.image.ImageObserver;
import java.text.AttributedCharacterIterator;
import javax.swing.*;
import java.awt.*;
import java.awt.Color;


public class NewClass extends JFrame
{
JScrollPane scrollPane;
ImageIcon icon;
ImageIcon icon2;
JButton button;
public NewClass()
{
icon = new ImageIcon("b.gif");
JPanel panel = new JPanel()
{
protected void paintComponent(Graphics g)
{


int buttonPosition = 20;
g.drawImage(icon.getImage(), 0, 0, null);
g.drawImage(icon2.getImage(),0,0, null);


g.drawImage(new ImageIcon("image.gif").getImage(), buttonPosition, 420, null);
buttonPosition = buttonPosition + 120;
}


super.paintComponent(g);
}
};
panel.setLayout(null);
panel.setPreferredSize( new Dimension(400, 400) );
scrollPane = new JScrollPane( panel );
getContentPane().add( scrollPane );


JButton button = new JButton( "mybutton" );
button.setBounds(80,600,150,70);


panel.add( button );
setVisible(true);



}


public void Start(){
Graphics gr = getGraphics();
gr.drawImage(image,50,50,50,50,null);



}


public static void main(String [] arg){
new newClass();
Start();



}

PLEASE HELP!why is it that i can't get the images on the Start() function on my Jpanel???

Your images are not appearing on the panel because this code is so riddled with errors that it won't even compile, much less run correctly.

Post some working code and then perhaps your question can be addressed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.