代码是同学那拷的没问题,但是在my上就报这个错误
*
//package java_test6;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class ExRate {
public static void main(String[] args) {
JFrame f = new JFrame(); //窗口容器
f.setSize(200, 200);
JTextArea t1 = new JTextArea(1, 5);//指定行列
JTextArea t2 = new JTextArea(1, 5);
JButton b1 = new JButton("test it");
Label l1, l2;
l1 = new Label();
l2 = new Label();
l1.setText("Please Enter The Number");
l2.setText("The Result Of The Test");
Choice c = new Choice(); //这里需final
c.add("RMB");
c.add("Euro");
c.add("USA$");
Choice c1 = new Choice();
c1.add("RMB");
c1.add("Euro");
c1.add("USA$");
f.add(l1);
f.add(t1);
f.add(c);
f.add(l2);
f.add(t2);
f.add(c1);
f.add(b1);
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (c.getSelectedItem() == "RMB" && c1.getSelectedItem() == "USA$") {
String s;
s = t1.getText();
int q = 0;
q = Integer.parseInt(s);
double w;
w = q * 0.1506;
String r = Double.toString(w);
t2.setText(r);
} else if (c.getSelectedItem() == "USA$" && c1.getSelectedItem() == "RMB") {
String s;
s = t1.getText();
int q = 0;
q = Integer.parseInt(s);
double w;
w = q * 6.6391;
String r = Double.toString(w);
t2.setText(r);
} else if (c.getSelectedItem() == "RMB" && c1.getSelectedItem() == "Euro") {
String s;
s = t1.getText();
int q = 0;
q = Integer.parseInt(s);
double w;
w = q * 0.1297;
String r = Double.toString(w);
t2.setText(r);
} else if (c.getSelectedItem() == "Euro" && c1.getSelectedItem() == "RMB") {
String s;
s = t1.getText();
int q = 0;
q = Integer.parseInt(s);
double w;
w = q * 7.7107;
String r = Double.toString(w);
t2.setText(r);
} else if (c.getSelectedItem() == "USA$" && c1.getSelectedItem() == "Euro") {
String s;
s = t1.getText();
int q = 0;
q = Integer.parseInt(s);
double w;
w = q * 0.8610;
String r = Double.toString(w);
t2.setText(r);
} else if (c.getSelectedItem() == "Euro" && c1.getSelectedItem() == "USA$") {
String s;
s = t1.getText();
int q = 0;
q = Integer.parseInt(s);
double w;
w = q * 1.1614;
String r = Double.toString(w);
t2.setText(r);
}
}
});
f.setLayout(new FlowLayout());
f.setVisible(true);
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
}*
把完整代码贴出来看看,估计是你在匿名内部类里使用了非
final
变量...