注册 登录
编程论坛 JAVA论坛

刚开始学JAVA

Rainbo 发布于 2018-04-12 13:02, 1876 次点击
我想运行书上的这个程序要怎么做
只有本站会员才能查看附件,请 登录
9 回复
#2
疯狂的小a2018-04-12 19:09
先安装jdk,在安装eclipse
#3
wangjingchun2018-04-17 09:52
我也是新手   要下什么软件呢  求链接和使用手册
#4
疯狂的小a2018-04-17 11:00
回复 3楼 wangjingchun
#5
Rainbo2018-04-17 16:00
回复 楼主 Rainbo
我用的是 editplus 和 命令方式

帮我解决一下 java Ch1_7.class 不能执行的问题

Ch1_7.java
程序代码:
import java.awt.*;
import java.applet.*;

public class Ch1_7 extends Applet
{
    int width, height;
    Image image;

    Graphics g1;

    public void init ( )
    {
        setBackground ( Color.black );
        this.setSize ( 350, 310 );

        width = getSize ( ).width;
        height = getSize ( ).height;
        image = createImage ( width, height );
        g1 = image.getGraphics ( );
    }

    public void paint ( Graphics g )
    {
        g1.clearRect ( 0, 0, width, height );
        g1.setColor ( Color.red );
        int i, j;
        double x, y, r;

        for ( i = 0; i <= 90; i ++ )
            for ( j = 0; j <= 90; j ++ )
            {
                r = Math.PI / 45 * i * ( 1 - Math.sin ( Math.PI / 45 * j ) ) * 18;
                x = r * Math.cos ( Math.PI /45 * j ) * Math.sin ( Math.PI / 45 * i ) + width / 2;
                y = -r * Math.sin ( Math.PI /45 * j ) + height / 4;

                g1.fillOval ( ( int ) x, ( int ) y, 2, 2 );
                g1.fillRect ( ( int ) x, ( int ) y, 1, 1 );
            }
        g.drawImage ( image, 0, 0, this );
    }
}


只有本站会员才能查看附件,请 登录


#6
Rainbo2018-04-17 16:02
回复 3楼 wangjingchun
我用的是 editplus 和 命令方式

帮我解决一下 java Ch1_7.class 不能执行的问题

Ch1_7.java
程序代码:
import java.awt.*;
import java.applet.*;

public class Ch1_7 extends Applet
{
    int width, height;
    Image image;

    Graphics g1;

    public void init ( )
    {
        setBackground ( Color.black );
        this.setSize ( 350, 310 );

        width = getSize ( ).width;
        height = getSize ( ).height;
        image = createImage ( width, height );
        g1 = image.getGraphics ( );
    }

    public void paint ( Graphics g )
    {
        g1.clearRect ( 0, 0, width, height );
        g1.setColor ( Color.red );
        int i, j;
        double x, y, r;

        for ( i = 0; i <= 90; i ++ )
            for ( j = 0; j <= 90; j ++ )
            {
                r = Math.PI / 45 * i * ( 1 - Math.sin ( Math.PI / 45 * j ) ) * 18;
                x = r * Math.cos ( Math.PI /45 * j ) * Math.sin ( Math.PI / 45 * i ) + width / 2;
                y = -r * Math.sin ( Math.PI /45 * j ) + height / 4;

                g1.fillOval ( ( int ) x, ( int ) y, 2, 2 );
                g1.fillRect ( ( int ) x, ( int ) y, 1, 1 );
            }
        g.drawImage ( image, 0, 0, this );
    }
}


只有本站会员才能查看附件,请 登录
#7
疯狂的小a2018-04-17 19:56
步骤1:你需要在Ch1_7.class文件同目录下新建一个Ch1_7.html
程序代码:
<HTML>
    <HEAD>
        <TITLE>Applet Test</TITLE>
    </HEAD>
    <BODY>
        <applet code = "Ch1_7.class" width = 100 height = 30></applet>
    </BODY>
</HTML>

只有本站会员才能查看附件,请 登录

只有本站会员才能查看附件,请 登录

步骤2:打开cmd命令窗口输入appletviewer Ch1_7.html
只有本站会员才能查看附件,请 登录

步骤3:此时你就可以看到结果了
只有本站会员才能查看附件,请 登录
#8
Rainbo2018-04-17 22:29
回复 7楼 疯狂的小a
非常感谢!!以后还会有很多问题麻烦前辈,还望不吝赐教。
#9
疯狂的小a2018-04-17 22:33
回复 8楼 Rainbo
不客气,有空就结下贴
#10
有多难2018-04-18 22:41
回复 7楼 疯狂的小a
漂亮
1