fork download
  1. import java.awt.Container;
  2. import java.awt.FlowLayout;
  3. import java.awt.event.ActionEvent;
  4. import java.awt.event.ActionListener;
  5.  
  6. import javax.swing.JButton;
  7. import javax.swing.JFrame;
  8. import javax.swing.JOptionPane;
  9. import javax.swing.JPanel;
  10.  
  11. public class Odd4 extends JFrame implements ActionListener {
  12.  
  13. private JButton button;
  14. private JPanel panel;
  15.  
  16. public static void main(final String [] args) {
  17. final Odd4 frame = new Odd4();
  18. frame.setSize(100, 100);
  19. frame.createLine();
  20. frame.show();
  21. }
  22.  
  23. private void createLine() {
  24. setDefaultCloseOperation(EXIT_ON_CLOSE);
  25. final Container window=getContentPane();
  26. window.setLayout (new FlowLayout());
  27.  
  28. this.button = new JButton("OK");
  29. window.add(this.button);
  30. this.button.addActionListener(this);
  31. }
  32.  
  33. public void actionPerformed(final ActionEvent event) {
  34. int n;
  35. final String nString = JOptionPane.showInputDialog("n:");
  36. n = Integer.parseInt(nString);
  37.  
  38. long total = 0;
  39. long term = 1;
  40. int i = 0;
  41. while( term < n ) {
  42. term += (2*i);
  43. total += term;
  44. i++;
  45. System.out.println("Term " + i + " is " + term);
  46. System.out.println("Current Total is " + total);
  47. }
  48.  
  49. JOptionPane.showMessageDialog(null, "Total is: " + total);
  50. }
  51. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:11: error: class Odd4 is public, should be declared in a file named Odd4.java
public class Odd4 extends JFrame implements ActionListener {
       ^
Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
1 error
stdout
Standard output is empty