Im making a program that outputs, the numbers 1-10 in one column, the square of this in another and in the third the number in cube.
How can i make the program a little nicer so the columns really differ.
And for every column i like to add a Title(Number, number squared, number cube).
//Sorry for my bad English
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("
").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();}
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…