刚学,虽然简单,但也想了很久,请指教。/*
<HTML>
<HEAD>
<TITLE>我的算术题</TITLE>
</HEAD> <BODY>
<APPLET code=MyApplet2.class width=600 height=1200>
</APPLET>
</BODY>
</HTML>
*/import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.JApplet;
import java.applet.*;public class MyApplet2 extends JApplet { JPanel MainPanel=new JPanel();
int a,b;
int d=20;
boolean boo=true;
Font ft1=new Font("新宋体",Font.PLAIN,18);
public void init(){
add(MainPanel);
MainPanel.setBackground(Color.white);
MainPanel.setLayout(new GridLayout(29,4));
for(int i=0;i<29;i++){
for(int j=0;j<4;j++){
JLabel jbl=new JLabel();
MainPanel.add(jbl);
jbl.setFont(ft1);
Random rnd=new Random();
a=rnd.nextInt(d)+1;
b=rnd.nextInt(d)+1;
if(boo==true){
if(a>=b){
jbl.setText(a+"-"+b+"=");
boo=false;
this.repaint();
}else if(a<b){
jbl.setText(b+"-"+a+"=");
boo=false;
this.repaint();
}
}else if(boo==false){
jbl.setText(b+"+"+a+"=");
boo=true;
this.repaint();
}
}
}
this.setContentPane(MainPanel);
}
}
<HTML>
<HEAD>
<TITLE>我的算术题</TITLE>
</HEAD> <BODY>
<APPLET code=MyApplet2.class width=600 height=1200>
</APPLET>
</BODY>
</HTML>
*/import java.awt.event.*;
import java.awt.*;
import javax.swing.event.*;
import javax.swing.*;
import java.util.*;
import javax.swing.JApplet;
import java.applet.*;public class MyApplet2 extends JApplet { JPanel MainPanel=new JPanel();
int a,b;
int d=20;
boolean boo=true;
Font ft1=new Font("新宋体",Font.PLAIN,18);
public void init(){
add(MainPanel);
MainPanel.setBackground(Color.white);
MainPanel.setLayout(new GridLayout(29,4));
for(int i=0;i<29;i++){
for(int j=0;j<4;j++){
JLabel jbl=new JLabel();
MainPanel.add(jbl);
jbl.setFont(ft1);
Random rnd=new Random();
a=rnd.nextInt(d)+1;
b=rnd.nextInt(d)+1;
if(boo==true){
if(a>=b){
jbl.setText(a+"-"+b+"=");
boo=false;
this.repaint();
}else if(a<b){
jbl.setText(b+"-"+a+"=");
boo=false;
this.repaint();
}
}else if(boo==false){
jbl.setText(b+"+"+a+"=");
boo=true;
this.repaint();
}
}
}
this.setContentPane(MainPanel);
}
}
/*
<APPLET code=MyApplet2.class width=600 height=1200>
*/
这一句啦,编辑过程为javac 类名,
之后,用appletviewer 类名.class(也许不用加.class,你试一下,我好久没有玩过啦,不是appletviewer 类名.class 就是用appletviewer 类名,这两种形式进行编辑啦!)
即可