它是以往任何时候都适合在一个applet的主要手段? [英] Is it ever appropriate to have a main method in an applet?

查看:102
本文介绍了它是以往任何时候都适合在一个applet的主要手段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图环绕的小程序使用规则我的头。我意识到,一个小程序并不一定有一个主要方法(它可以使用的init()代替),但每code样品我的教授提供的是一个小程序主要方法,像下面的code。

I am trying to wrap my head around the rules of applet use. I realize that an applet does not have to have a main method (it can use init() instead) but every code sample my professor provides is an applet with a main method, like in the code below.

我的理解是,它是不是在因为安全问题的小程序的主要手段是个好主意,这是正确的?当(如果有的话),我应该在一个applet使用的主要手段?

My understanding was that it is not a good idea to have a main method in an applet because of security issues, is this correct? When (if ever) should I use a main method in an applet?

另外,我的教授是用这样的嵌入一个PowerPoint presentation他能那么他的presentation中轻松运行小程序。将它仍然有可能像这样运行它嵌入到一个PowerPoint presentation一个小程序,如果使用 INTI()而不是 applet的主()?我问,因为我看不出有任何理由,除非它是必需的,当嵌入一个PowerPoint presentation小程序才能正常运行,他将使用的主要手段在这样的小程序。

Also, my professor is using applets like this embedded into a PowerPoint presentation which he can then run easily during his presentation. Would it still be possible to run an applet like this which was embedded into a PowerPoint presentation if the applet used inti() instead of main()? I ask that because I cannot see any reason why he would use a main method in such an applet unless it was required for the applet to run properly when embedded into a PowerPoint presentation.

//EventDispatcherThreadDemo.java

import javax.swing.*;

public class EventDispatcherThreadDemo extends Japplet{

    public EventDispatcherThreadDemo(){
        add(new JLabel("Hi, it runs from an event dispatch thread"));
    }

    public static void main(Stirng[] args){

        SwingUtilities.invokeLater(new Runnable(){

            public void run(){
                JFrame frame = new JFrame("EventDispatcherThreadDemo");
                frame.add(new EventDispatcherThreadDemo());
                frame.setSize(200, 200);
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }

        });

    }

}

P.S。这有什么好做的功课,只是想了解更多关于小程序。

P.S. This has nothing to do with homework, just trying to learn more about applets.

推荐答案

方法没有任何特殊含义的小程序。

The main method does not have any special meaning to an applet.

您是教授,包括它用几行火了类一个JFrame一起,才能够在命令行用一个简单的java foobar的命令来运行它。这是不是让运行的appletviewer foobar的命令,它可能有问题,与来自如PowerPoint另一个程序正在启动。它没有给予充分的Applet的环境,虽然,但演示程序可能是这么简单,它并不重要。

Your professor is including it along with a few lines to fire up the class in a JFrame, to be able to run it from the command line too with a simple "java foobar" command. This as opposed to having to run the "appletviewer foobar" command which may have issues with being launched from another program like PowerPoint. it does not give the full Applet environment though, but the demonstration programs may be so simple, it doesn't matter.

他为什么选择做这样而不是仅仅presenting你在,我不知道小程序一个很大的HTML页面。

Why he chose to do so instead of just presenting you with a big HTML page with the applets in, I do not know.

这篇关于它是以往任何时候都适合在一个applet的主要手段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆