简体   繁体   中英

applet to Jframe

I've followed kilobolt's tutorial to make a game ( http://www.kilobolt.com/unit-2-creating-a-game-i.html ) then changed it. I've used applet but now I want to turn it into JFrame.

What I've done:

1- I've imported and extended JFrame instead of Applet.

2- I've changed init method into a constructor and added

public static void main(String[] args)
{
    // Use the event dispatch thread to build the UI for thread-safety.
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            new AltMain(); //AltMain is the name of my main class.
        }
    });
}

I've copied this code from somewhere and I don't exactly know what this does. I will probably just use this instead:

public static void main(String[] args){
    new AltMain();
}

What I couldn't:

These required some changing: (My first priority right now)

base = getDocumentBase();

and

bg = getImage(base, "data/bg space.jpg");

GetImage and GetDocumentBase give me "undefined for the type AltMain" error.

How can I fix these? Is there any JFrame equivalent for these? Also since I cannot run the program I'm not sure if anything else is necessary. Is there anything else I must do?

These are my other methods:

public void run(){
public void start(){
public void update(Graphics g){
public void paint(Graphics g){

How am i supposed to connect them.

The code is very long so I've just posted a summary. If necessary I can write more of the code. Any help would be appreciated. Thanks in advance.

You need to understand what the functions do rather than just copy-pasting them and hoping for the best.

But the main idea is this: an applet (which uses a JApplet) has several functions that are called automatially.

An application (which uses a JFrame) only has the main() method as an entry point. It doesn't automagically call any other functions for you, so if you have existing functions (the JApplet functions), you have to call them from the main() method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM