让 Applet Viewer 与我的代码一起显示 [英] Getting an Applet Viewer to display with my code

查看:23
本文介绍了让 Applet Viewer 与我的代码一起显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习 Java 课程,并且正在学习 Java Illuminate 3rd edition 的第 4 章.我们正在努力让 Applet 显示文本和/或设计和颜色.我正在使用 macbook,我正在通过 TextWrangler 进行编码,并试图在我的终端上运行我的,但由于某种原因,在我编译我的代码后,我无法显示 Applet 显示.请参阅下文以查看本书提供给我们的代码,他们希望我们通过运行代码来获得 Applet 查看器,但我不知道如何执行此操作.

I am taking a Java course at the moment and am on Chapter 4 in Java Illuminate 3rd edition. we are working on getting an Applet to display text and or designs and colors. i am working with a macbook and i am doing my coding through TextWrangler and am trying to run my on my terminal, but for some reason after i compile my code i cannot get the Applet display to show. Please see below to see the code the book gives us and they expect us to get an Applet Viewer by running the code, as such, but i cannot find out how to do so.

/* Drawing Text
   Anderson, Franceschi
*/


import javax.swing.JApplet;
import java.awt.Graphics;

public class DrawingTextApplet extends JApplet
{
  public void paint( Graphics g )
  {
    super.paint( g );
    g.drawString( "Programming is not", 140, 100 );
    g.drawString( "a spectator sport!", 140, 115 ); //for every new line you add 15 to the Y cord.
  }
}

推荐答案

直接来自 标签信息.页.请特别注意多行注释.

Direct from the applet tag info. page. Take particular note of the multi-line comments.

此示例需要安装 Java Development Kit.访问 Java SE 下载以获取最新的 JDK.

Applet 'Hello World' Example

This example requires the Java Development Kit installed. Visit Java SE Downloads for the latest JDK.

/* <!-- Defines the applet element used by the appletviewer. -->
<applet code='HelloWorld' width='200' height='100'></applet> */
import javax.swing.*;

/** An 'Hello World' Swing based applet.

To compile and launch:
prompt> javac HelloWorld.java
prompt> appletviewer HelloWorld.java  */
public class HelloWorld extends JApplet {

    public void init() {
        // Swing operations need to be performed on the EDT.
        // The Runnable/invokeAndWait(..) ensures that happens.
        Runnable r = new Runnable() {
            public void run() {
                // the crux of this simple applet
                getContentPane().add( new JLabel("Hello World!") );
            }
        };
        SwingUtilities.invokeAndWait(r);
    }
}

这篇关于让 Applet Viewer 与我的代码一起显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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