import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class Odd4 extends JFrame implements ActionListener {

	private JButton button;
	private JPanel panel;

	public static void main(final String [] args) {
		final Odd4 frame = new Odd4();
		frame.setSize(100, 100);
		frame.createLine();
		frame.show();
	}

	private void createLine() {
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		final Container window=getContentPane();
		window.setLayout (new FlowLayout());

		this.button = new JButton("OK");
		window.add(this.button);
		this.button.addActionListener(this);
	}

	public void actionPerformed(final ActionEvent event) {
		int n;
		final String nString = JOptionPane.showInputDialog("n:");
		n = Integer.parseInt(nString);

		long total = 0;
		long term = 1;
		int i = 0;
		while( term < n ) {
			term += (2*i);
			total += term;
			i++;
			System.out.println("Term " + i + " is " + term);
			System.out.println("Current Total is " + total);
		}

		JOptionPane.showMessageDialog(null, "Total is: " + total);
	}
}