I just started using JFrames and such instead of Applets, and I'm having some trouble using a backbuffer like I use to. I made a smple program to demonstrate what I mean.
It kept telling me that I cannot make a non-static reference to something static. So I went about changing things to static, hoping that would solve the problem... but, I got to the createImage method and it says "Cannot make a static reference to the non-static method createImage(int, int) from the type Component" So yeah, that's rather unfortunate. Any tips? :/
Code:import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SomeGraphics extends JFrame
{
public static int WIDTH = 300, HEIGHT = 300;
public static Image backbuffer = createImage(WIDTH, HEIGHT);
public static Graphics backg = backbuffer.getGraphics();
public static int speed = 20;
public static int x1 = 0, y1 = 0, x2 = 300, y2 = 300;
public static ActionListener timerAction = new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
update();
}
};
public SomeGraphics()
{
setVisible(true);
setSize(WIDTH, HEIGHT);
}
public void paint(Graphics g)
{
g.drawImage(backbuffer, 0, 0, this);
}
public static void update()
{
x1++;
x2--;
backg.setColor(Color.white);
backg.fillRect(0, 0, WIDTH, HEIGHT);
backg.setColor(Color.red);
backg.drawLine(x1, y1, x2, y2);
}
public static void main(String args[])
{
SomeGraphics SG = new SomeGraphics();
new Timer(speed, timerAction).start();
}
}

