我写了一个Applet小程序(用JBuilder5),运行正常,但是…… 应该是IE的支持问题,就是说你的程序里边用了jdk1.2以上才有的函数。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不会吧;我的代码:package testapp;import java.awt.*;import java.awt.event.*;import java.applet.*;public class Applet1 extends Applet { public void paint(Graphics g) { g.drawString("Hell",50,50); }} 你还没有了解package的概念把***.class和这个html文件放到同一目录底下,就要把前面的package testapp; 去掉,然后重新编译吧,一定可以的。否则就在该Html文件目录下建立一个testapp目录,再把class文件放到改目录下,applet参数做适当修改 按照楼上老兄的说法没有错误。但是我写的如下的代码,却不能作到,为什么呀?(惭愧):import java.awt.*;import java.awt.event.*;import java.applet.*;import javax.swing.*;import com.borland.jbcl.layout.*;public class fuNum extends Applet { boolean isStandalone = false; XYLayout xYLayout1 = new XYLayout(); JButton jButton1 = new JButton(); JLabel jLabel1 = new JLabel(); JLabel jLabel2 = new JLabel(); JLabel jLabel3 = new JLabel(); JLabel jLabel4 = new JLabel(); JLabel jLabel5 = new JLabel(); JLabel jLabel6 = new JLabel(); JLabel jLabel7 = new JLabel(); JLabel jLabel8 = new JLabel(); JLabel jLabel9 = new JLabel(); JLabel jLabel10 = new JLabel(); JLabel jLabel11 = new JLabel(); JLabel jLabel12 = new JLabel(); /**Get a parameter value*/ public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } /**Construct the applet*/ public fuNum() { } /**Initialize the applet*/ public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } /**Component initialization*/ private void jbInit() throws Exception { this.setBackground(new Color(138, 184, 223)); this.setEnabled(true); this.setForeground(Color.lightGray); this.setLayout(xYLayout1); jButton1.setText("开始选号"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { jButton1_actionPerformed(e); } }); jLabel1.setForeground(Color.red); jLabel1.setText("第一组号码"); xYLayout1.setWidth(274); xYLayout1.setHeight(300); jLabel2.setForeground(Color.red); jLabel2.setText("第二组号码"); jLabel3.setForeground(Color.red); jLabel3.setText("第三组号码"); jLabel4.setForeground(Color.red); jLabel4.setText("第四组号码"); jLabel5.setForeground(Color.red); jLabel5.setText("第五组号码"); jLabel6.setForeground(Color.yellow); jLabel6.setText("XX XX XX XX XX XX XX"); jLabel7.setForeground(Color.yellow); jLabel7.setText("XX XX XX XX XX XX XX"); jLabel8.setForeground(Color.yellow); jLabel8.setText("XX XX XX XX XX XX XX"); jLabel9.setForeground(Color.yellow); jLabel9.setText("XX XX XX XX XX XX XX"); jLabel10.setForeground(Color.yellow); jLabel10.setText("XX XX XX XX XX XX XX"); jLabel11.setText("陕西风采福利彩票选号器"); jLabel12.setForeground(Color.white); jLabel12.setText("By oldseven"); this.add(jButton1, new XYConstraints(88, 233, 119, 25)); this.add(jLabel2, new XYConstraints(10, 71, 76, 16)); this.add(jLabel3, new XYConstraints(9, 99, 72, 19)); this.add(jLabel4, new XYConstraints(9, 130, 70, 14)); this.add(jLabel5, new XYConstraints(10, 158, 69, 17)); this.add(jLabel1, new XYConstraints(9, 37, 74, 20)); this.add(jLabel6, new XYConstraints(94, 38, 216, 19)); this.add(jLabel10, new XYConstraints(92, 158, 217, -1)); this.add(jLabel9, new XYConstraints(92, 129, 218, 16)); this.add(jLabel8, new XYConstraints(92, 97, 220, 17)); this.add(jLabel7, new XYConstraints(93, 67, 219, 19)); this.add(jLabel11, new XYConstraints(72, 13, 142, 15)); this.add(jLabel12, new XYConstraints(201, 199, 89, 17)); } /**Get Applet information*/ public String getAppletInfo() { return "Applet Information"; } /**Get parameter info*/ public String[][] getParameterInfo() { return null; } void jButton1_actionPerformed(ActionEvent e) { RandomHaoMa HMGet=new RandomHaoMa(); int[][] HM =new int[5][7]; String Temps; int i; Temps=""; HM=HMGet.GetNumber(); for(i=0;i<7;i++) { Temps =Temps+" "+String.valueOf(HM[0][i]); } jLabel6.setText(Temps); Temps=""; for(i=0;i<7;i++) { Temps =Temps+" "+String.valueOf(HM[1][i]); } jLabel7.setText(Temps); Temps=""; for(i=0;i<7;i++) { Temps =Temps+" "+String.valueOf(HM[2][i]); } jLabel8.setText(Temps); Temps=""; for(i=0;i<7;i++) { Temps =Temps+" "+String.valueOf(HM[3][i]); } jLabel9.setText(Temps); Temps=""; for(i=0;i<7;i++) { Temps =Temps+" "+String.valueOf(HM[4][i]); } jLabel10.setText(Temps); }}class Rom{ public int RandomInt(int BeginNum,int EndNum) { double Dou; int Rom1; if (BeginNum==50){ Rom1 = 4; } Dou =Math.random(); Rom1 =(int)(Dou*(EndNum-BeginNum))+BeginNum; return Rom1; }} class RandomHaoMa { public static final int GroupNumber = 5; public static final int HaoMaNumber = 7; public static final int BeginNum = 1; public static final int EndNum = 33; public RandomHaoMa() { int i,j,k; int TempRom; Rom rom = new Rom(); for(i=0;i<GroupNumber;i++) { k=0; while(k<7) { boolean FindNum; TempRom = rom.RandomInt(BeginNum,EndNum); FindNum = false; for(j=0;j<k;j++) { if (TempRom==HaoMa[i][j]) { FindNum = true; break; } } if(!FindNum) { HaoMa[i][k] = TempRom; k++; } } } // end i //排序 for(i=0;i<GroupNumber;i++) { sort(HaoMa[i]); } } //对一个整形数组进行排序 public int[] sort(int[] RomArray) { int i,j; for(i=0;i<6;i++) { for(j=i+1;j<7;j++) { if(RomArray[i]>RomArray[j]) { int t = RomArray[i]; RomArray[i] = RomArray[j]; RomArray[j] = t; } } } return RomArray; } public int[][] GetNumber(){ return HaoMa; } private int[][] HaoMa = new int[GroupNumber][HaoMaNumber];}而且,在JBuilder5环境下能正常显示。 参照一楼所有SWING都至少需要支持jdk1.2的JRE来解释运行 java网页抓取 如何才能写出执行效率高的代码? Java连接SQL Server 2005 JDBC问题,一个奇怪的问题 我也想玩JAVA,但。。。 这个程序在编译的时候,为什么会有这样的报错信息? 使用UltraEdit的心得 做j2eetutorial1.3的例子总是出现这样的错误,大家帮帮忙啊! 谁有UltraEdit的注册号?俺的版本是9.20 JDBC 的错误请教 skyyoung:刚才个问题还没解决(requestFocus) 关于classpath设置的问题
我的代码:
package testapp;import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class Applet1 extends Applet { public void paint(Graphics g)
{
g.drawString("Hell",50,50);
}
}
否则就在该Html文件目录下建立一个testapp目录,再把class文件放到改目录下,applet参数做适当修改
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;public class fuNum extends Applet {
boolean isStandalone = false;
XYLayout xYLayout1 = new XYLayout();
JButton jButton1 = new JButton();
JLabel jLabel1 = new JLabel();
JLabel jLabel2 = new JLabel();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
JLabel jLabel7 = new JLabel();
JLabel jLabel8 = new JLabel();
JLabel jLabel9 = new JLabel();
JLabel jLabel10 = new JLabel();
JLabel jLabel11 = new JLabel();
JLabel jLabel12 = new JLabel();
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
} /**Construct the applet*/
public fuNum() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
this.setBackground(new Color(138, 184, 223));
this.setEnabled(true);
this.setForeground(Color.lightGray);
this.setLayout(xYLayout1);
jButton1.setText("开始选号");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
jLabel1.setForeground(Color.red);
jLabel1.setText("第一组号码");
xYLayout1.setWidth(274);
xYLayout1.setHeight(300);
jLabel2.setForeground(Color.red);
jLabel2.setText("第二组号码");
jLabel3.setForeground(Color.red);
jLabel3.setText("第三组号码");
jLabel4.setForeground(Color.red);
jLabel4.setText("第四组号码");
jLabel5.setForeground(Color.red);
jLabel5.setText("第五组号码"); jLabel6.setForeground(Color.yellow);
jLabel6.setText("XX XX XX XX XX XX XX"); jLabel7.setForeground(Color.yellow);
jLabel7.setText("XX XX XX XX XX XX XX"); jLabel8.setForeground(Color.yellow);
jLabel8.setText("XX XX XX XX XX XX XX"); jLabel9.setForeground(Color.yellow);
jLabel9.setText("XX XX XX XX XX XX XX"); jLabel10.setForeground(Color.yellow);
jLabel10.setText("XX XX XX XX XX XX XX");
jLabel11.setText("陕西风采福利彩票选号器");
jLabel12.setForeground(Color.white);
jLabel12.setText("By oldseven");
this.add(jButton1, new XYConstraints(88, 233, 119, 25));
this.add(jLabel2, new XYConstraints(10, 71, 76, 16));
this.add(jLabel3, new XYConstraints(9, 99, 72, 19));
this.add(jLabel4, new XYConstraints(9, 130, 70, 14));
this.add(jLabel5, new XYConstraints(10, 158, 69, 17));
this.add(jLabel1, new XYConstraints(9, 37, 74, 20));
this.add(jLabel6, new XYConstraints(94, 38, 216, 19));
this.add(jLabel10, new XYConstraints(92, 158, 217, -1));
this.add(jLabel9, new XYConstraints(92, 129, 218, 16));
this.add(jLabel8, new XYConstraints(92, 97, 220, 17));
this.add(jLabel7, new XYConstraints(93, 67, 219, 19));
this.add(jLabel11, new XYConstraints(72, 13, 142, 15));
this.add(jLabel12, new XYConstraints(201, 199, 89, 17));
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
} void jButton1_actionPerformed(ActionEvent e) {
RandomHaoMa HMGet=new RandomHaoMa();
int[][] HM =new int[5][7];
String Temps;
int i;
Temps="";
HM=HMGet.GetNumber();
for(i=0;i<7;i++)
{
Temps =Temps+" "+String.valueOf(HM[0][i]);
}
jLabel6.setText(Temps);
Temps="";
for(i=0;i<7;i++)
{
Temps =Temps+" "+String.valueOf(HM[1][i]);
}
jLabel7.setText(Temps);
Temps="";
for(i=0;i<7;i++)
{
Temps =Temps+" "+String.valueOf(HM[2][i]);
}
jLabel8.setText(Temps);
Temps="";
for(i=0;i<7;i++)
{
Temps =Temps+" "+String.valueOf(HM[3][i]);
}
jLabel9.setText(Temps);
Temps="";
for(i=0;i<7;i++)
{
Temps =Temps+" "+String.valueOf(HM[4][i]);
}
jLabel10.setText(Temps);
}
}
class Rom
{
public int RandomInt(int BeginNum,int EndNum)
{
double Dou;
int Rom1; if (BeginNum==50){
Rom1 = 4;
}
Dou =Math.random();
Rom1 =(int)(Dou*(EndNum-BeginNum))+BeginNum;
return Rom1;
}
}
class RandomHaoMa {
public static final int GroupNumber = 5;
public static final int HaoMaNumber = 7;
public static final int BeginNum = 1;
public static final int EndNum = 33; public RandomHaoMa() {
int i,j,k;
int TempRom;
Rom rom = new Rom(); for(i=0;i<GroupNumber;i++)
{
k=0;
while(k<7)
{
boolean FindNum;
TempRom = rom.RandomInt(BeginNum,EndNum); FindNum = false;
for(j=0;j<k;j++)
{
if (TempRom==HaoMa[i][j])
{
FindNum = true;
break;
}
}
if(!FindNum)
{
HaoMa[i][k] = TempRom;
k++;
}
} } // end i //排序
for(i=0;i<GroupNumber;i++)
{
sort(HaoMa[i]);
} } //对一个整形数组进行排序
public int[] sort(int[] RomArray)
{
int i,j;
for(i=0;i<6;i++)
{
for(j=i+1;j<7;j++)
{
if(RomArray[i]>RomArray[j])
{
int t = RomArray[i];
RomArray[i] = RomArray[j];
RomArray[j] = t;
} }
} return RomArray;
} public int[][] GetNumber(){
return HaoMa;
} private int[][] HaoMa = new int[GroupNumber][HaoMaNumber];
}
而且,在JBuilder5环境下能正常显示。
所有SWING都至少需要支持jdk1.2的JRE来解释运行