初学java,怎么也搞不懂为什么编译不通过,能说明理由吗?谢谢拉!
import java.awt.*;
import javax.swing.JApplet;
public class Stringtest extends JApplet{
int x1,y1;
String fsize;
String fname;
String fstyle;
String fcolor;
public void start(){
String param;
x1=Integer.parseInt(getParameter("x1"));
y1=Integer.parseInt(getParameter("y1"));
fsize=getParameter("fsize");
if(fsize==null)fsize="Not found";
/*try{if(param!=null)
fsize=Integer.parseInt(param);
else
fsize=0;
}catch(NumberFormatException e){
fsize=-1;
}*/
fname=getParameter("fname");
if(fname==null)fname="Not found";
fstyle=getParameter("fstyle");
if(fstyle==null)fstyle="Not found";
fcolor=getParameter("fcolor");
if(fcolor==null)fcolor="Not found";
}
public void paint(Graphics g){
g.setColor(Color.fcolor);
g.setFont(new Font(fname,fstyle,fsize));
g.drawString("This is String test!",x1,y1);
}
}
----------------解决方案--------------------------------------------------------
[CODE]import java.awt.*;
import javax.swing.JApplet;
public class Stringtest extends JApplet{
int x1,y1;
String fsize;
String fname;
String fstyle;
String fcolor;
public void start(){
String param;
x1=Integer.parseInt(getParameter("x1"));
y1=Integer.parseInt(getParameter("y1"));
fsize=getParameter("fsize");
if(fsize==null)fsize="Not found";
/*try{if(param!=null)
fsize=Integer.parseInt(param);
else
fsize=0;
}catch(NumberFormatException e){
fsize=-1;
}*/
fname=getParameter("fname");
if(fname==null)fname="Not found";
fstyle=getParameter("fstyle");
if(fstyle==null)fstyle="Not found";
fcolor=getParameter("fcolor");
if(fcolor==null)fcolor="Not found";
}
public void paint(Graphics g){
g.setColor(Color.RED);
int style=Integer.parseInt(fstyle);
int size=Integer.parseInt(fsize);
g.setFont(new Font(fname,style,size));
g.drawString("This is String test!",x1,y1);
}
}[/CODE]
注意参数传递
在需要int的地方,你怎么可以传String给它呢
好好看看API吧,
----------------解决方案--------------------------------------------------------
我会努力的!
----------------解决方案--------------------------------------------------------