回复 楼主 冰雪天
import javax.swing.*;
import java.awt.event.*;
import java.awt.Container;
import java.awt.*;
import java.text.*;
public class MyFirstTextArea extends JFrame{
private JFrame mainFrame;
private JTextArea outArea;
public MyFirstTextArea(){
mainFrame = new JFrame("example of a TextArea");
outArea = new JTextArea(10,28);
Container c = mainFrame.getContentPane();
c.setLayout(new FlowLayout());
c.add(outArea);
mainFrame.setSize(300,250);
mainFrame.addWindowListener(new WindowAdapter(){
//定义窗口关闭事件
public void windowClosing(WindowEvent e){System.exit(0);}
});
mainFrame.show();
}
public void createTable(){
int num;
DecimalFormat df = new DecimalFormat("0000");
//定义数据格式
outArea.setFont(new Font("Courier",Font.BOLD,10));
outArea.append("NUMBER
SQUARE
CUBE\n");
outArea.append("------
------
------\n");
outArea.setFont(new Font("Courier",Font.PLAIN,10));
for(num = 1;num < 11 ;num ++){
outArea.append("
" + df.format(num));
outArea.append("
" + df.format(num*num));
outArea.append("
" + df.format(num*num*num) + '\n');
}
return;
}
public static void main(String args[]){
MyFirstTextArea app;
app = new MyFirstTextArea();
app.createTable();
}
}