English 中文(简体)
这个 java. execute () 方法的称呼是什么意思?
原标题:What does this java .execute() method call mean?

我在做一些阅读 通过太阳java教程, 我发现这个页面在这里:

如何制作一个苹果

在标题下, < strong> "Applets中的种子" 我发现了这个代码:

   //Background task for loading images.
    SwingWorker worker = (new SwingWorker<ImageIcon[], Object>() {
            public ImageIcon[] doInBackground() {
                final ImageIcon[] innerImgs = new ImageIcon[nimgs];
            ...//Load all the images...
            return imgs;
        }
        public void done() {
            //Remove the "Loading images" label.
            animator.removeAll();
            loopslot = -1;
            try {
                imgs = get();
            } ...//Handle possible exceptions
        }

    }).execute();
}

首先,我是新人,所以我很抱歉,如果这是一个愚蠢的问题。然而,我从来没有听说过这个“.excecute ()” 。 我不明白这一点,我无法从谷歌那里找到关于它的任何信息。 我看到这里是... 一个匿名的内科? (请纠正我), 它开始在图像中加载一个线。 我认为运行()的方法会被调用来启动()? 请帮助我澄清这个混乱 。

最佳回答

execut 是 SwingWorker 的一种方法。你看到的是 < a href=" http://docs.oracle.com/javase/spec/specs/jls/se7/html/jls-15.html#jls-15.html#jls-15.9.5" rel="nofolpolt" >anonomous clasle 被即时使用并立即调用其 execute 方法。

我不得不承认,我对代码汇编感到有点惊讶,因为它似乎将 execute 的结果分配给 worker 变量,而文件告诉我们, execute 省略 的函数。

如果我们稍微解构该代码, 它会更清楚。 首先, 我们创建一个匿名类, 扩展 < code> SwingWorker , 并同时创建它的实例( 这是括号中的大段) :

SwingWorker tmp = new SwingWorker<ImageIcon[], Object>() {
    public ImageIcon[] doInBackground() {
            final ImageIcon[] innerImgs = new ImageIcon[nimgs];
        ...//Load all the images...
        return imgs;
    }
    public void done() {
        //Remove the "Loading images" label.
        animator.removeAll();
        loopslot = -1;
        try {
            imgs = get();
        } ...//Handle possible exceptions
    }

};

然后我们调用 execut 并将结果指派给 worker (在我看来,这有点应该编译):

SwingWorker worker = tmp.execute();

update :实际上,我尝试了它,它doesn t 编译。所以不是伟大的示例代码。 这将汇编 :

SwingWorker worker = new SwingWorker<ImageIcon[], Object>() {
    public ImageIcon[] doInBackground() {
            final ImageIcon[] innerImgs = new ImageIcon[nimgs];
        ...//Load all the images...
        return imgs;
    }
    public void done() {
        //Remove the "Loading images" label.
        animator.removeAll();
        loopslot = -1;
        try {
            imgs = get();
        } ...//Handle possible exceptions
    }

};
worker.execute();
问题回答

.execute () 在匿名类的例子中调用执行方法; 即由 new Swingworker< ImageIcon[], Object>() {...\\\\/code> 创建的对象。 (这是一个扩展 SwingWorker 类的类别 。 )

根据 Javadoc, execut 方法规定了在现有工人线上执行的案件所代表的任务,工人线的生命周期(如创建、启动等)由Swing基础设施负责。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...