Advertisement
Guest User

Untitled

a guest
Jul 27th, 2014
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. frame.setDefaultCloseOperation(JFrame.CLOSE_ON_EXIT);
  2.  
  3. Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous tree type: <any>
  4. at InvestmentFrame2.main(InvestmentFrame2.java:103)
  5.  
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JLabel;
  11. import javax.swing.JPanel;
  12. import javax.swing.JTextField;
  13.  
  14. public class InvestmentFrame2 extends JFrame
  15. {
  16. private static final int FRAME_WIDTH = 450;
  17. private static final int FRAME_HEIGHT = 250;
  18.  
  19. private static final double DEFAULT_RATE = 0;
  20. private static final double INITIAL_BALANCE = 0;
  21. private static final double YEARS = 0;
  22.  
  23. private JLabel rateLabel;
  24. private JLabel balanceLabel;
  25. private JLabel yearsLabel;
  26.  
  27. private JTextField rateField;
  28. private JTextField balanceField;
  29. private JTextField yearsField;
  30.  
  31. private JButton button;
  32.  
  33. private JLabel resultLabel;
  34. private double balance;
  35.  
  36. public InvestmentFrame2()
  37. {
  38. balance = INITIAL_BALANCE;
  39. resultLabel = new JLabel("Balance: " + balance);
  40.  
  41. createTextField();
  42. createButton();
  43. createPanel();
  44.  
  45. setSize(FRAME_WIDTH, FRAME_HEIGHT);
  46. }
  47.  
  48. private void createTextField()
  49. {
  50. rateLabel = new JLabel("Interest Rate: ");
  51. balanceLabel = new JLabel("Account Balance: ");
  52. yearsLabel = new JLabel("Number of Years Saving: ");
  53.  
  54. final int FIELD_WIDTH = 10;
  55.  
  56. rateField = new JTextField(FIELD_WIDTH);
  57. rateField.setText ("" + DEFAULT_RATE);
  58.  
  59. balanceField = new JTextField(FIELD_WIDTH);
  60. balanceField.setText("" + INITIAL_BALANCE);
  61.  
  62. yearsField = new JTextField(FIELD_WIDTH);
  63. yearsField.setText("" + YEARS);
  64. }
  65.  
  66. class AddInterestListener implements ActionListener
  67. {
  68. public void actionPerformed(ActionEvent event)
  69. {
  70. double rate = Double.parseDouble(rateField.getText());
  71. double accountBalance = Double.parseDouble(balanceField.getText());
  72. double years = Double.parseDouble(yearsField.getText());
  73. double interest = (accountBalance * rate / 100) * years;
  74. balance = accountBalance + interest;
  75. resultLabel.setText("Balance: " + balance);
  76. }
  77. }
  78.  
  79. private void createButton()
  80. {
  81. button = new JButton("Calculate Balance");
  82.  
  83. ActionListener listener = new AddInterestListener();
  84. button.addActionListener(listener);
  85. }
  86.  
  87. private void createPanel()
  88. {
  89. JPanel panel = new JPanel();
  90. panel.add(rateLabel);
  91. panel.add(rateField);
  92.  
  93. panel.add(balanceLabel);
  94. panel.add(balanceField);
  95.  
  96. panel.add(yearsLabel);
  97. panel.add(yearsField);
  98.  
  99. panel.add(button);
  100. panel.add(resultLabel);
  101. add(panel);
  102. }
  103.  
  104. public static void main(String[] args)
  105. {
  106. JFrame frame = new InvestmentFrame2();
  107. frame.setTitle("Savings Frame");
  108. frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_EXIT);
  109. frame.setVisible(true);
  110. }
  111. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement