我正在制作一个程序,输出一列中的数字 1-10,另一列中的平方,第三列中的数字。
我怎样才能使程序更好一点,所以列真的不同。对于每一列,我喜欢添加一个标题(数字,数字平方,数字立方体)。
//对不起,我的英语不好
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Del2upp3 extends JFrame implements ActionListener
{
int i;
JLabel label2 = new JLabel();
JPanel panel = new JPanel();
JButton button = new JButton("Press");
Del2upp3()
{
super ("Panel"); setSize (200,300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container con = this.getContentPane();
con.add(panel);
button.addActionListener(this);
panel.add(label2);
panel.add(button);
setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
Object source = event.getSource();
if (source == button)
{
StringBuilder string = new StringBuilder();
for( i = 1; i< 11; i++){
string.append("\n ").append(i);
string.append(", ").append(i*i);
string.append(", ").append(i*i*i);
}
JOptionPane.showMessageDialog(null, string,"Data",
JOptionPane.PLAIN_MESSAGE);
setSize (200,200);
setVisible(true);
i = 0;
}}
public static void main(String[] args){new Del2upp3();}
}