2016-09-08 8 views
-5
import javax.swing.*; 
import java.awt.*; 
import java.awt.event.*; 
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 java.lang.*; 
import java.util.*; 
public class Life { 
public static void main (String[] args){ 
    JFrame frame = new JFrame("Interest Calculator"); 
    frame.setVisible(true); 
    frame.setSize(300,100); 
    frame.setBackground(Color.magenta); 
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 

    JPanel panel = new JPanel(); 
    frame.add(panel); 


    JButton button = new JButton("Simple Interest"); 
    panel.add(button); 
    button.addActionListener (new Action1()); 

    JButton button2 = new JButton("Compound Interest"); 
    panel.add(button2); 
    button2.addActionListener (new Action2()); 
} 
static class Action1 implements ActionListener {   
     public void actionPerformed (ActionEvent e) {  
    JFrame frame2 = new JFrame("Simple"); 
    frame2.setVisible(true); 
    frame2.setSize(300,100); 
    JPanel panel = new JPanel(); 
    frame2.add(panel); 

    JButton button = new JButton("Ordinary"); 
     panel.add(button); 
    button.addActionListener (new Ordinary()); 


    JButton button2 = new JButton("Exact"); 
    panel.add(button2);  
    button2.addActionListener (new Exact());  
    } 
} 
static class Action2 implements ActionListener {   
    public void actionPerformed (ActionEvent e) {  
    JFrame frame3 = new JFrame("Compound Interest"); 
    frame3.setVisible(true); 
    frame3.setSize(300,100); 

    JPanel panel = new JPanel(); 
    frame3.add(panel); 

    JButton button = new JButton("Compounded"); 
    panel.add(button); 

    JButton button2 = new JButton("Continously"); 
    panel.add(button2); 
    } 
} 
    static class Ordinary implements ActionListener { 
    public void actionPerformed (ActionEvent e) { 
    JFrame frame4 = new JFrame("Simple"); 
    frame4.setVisible(true); 
    frame4.setSize(300,100); 

    JPanel panel = new JPanel(); 
    frame4.add(panel); 

     JButton button = new JButton("Approximate"); 
    panel.add(button); 
    button.addActionListener (new Approximate()); 

    JButton button2 = new JButton("Actual"); 
    panel.add(button2); 
} 
} 
static class Exact implements ActionListener { 
public void actionPerformed (ActionEvent e) { 
JFrame frame5 = new JFrame("Exact"); 
frame5.setVisible(true); 
frame5.setSize(300,100); 

    JPanel panel = new JPanel(); 
    frame5.add(panel); 

    JButton button = new JButton("Approximate"); 
    panel.add(button); 



    JButton button2 = new JButton("Actual"); 
    panel.add(button2); 
} 
} 
static class Approximate implements ActionListener { 
public void actionPerformed (ActionEvent e) { 

JFrame frame6 = new JFrame("Simple"); 
frame6.setVisible(true); 
frame6.setSize(300,100); 
JPanel panel = new JPanel(); 
    frame6.add(panel); 
    frame6.setVisible(true); 
frame6.setSize(300,300); 
frame6.setLayout(null); 
frame6.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
JTextField P = new JTextField(); 
panel.add(P); 
P.setText("Enter Principal"); 
JTextField r = new JTextField(); 
panel.add(r); 
r.setText("Enter Rate"); 
JTextField t = new JTextField(); 
panel.add(t); 
t.setText("Enter Year"); 
JButton button = new JButton("Calculate"); 
panel.add(button); 
button.addActionListener (new button()); 
static class button implements ActionListener { 
    public void actionPerformed (ActionEvent e) { 

float P,r,t,result ; 
P = Float.parseFloat(P.getText()); 
r = Float.parseFloat(r.getText()); 
t = Float.parseFloat(t.getText()); 
result = P*r/100*t/360; 
button.setText(String.valueof(result)); 
} 
} 
} 
} 
} 

だから、これは化合物の電卓を作成するための私のコードですが、私はそれがexpression.pleaseの違法開始は私のプロジェクトのために私を助けているという問題があります。エラー:式の違法開始1つのエラー

+0

なぜあなたは "zzzzzzz"をスパムしましたか? – byxor

+2

彼はキーボードで眠りに落ちた;) – fabian

+0

私はあまりにも書かれたこのような問題を校正していたとしても私は眠りにつくだろう。 – byxor

答えて

0

以下は、問題の原因となるコードの一部を修正したものです。次回はフルエラーコードを含め、コードの関連部分のみを表示しようとします。

ActionListener listener = new ActionListener() { 
    public void actionPerformed (ActionEvent e) { 
     float P,r,t,result ; 
     //P = Float.parseFloat(P.getText()); // P makes no sens here - its float !!! and uninitialized 
     //r = Float.parseFloat(r.getText()); // same for r 
     //t = Float.parseFloat(t.getText()); // same for t 
     result = P*r/100*t/360; 
     button.setText(String.valueOf(result)); 
    } 
}; 
button.addActionListener (listener); 
関連する問題