Hey everyone, i'm working on this code...i'm trying to put some images ---animations--on to my jpanel..the problem is everytime i try that, it gets repainted with initial screen setup I have...how do i solve this..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 NewClass1 extends JFrame
{
JScrollPane scrollPane;
ImageIcon icon;
ImageIcon icon2;
//ImageIcon icon3;
Image image;
JButton button;
public NewClass1()
{
icon = new ImageIcon("backgroundblue5.gif");
icon2 = new ImageIcon("h1.gif");
//icon3 = new ImageIcon("Board.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);
super.paintComponent(g);
}
};
panel.setLayout(null);
panel.setOpaque( false );
panel.setPreferredSize( new Dimension(400, 400) );
scrollPane = new JScrollPane( panel );
getContentPane().add( scrollPane );
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1024, 768);
setResizable(false);
setLocationRelativeTo( null );
setVisible(true);
}
private void Start(){
Toolkit toolkit = Toolkit.getDefaultToolkit();
Image image = toolkit.getImage("h1.gif");
Graphics gr = getGraphics();
gr.drawImage(image,200,200,600,500,null);
}
public static void main(String [] arg){
NewClass1 h = new NewClass1();
h.Start();
}
}
why is it that the code in Start() does not paint on the screen set in my constructor NewClass1() where I have my buttons and everything?