简体   繁体   English

小程序到Jframe

[英]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. 我按照千斤顶的教程制作了游戏( http://www.kilobolt.com/unit-2-creating-a-game-i.html ),然后进行了更改。 I've used applet but now I want to turn it into JFrame. 我使用过applet,但现在我想将其转换为JFrame。

What I've done: 我所做的:

1- I've imported and extended JFrame instead of Applet. 1-我已经导入并扩展了JFrame而不是Applet。

2- I've changed init method into a constructor and added 2-我已经将init方法更改为构造函数并添加了

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. GetImage和GetDocumentBase给我“类型为MainMain的未定义”错误。

How can I fix these? 我该如何解决? Is there any JFrame equivalent for these? 是否有与之等效的JFrame? 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. 但是主要思想是这样的:一个applet(使用JApplet)具有几个被自动调用的功能。

An application (which uses a JFrame) only has the main() method as an entry point. 应用程序(使用JFrame)仅将main()方法作为入口点。 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. 它不会自动为您调用其他任何函数,因此,如果您已有现有的函数(JApplet函数),则必须从main()方法中调用它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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