i need to make my applet be runnable as application.
therefore i did nothing more that adding a main method like
public static void main(String args[])
{
final Memory memory = new Memory();
JFrame frame = new JFrame();
frame.add(memory);
frame.setSize(550, 550);
frame.setResizable(false);
memory.init();
memory.start();
// minimize !!
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent we)
{
memory.destroy();
System.out.println("Applikation wird geschlossen");
System.exit(0);
}
});
frame.setVisible(true);
}
but by launching it as application i get a NullPointerException in my init() methode where i create my offscreen Buffer:
public void init()
{
//Definition des des OffScreen Bereiches
offscreenImg = createImage(getSize().width, getSize().height);
offscreen = (Graphics2D)offscreenImg.getGraphics();
offscreen.setColor(new Color(247, 22, 20));
offscreen.setFont(new Font("Monospaced", Font.BOLD, 18));
showStartMenu();
}
right at offscreenImg = createImage(getSize().width, getSize().height);
first i thought it would be cause an application doesnt seek for the dimension of the applet in the html so i have to set it with setSize(…). but this doesnt fix the problem.
any ideas ?
here, I sympathise with you that this is one of those really crappy parts of AWT desgin/docs that I recall having lots of pain in early days discovering :(.