如何运行在Mac OS 10.6.6 Java小程序 [英] How to run a Java Applet on Mac OS 10.6.6

查看:166
本文介绍了如何运行在Mac OS 10.6.6 Java小程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的第一个编程班,我现在达到了学期结束。我有一个在线的投资组合,我分享我的大学成绩。在本学期这一点上,我想上传一些我已经创建了我的网上组合简单的小程序。我的投资组合托管在Weebly.com。我尝试了文件上传到主机上,使用简单的标签来运行HTML中的小程序。我敢肯定,我访问使用正确的目录中的文件。但在此之前,我们跳转到任何结论,我决定我应该在本地运行小程序,以确保我在做正确的一切。我在运行OS 10.6.6一个的MacBook Pro。在Java preferences,我的Java SE版本的Java SE 6中64位和Java SE 6 32位。我的插件版本是1.6.0(在/系统/图书馆/的Java / JavaVirtualMachines找到)。这些都是我的机器上唯一的版本我有。我的研究告诉我,我可能有分歧的版本。一些论坛都提出要回插件版本1.5(虽然,我不知道如何)。我是pretty肯定现在虽然苹果已经更新了Safari浏览器到​​64位版本。我让Eclipse设置为1.6也。似乎一切都在同一页上我了。

I am in my first programming class and I am now reaching the end of the semester. I have an online portfolio where I share my college accomplishments. At this point in the semester, I would like to upload some of the simple Applets I have created to my online portfolio. My portfolio is hosted on Weebly.com. I tried uploading the files to the host site and using the simple tags to run the applet within the html. I'm quite sure I'm accessing the files using the correct directories. But before we jump to any conclusions there, I decided I ought to run the applets locally to ensure I'm doing everything correctly. I am on a macbook pro running OS 10.6.6. In Java Preferences, my Java SE versions are Java SE 6 64-bit and Java SE 6 32-bit. My plug-in version is 1.6.0 (found in /System/Library/Java/JavaVirtualMachines). These are the only versions I have on my machine. My research tells me that I may be having version disagreements. Some forums have suggested going back to plug-in version 1.5 (although, I have no idea how). I'm pretty sure now though that apple has updated Safari to a 64-bit version. I have Eclipse set to 1.6 also. Everything seems to be on the same page to me.

是的,我读过关于这里遍地的所有相关问题。他们中的大多数现在已经有点过时了。

And yes, I've read all the related questions on here over and over. Most of them are a little outdated now.

下面是我的小程序code:

Here's my applet code:

/** 
 * Class NightScene - Draws a night scene (just for fun). 
 *  
 * @author Alex Stout 
 * @version February 8, 2011 
 */ 
package lab05_1; 
import java.awt.*; 
import javax.swing.*; 

public class NightScene extends JApplet 
{ 
        /** 
         * Paint method for applet. 
         *  
         * @param  g   the Graphics object for this applet 
         */ 
        public void paint(Graphics g) 
        { 
            g.setColor(Color.BLUE.darker().darker().darker());
            g.fillRect(0,0, this.getWidth(), this.getHeight());

            this.drawMoon(g);

            this.drawStars(g);

            this.drawHorizon(g);

        }
        public void drawStars(Graphics h)
        {   
            for (int i = 0 ; i <= this.getWidth()*5; i++)
            {
                int x = (int)(Math.random()*this.getWidth());
                int y = (int)(Math.random()*this.getHeight());

                h.setColor(Color.WHITE);
                h.fillOval (x, y, (int) (Math.random()*3)+1, (int) (Math.random()*3)+1);
            }

        }
        public void drawMoon(Graphics j)
        {
            int x = (int)(Math.random()*(this.getWidth()-200)+50);
            int y = (int)(Math.random()*(this.getHeight()-200)+50);

            j.setColor(Color.YELLOW.brighter().brighter());
            j.fillOval (x, y, this.getWidth()/10, this.getWidth()/10);
            j.setColor (Color.BLUE.darker().darker().darker());
            j.fillOval (x-(this.getWidth()/100), y-(this.getWidth()/100), this.getWidth()/10, this.getWidth()/10);
        }   

        public void drawHorizon(Graphics k)
        {
            int xi = 0;
            int xj = this.getWidth();
            int yj = this.getHeight();
            int rh = this.getHeight()-this.getHeight()/8;

            for (int i=0; i < xj; i++)
            {
                k.setColor(Color.BLACK);
                k.drawLine(xi, yj, xi, rh);

                k.setColor(Color.BLUE);
                if(Math.random()<0.50)
                {
                    k.drawLine(xi++, rh++, xi, rh++);
                }
                else
                {
                    k.drawLine(xi++, rh--, xi, rh--);
                }

            }           
        }
}    

下面是我的html code:

Here's my html code:

<html>
<Applet code = NightScene.class codebase = "." width = "400" height = "400">
</Applet>
</html>

下面是Java控制台输出:

Here's the Java Console output:

Java Plug-in 1.6.0_24
Using JRE version 1.6.0_24-b07-334-10M3326 Java HotSpot(TM) 64-Bit Server VM
User home directory = /Users/myUserName

有些人认为使用codeBase的=。所以我想这无济于事。它不具有或不具有它的工作。我试图把在完整的目录路径,没有成功。我试着报价和周围的类名没有引号。我想有和无最终的.class。我试图使一个lab05_1子目录,因为这是在code包的名称。没有运气。无论是类文件和HTML文件在桌面上的同一个文件夹。类文件是在Eclipse中创建原始的副本之一,但它具有相同的名称,所以我不认为这应该会导致不同的目录是什么问题。

Some people have suggested using codebase = "." so I tried that to no avail. It doesn't work with or without it. I tried putting in the full directory path, no success. I tried quotes and no quotes around the class name. I tried with and without .class on the end. I tried making a lab05_1 subdirectory because that's the package name in the code. No luck. Both the class file and the html file are in the same folder on the desktop. The class file is a copy of the original one that was created in Eclipse, but it has the same name, so I wouldn't think this should cause any problems being in different directories.

我不知道自己还能做什么。请帮忙!这已被irking我一个星期。我已经在这么简单的东西花了几个小时后小时。

I don't know what else to do. Please Help! This has been irking me for a week. I've spent hours upon hours on something so simple.

推荐答案

我没有在Mac方便检查,但如果你改变你的HTML文件,它应该工作---你丢失的包名在NightScene.class。

I don't have a Mac handy to check this, but if you change your HTML file, it should work --- you are missing the package name for the NightScene.class.

<html>
  <Applet code="lab05_1.NightScene.class" width="400" height="400"/>
</html>

有关APPLET标记甲骨文引用是<一个href=\"http://download.oracle.com/javase/6/docs/technotes/guides/deployment/deployment-guide/applet.html\"相对=nofollow>这里。

The Oracle reference for the APPLET tag is here.

在这个页面:

code = appletFile

CODE = appletFile

这需要
  属性给出该文件的名称
  包含编译applet的
  Applet的子类。此文件是相对的
  该applet的基本URL。它
  不能绝对。其中code或
  对象必须是present。价值
  的 appletFile 的可能形式
  的 classname.class 的或形式
   packagename.classname.class

This REQUIRED attribute gives the name of the file that contains the applet's compiled Applet subclass. This file is relative to the base URL of the applet. It cannot be absolute. One of CODE or OBJECT must be present. The value appletFile can be of the form classname.class or of the form packagename.classname.class.

编辑:的以防万一它是不明确的,目录应该进行布局,像这​​样:


Just in case it's not clear, the directory should be laid out like so:

    +-top-level/
      |
      +-lab05_1/
      | |
      | +-NightScene.class
      |
      +-test.html

这篇关于如何运行在Mac OS 10.6.6 Java小程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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