import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Gametry {
private static void GUItry() {
JFrame f = new JFrame("Game Window");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel emptyLabel = new JLabel("");
emptyLabel.setPreferredSize(new Dimension(800,600));
f.getContentPane().add(emptyLabel,BorderLayout.CENTER);
f.pack();
f.setVisible(true);
}
public static void main(String args[]) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
GUItry();
}
});
}
public class ImageApplet extends JApplet {
public void init() {
Container content_pane = getContentPane();
Image img = getImage (getCodeBase (), "Halo.jpeg");
DrawingPanel drawing_panel = new DrawingPanel (img);
content_pane.add (drawing_panel);
}
}
}
class DrawingPanel extends JPanel {
Image img;
DrawingPanel (Image img)
{this.img = img; }
public void paintComponent (Graphics g) {
super.paintComponent (g);
int imgX = getSize ().width/2 - img.getWidth (this);
int imgY = getSize ().height/2 - img.getHeight (this);
g.drawImage (img, imgX, imgY, this);
}
}
Java errors
I get this error:
C:\Users\mark\Desktop>java gametry.class
Exception in thread "main" java.lang.NoClassDefFoundError: gametry/class
Caused by: java.lang.ClassNotFoundException: gametry.class
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
Here's my source:
Please help, i'm not sure what i've done wrone. :D
You never added an Image to your JFrame. You only added a DrawingElement to your applet class, which never runs, since you launch the "Gametry" class and not the applet.
I am confused why you have an applet and a JFrame.
I am confused why you have an applet and a JFrame.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement