请问我的java小应用程序,在ie里面无论中文英文都显示为方框,是怎么回事啊!!!!高分 你在程序力加上//<applet code=你的文件.class width=300 height=200></applet>当注释然后编译javac 文件.java然后:appletviewer 文件.java看看能不能显示? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 我前两天刚用过啊,我没调过什么东西啊!!!我还不知道要调什么地方呢有什么地方可以调的,请说出来我试试英文程序是这样的import java.applet.*;import java.awt.*;class Student{ float math,english,sum; float f(float k1,float k2) { sum=k1*math+k2*english; return sum; }}public class Average extends Applet{ Student wanghong,lihong; public void init() { wanghong=new Student(); lihong=new Student(); wanghong.math=60.0f; wanghong.english=80f; lihong.math=70.0f; lihong.english=90.0f; wanghong.sum=wanghong.f(2.0f,2.0f); lihong.sum=lihong.f(2.0f,2.0f); } public void paint(Graphics g) { g.drawString("lihong sum= "+lihong.sum,12,45); g.drawString("wanghong sum=" +wanghong.sum,12,60); }}中文是这样的import java.applet.*;import java.awt.*;class Father{ private int money; float weight,height; String head; String speak(String s) { return s; }}class Son extends Father{ String hand,foot;}public class Example4_6 extends Applet{ Son boy; public void init() { boy=new Son(); boy.weight=1.80f; boy.height=120f; boy.head="一个头"; boy.hand="两只手"; boy.foot="两只脚"; } public void paint(Graphics g) { g.drawString(boy.speak("我是儿子"),5,20); g.drawString(boy.hand+boy.foot+boy.head+boy.weight+boy.height,5,40); }}这两个程序我在编的机器上一样的操作,运行没有问题 yashiro(七枷社)谢谢了,用得的方法可以显示,但是为什么在ie里面不行呢???如果问题解决了一定高分相送 可能是找不到你的 applet.class ,是在一个目录里吗? 是在一个目录下阿,我在公司里面就是这样做的,在家就不行了,你的qq号是多少阿,csdn有的时候登陆不上来分还是会给的 问题还没有解决阿!!!!!!我用的是jdk1.4.0.1版的,操作系统是xp,而且就是这样的配置前几天还能用呢? 你的javac 时用javac -encoding GB2312 YourFile.javamouse右健,然后看你的IE的编码是否为GB2312 强制一下这web页的字符集成英文的试试.... 大家说的好泪!其实最简单的是设置java Application 中所有的控件的字体为宋体,字体大小为12祝你好运!----------------------我相信我会成功! XP 不支持java(IE)。你下载了插件吗?(jre1.4) 不是这个原因吧,我的2000系统上也不能显示 出applet来,难道说2000也不支持java(IE)? 你这样骂人,谁还会帮你解决。可能是内码转换的问题,下面给你两个方法参考一下,也许能解决你的问题,因为你的问题并不是每个人的机器上都能出现的,所以没法帮你试,碰到问题要尽量自己解决,这样效果会更好。我不是高手。/*用于内码转换的两个方法*/ public static String GBToUnicode(String strIn) { String strOut = null; if(strIn == null||(strIn.trim().equals(""))) { return strIn; } try{ byte[] b = strIn.getBytes("ISO8859_1"); strOut = new String(b,"GBK"); }catch(Exception ee){ } return strOut; } public static String UnicodeToGB(String strIn) { byte[] b; String strOut = null; if(strIn == null||(strIn.trim().equals(""))) { return strIn; } try{ b = strIn.getBytes("GBK"); strOut = new String(b,"ISO8859_1"); }catch(Exception ee){ } return strOut; } 实在不行,只好求助于国际化了。也就是说正规的程序里面是不允许出现汉字的(注释除外)。也就是把所有汉字都放到一个property文件里,给你一个例子:import java.io.Serializable;import java.util.*;// Referenced classes of package com.optel.telemaster.util:// LIException, Statuspublic class EnumType implements Serializable{ public EnumType() { code = 0; } public EnumType(int value) { code = value; } public int getIntValue() { return code; } public Status setIntCode(int value) throws LIException { if(!isValidCode(value)) { throw new LIException(new Status(10002)); } else { code = value; return new Status(1); } } public String getStringValue() throws LIException { String ret; try { ResourceBundle messages = getDefaultResourceBundle(); String str = Integer.toString(code); ret = messages.getString(str); } catch(MissingResourceException ex) { throw new LIException(new Status(10003), ex); } return ret; } public Status setStringValue(String str) throws LIException { int index = getIndex(str); if(index == 0x80000000) { throw new LIException(new Status(10002)); } else { code = index; return new Status(1); } } protected int[] getValidCode() { int temp[] = { 1, 2, 3, 4 }; return temp; } public boolean isValidCode(int value) { int validCodeArray[] = getValidCode(); for(int i = 0; i < validCodeArray.length; i++) if(value == validCodeArray[i]) return true; return false; } public boolean isValidString(String str) throws LIException { int index = 0; return getIndex(str) != 0x80000000; } public String getStringValue(Locale locale) throws LIException { String ret; try { ResourceBundle messages = getResourceBundle(locale); String str = getStringValue(); ret = messages.getString(str); } catch(MissingResourceException e) { throw new LIException(new Status(10005), e); } return ret; } public String getStringValue(int value) throws LIException { String ret; try { ResourceBundle messages = getDefaultResourceBundle(); ret = messages.getString(Integer.toString(value)); } catch(MissingResourceException ex) { throw new LIException(new Status(10003), ex); } return ret; } public String getStringValue(int value, Locale locale) throws LIException { String str = getStringValue(value); String ret = getStringValue(str, locale); return ret; } public String getStringValue(String str, Locale locale) throws LIException { String ret; try { ResourceBundle messages = getResourceBundle(locale); ret = messages.getString(str); } catch(MissingResourceException ex) { throw new LIException(new Status(10005), ex); } return ret; } private ResourceBundle getDefaultResourceBundle() throws LIException { return getResourceBundle(new Locale("zh", "CN")); } private ResourceBundle getResourceBundle(Locale locale) throws LIException { String className = getClassName(); ResourceBundle messages; try { messages = ResourceBundle.getBundle(className, locale); } catch(MissingResourceException e) { throw new LIException(new Status(10004), e); } return messages; } private int getIndex(String str) throws LIException { int index = 0x80000000; try { ResourceBundle messages = getDefaultResourceBundle(); for(Enumeration enum = messages.getKeys(); enum.hasMoreElements();) { String key = (String)enum.nextElement(); String value = messages.getString(key); if(str.compareToIgnoreCase(value) == 0) { index = Integer.parseInt(key); return index; } } } catch(MissingResourceException e) { throw new LIException(new Status(10003), e); } return index; } private String getClassName() { String className = getClass().getName(); int pos = className.lastIndexOf("."); String name = className.substring(pos + 1); return name; } private int code;} english显示正常吧,一般来说出现这样的情况,都是中文编码的问题,有没有试过楼上几位的方法?解决了吗?? java正则表达式的替换问题 一个向MySQL里插入图片的Java程序的问题(在线等...) 浏览器中显示不出Applet程序? 大侠请教一个问题 请问该怎么运行这个HelloWorld 我想对java有更深入的了解 Vector! think in java中关于io问题的一个例子? 我的JB6,在输入代码时,光标总是靠前一个字符??? 编写Socket客户端和服务器程序,客户端读取本地文件的数据,发送到服务器,服务器接收并存储到文件中。 如何使用QueryDataSet插入与更新一条记录? 关于java编码的讨论,请高手发言(需要对系统有所了解)!
英文程序是这样的
import java.applet.*;
import java.awt.*;
class Student
{
float math,english,sum;
float f(float k1,float k2)
{
sum=k1*math+k2*english;
return sum;
}
}public class Average extends Applet
{
Student wanghong,lihong;
public void init()
{
wanghong=new Student();
lihong=new Student();
wanghong.math=60.0f;
wanghong.english=80f;
lihong.math=70.0f;
lihong.english=90.0f;
wanghong.sum=wanghong.f(2.0f,2.0f);
lihong.sum=lihong.f(2.0f,2.0f);
}
public void paint(Graphics g)
{
g.drawString("lihong sum= "+lihong.sum,12,45);
g.drawString("wanghong sum=" +wanghong.sum,12,60);
}
}
中文是这样的
import java.applet.*;
import java.awt.*;
class Father
{
private int money;
float weight,height;
String head;
String speak(String s)
{
return s;
}
}
class Son extends Father
{
String hand,foot;
}
public class Example4_6 extends Applet
{
Son boy;
public void init()
{
boy=new Son();
boy.weight=1.80f;
boy.height=120f;
boy.head="一个头";
boy.hand="两只手";
boy.foot="两只脚";
}
public void paint(Graphics g)
{
g.drawString(boy.speak("我是儿子"),5,20);
g.drawString(boy.hand+boy.foot+boy.head+boy.weight+boy.height,5,40);
}
}
这两个程序我在编的机器上一样的操作,运行没有问题
谢谢了,用得的方法可以显示,但是为什么在ie里面不行呢???如果问题解决了一定高分相送
其实最简单的是设置
java Application 中所有的控件的字体为宋体,字体大小为12
祝你好运!----------------------
我相信我会成功!
你下载了插件吗?(jre1.4)
我不是高手。
/*用于内码转换的两个方法*/
public static String GBToUnicode(String strIn)
{
String strOut = null;
if(strIn == null||(strIn.trim().equals("")))
{
return strIn;
}
try{
byte[] b = strIn.getBytes("ISO8859_1");
strOut = new String(b,"GBK");
}catch(Exception ee){ }
return strOut;
} public static String UnicodeToGB(String strIn)
{
byte[] b;
String strOut = null;
if(strIn == null||(strIn.trim().equals("")))
{
return strIn;
}
try{
b = strIn.getBytes("GBK");
strOut = new String(b,"ISO8859_1");
}catch(Exception ee){ }
return strOut;
}
import java.io.Serializable;
import java.util.*;// Referenced classes of package com.optel.telemaster.util:
// LIException, Statuspublic class EnumType
implements Serializable
{ public EnumType()
{
code = 0;
} public EnumType(int value)
{
code = value;
} public int getIntValue()
{
return code;
} public Status setIntCode(int value)
throws LIException
{
if(!isValidCode(value))
{
throw new LIException(new Status(10002));
} else
{
code = value;
return new Status(1);
}
} public String getStringValue()
throws LIException
{
String ret;
try
{
ResourceBundle messages = getDefaultResourceBundle();
String str = Integer.toString(code);
ret = messages.getString(str);
}
catch(MissingResourceException ex)
{
throw new LIException(new Status(10003), ex);
}
return ret;
} public Status setStringValue(String str)
throws LIException
{
int index = getIndex(str);
if(index == 0x80000000)
{
throw new LIException(new Status(10002));
} else
{
code = index;
return new Status(1);
}
} protected int[] getValidCode()
{
int temp[] = {
1, 2, 3, 4
};
return temp;
} public boolean isValidCode(int value)
{
int validCodeArray[] = getValidCode();
for(int i = 0; i < validCodeArray.length; i++)
if(value == validCodeArray[i])
return true; return false;
} public boolean isValidString(String str)
throws LIException
{
int index = 0;
return getIndex(str) != 0x80000000;
} public String getStringValue(Locale locale)
throws LIException
{
String ret;
try
{
ResourceBundle messages = getResourceBundle(locale);
String str = getStringValue();
ret = messages.getString(str);
}
catch(MissingResourceException e)
{
throw new LIException(new Status(10005), e);
}
return ret;
} public String getStringValue(int value)
throws LIException
{
String ret;
try
{
ResourceBundle messages = getDefaultResourceBundle();
ret = messages.getString(Integer.toString(value));
}
catch(MissingResourceException ex)
{
throw new LIException(new Status(10003), ex);
}
return ret;
} public String getStringValue(int value, Locale locale)
throws LIException
{
String str = getStringValue(value);
String ret = getStringValue(str, locale);
return ret;
} public String getStringValue(String str, Locale locale)
throws LIException
{
String ret;
try
{
ResourceBundle messages = getResourceBundle(locale);
ret = messages.getString(str);
}
catch(MissingResourceException ex)
{
throw new LIException(new Status(10005), ex);
}
return ret;
} private ResourceBundle getDefaultResourceBundle()
throws LIException
{
return getResourceBundle(new Locale("zh", "CN"));
} private ResourceBundle getResourceBundle(Locale locale)
throws LIException
{
String className = getClassName();
ResourceBundle messages;
try
{
messages = ResourceBundle.getBundle(className, locale);
}
catch(MissingResourceException e)
{
throw new LIException(new Status(10004), e);
}
return messages;
} private int getIndex(String str)
throws LIException
{
int index = 0x80000000;
try
{
ResourceBundle messages = getDefaultResourceBundle();
for(Enumeration enum = messages.getKeys(); enum.hasMoreElements();)
{
String key = (String)enum.nextElement();
String value = messages.getString(key);
if(str.compareToIgnoreCase(value) == 0)
{
index = Integer.parseInt(key);
return index;
}
} }
catch(MissingResourceException e)
{
throw new LIException(new Status(10003), e);
}
return index;
} private String getClassName()
{
String className = getClass().getName();
int pos = className.lastIndexOf(".");
String name = className.substring(pos + 1);
return name;
} private int code;
}