import java.applet.*;
import java.awt.*;
public class Myapplet extends Applet{
public void paint(Graphics g){
int row,col;
String output="";
for(row=1;row <10;row++){
for(col=1;col <=row;col++)
output+=col+"*"+row+"="+(row*col)+" ";
output+="\n";
}
g.drawString(output,3,34);
}
}
小程序启动后只显示:
1*1=1 1*2=2 2*2=4....................
怎么实现: 1*1=1
1*2=2 2*2=4
1*3=3.......这样啊!!!
------解决方案--------------------
试一下output+="\r\n";
------解决方案--------------------
没什么变化啊!
------解决方案--------------------
//9*9表啊 呵呵
import java.applet.*;
import java.awt.*;
public class Myapplet extends Applet{
javax.swing.JTextArea jta=null;
public void init()
{
this.setLayout(new BorderLayout());
jta=new javax.swing.JTextArea();
this.add(jta);
}
public void paint(Graphics g){
jta.setText("");
int row,col;
String output="";
for(row=1;row <10;row++){
for(col=1;col <=row;col++)
output+=col+"*"+row+"="+(row*col)+" ";
output+="\n";
}
jta.append(output);
}
}
------解决方案--------------------
import java.applet.*;
import java.awt.*;
public class Myapplet extends Applet{
public void paint(Graphics g){
int row,col;
String output="";
for(row=1;row <10;row++){
for(col=1;col <=row;col++)
output+=col+"*"+row+"="+(row*col)+" ";
output+="\n";
g.drawString(output,3,34+i*10);
}
}
}
------解决方案--------------------
JTextArea 支持html,所以可以\n
如果不想用JTextArea ,下面的代码:
-----------------------------
import java.applet.*;
import java.awt.*;
public class MyApplet extends Applet {
public void paint(Graphics g) {
int row, col;
String output = "";
for (row = 1; row < 10; row++) {
for (col = 1; col <= row; col++) {
output += col + "*" + row + "=" + (row * col) + " ";
}
g.drawString(output, 10, row * 10);
output = "";
}
}
}
------解决方案--------------------
我想问下,我也是照三楼的做的,执行时,没结果啊,只打出一行字,帮帮我啊
exception in thread "main"java.langNoSuchMethodError:main