当前位置: 技术问答>java相关
看看这几个APPLET程序。(在线等2小时)
来源: 互联网 发布时间:2015-07-22
本文导语: 一﹐import java.applet.*; import java.awt.*; public class Example extends Applet{ public void init(){} public void paint(Graphics g){ String s="Using drawsString!"; char[] ch="chars"; byte[] b={'a','b','c','d',1}; g.drawString(s,100,25); g.drawChars(ch,2,3...
一﹐import java.applet.*;
import java.awt.*;
public class Example extends Applet{
public void init(){}
public void paint(Graphics g){
String s="Using drawsString!";
char[] ch="chars";
byte[] b={'a','b','c','d',1};
g.drawString(s,100,25);
g.drawChars(ch,2,3,100,50);
g.drawByte(b,0,5,100,75);}}
错误--------------------Configuration: Example - JDK version 1.4 --------------------
C:JCreatorMyProjectsExampleExample.java:19: incompatible types
found : java.lang.String
required: char[]
char[] ch="chars";
^
C:JCreatorMyProjectsExampleExample.java:23: cannot resolve symbol
symbol : method drawByte (byte[],int,int,int,int)
location: class java.awt.Graphics
g.drawByte(b,0,5,100,75);}}
^
2 errors
Process completed.
为什幺﹖
二﹐import java.applet.*;
import java.awt.*;
public class Example3 extends Applet{
public void paint(Graphics g){
g.drawString("Hello,World!!", 25, 25 );
Color c(0.5,0.3,0.7);
g.setColor(c);
String s=c.toString();
g.drawString(s,25,50);}}
错误--------------------Configuration: Example3 - JDK version 1.4 --------------------
C:JCreatorMyProjectsExample3Example3.java:6: ';' expected
Color c(0.5,0.3,0.7);
^
1 error
Process completed.
为什幺﹖
三﹐public class Example4 extends Applet {
public void paint(Graphics g) {
Font font1("TimesRoman",Font.PLAIN,16);
Font font2("Courier",Font.ITALIC,24);
Font font3("Helvetica",Font.BOLD,32);
g.setFont(font1);
g.drawString(font1.toString(),25,25);
g.setFont(font2);
g.drawString(font2.toString(),25,50);
g.setFont(font3);
g.drawString(font3.toString(),25,75);}}
错误C:JCreatorMyProjectsExample4Example4.java:19: ';' expected
Font font1("TimesRoman",Font.PLAIN,16);
^
C:JCreatorMyProjectsExample4Example4.java:20: ';' expected
Font font2("Courier",Font.ITALIC,24);
^
C:JCreatorMyProjectsExample4Example4.java:21: ';' expected
Font font3("Helvetica",Font.BOLD,32);
^
3 errors
四﹐import java.awt.*;
import java.applet.*;
public class Example5 extends Applet {
public void paint(Graphics g) {
Font font1=g.getFont();
String s;
StringBuffer buffer;
if(font1.isBold())
buffer.append("is not Bold");
else buffer.append("is not Bold");
s=buffer;
g.drawString(s,25,25);
if(font1.isItalic())
buffer.append("is Italic");
else buffer.append("is not Italic");
s=buffer;
g.drawString(s,25,50);
if(font1.isPlain())
buffer.append("is plan");
else buffer.append("is not plain");
s=buffer;
g.drawString(s,25,90);}}
错误C:JCreatorMyProjectsExample5Example5.java:23: incompatible types
found : java.lang.StringBuffer
required: java.lang.String
s=buffer;
^
C:JCreatorMyProjectsExample5Example5.java:28: incompatible types
found : java.lang.StringBuffer
required: java.lang.String
s=buffer;
^
C:JCreatorMyProjectsExample5Example5.java:33: incompatible types
found : java.lang.StringBuffer
required: java.lang.String
s=buffer;
^
3 errors
请帮忙﹗﹗﹗
还请问这些程序的实现过程是不是:先编译产生*.class文件﹐然后在*.class这个文件同目录下建立一个同名的*.html文件﹐嵌入执行此*.html文件就可以显示程序中的图像了﹖还是用别的什幺方法实现﹐谢谢﹗
import java.awt.*;
public class Example extends Applet{
public void init(){}
public void paint(Graphics g){
String s="Using drawsString!";
char[] ch="chars";
byte[] b={'a','b','c','d',1};
g.drawString(s,100,25);
g.drawChars(ch,2,3,100,50);
g.drawByte(b,0,5,100,75);}}
错误--------------------Configuration: Example - JDK version 1.4 --------------------
C:JCreatorMyProjectsExampleExample.java:19: incompatible types
found : java.lang.String
required: char[]
char[] ch="chars";
^
C:JCreatorMyProjectsExampleExample.java:23: cannot resolve symbol
symbol : method drawByte (byte[],int,int,int,int)
location: class java.awt.Graphics
g.drawByte(b,0,5,100,75);}}
^
2 errors
Process completed.
为什幺﹖
二﹐import java.applet.*;
import java.awt.*;
public class Example3 extends Applet{
public void paint(Graphics g){
g.drawString("Hello,World!!", 25, 25 );
Color c(0.5,0.3,0.7);
g.setColor(c);
String s=c.toString();
g.drawString(s,25,50);}}
错误--------------------Configuration: Example3 - JDK version 1.4 --------------------
C:JCreatorMyProjectsExample3Example3.java:6: ';' expected
Color c(0.5,0.3,0.7);
^
1 error
Process completed.
为什幺﹖
三﹐public class Example4 extends Applet {
public void paint(Graphics g) {
Font font1("TimesRoman",Font.PLAIN,16);
Font font2("Courier",Font.ITALIC,24);
Font font3("Helvetica",Font.BOLD,32);
g.setFont(font1);
g.drawString(font1.toString(),25,25);
g.setFont(font2);
g.drawString(font2.toString(),25,50);
g.setFont(font3);
g.drawString(font3.toString(),25,75);}}
错误C:JCreatorMyProjectsExample4Example4.java:19: ';' expected
Font font1("TimesRoman",Font.PLAIN,16);
^
C:JCreatorMyProjectsExample4Example4.java:20: ';' expected
Font font2("Courier",Font.ITALIC,24);
^
C:JCreatorMyProjectsExample4Example4.java:21: ';' expected
Font font3("Helvetica",Font.BOLD,32);
^
3 errors
四﹐import java.awt.*;
import java.applet.*;
public class Example5 extends Applet {
public void paint(Graphics g) {
Font font1=g.getFont();
String s;
StringBuffer buffer;
if(font1.isBold())
buffer.append("is not Bold");
else buffer.append("is not Bold");
s=buffer;
g.drawString(s,25,25);
if(font1.isItalic())
buffer.append("is Italic");
else buffer.append("is not Italic");
s=buffer;
g.drawString(s,25,50);
if(font1.isPlain())
buffer.append("is plan");
else buffer.append("is not plain");
s=buffer;
g.drawString(s,25,90);}}
错误C:JCreatorMyProjectsExample5Example5.java:23: incompatible types
found : java.lang.StringBuffer
required: java.lang.String
s=buffer;
^
C:JCreatorMyProjectsExample5Example5.java:28: incompatible types
found : java.lang.StringBuffer
required: java.lang.String
s=buffer;
^
C:JCreatorMyProjectsExample5Example5.java:33: incompatible types
found : java.lang.StringBuffer
required: java.lang.String
s=buffer;
^
3 errors
请帮忙﹗﹗﹗
还请问这些程序的实现过程是不是:先编译产生*.class文件﹐然后在*.class这个文件同目录下建立一个同名的*.html文件﹐嵌入执行此*.html文件就可以显示程序中的图像了﹖还是用别的什幺方法实现﹐谢谢﹗
|
问题一:char[] ch={'c','h','a','r','s'};
byte[] b={'a','b','c','d','1'};
问题二:Color c=new Color(0.5,0.3,0.7);//注意创建对象的方法!没有象你那样的简写
问题三:和问题2是一样的错误。
问题四:s=buffer;这是错误的!s是String类型,而buffer是StringBuffer类型,它们的类型不匹配!
byte[] b={'a','b','c','d','1'};
问题二:Color c=new Color(0.5,0.3,0.7);//注意创建对象的方法!没有象你那样的简写
问题三:和问题2是一样的错误。
问题四:s=buffer;这是错误的!s是String类型,而buffer是StringBuffer类型,它们的类型不匹配!
|
第四个问题:
把s =buffer,改为。
char[] b;
buffer.getChars( 0 , buffer.length( ), b, 0 );
该用法的具体描述:请看
http://www.servertec.com/products/iscript/docs/StringBuffer_getChars.html
别忘了给加分啊。哈哈
把s =buffer,改为。
char[] b;
buffer.getChars( 0 , buffer.length( ), b, 0 );
该用法的具体描述:请看
http://www.servertec.com/products/iscript/docs/StringBuffer_getChars.html
别忘了给加分啊。哈哈
|
回第二问:Color c(0.5,0.3,0.7);出错是因设置色彩参数只能是从0到255的整型或浮点型的0。0到1。0。因你没说明是设置的浮点型,建议改为0到255的整型。
|
可以重载一个类,名为COLOR把其参数为float。
|
关于不要创建htm文件的问题
只要在jcreator里面设置一个工具石塔对应的是jdkbin里面的appletviewer就行了
arguement:filename
initial:filedirectory
只要在jcreator里面设置一个工具石塔对应的是jdkbin里面的appletviewer就行了
arguement:filename
initial:filedirectory
|
Color的构造函数可以是new Color(float,float,float);不过要加一个'f'
例如:Color color1=new Clor(0.2f,0.6f,0.8f);
例如:Color color1=new Clor(0.2f,0.6f,0.8f);