我有两个错误:
C:\Users\anderson\Documents\FlopstoGFlopsConverter1.java:80: error: cannot find symbol
long flops = Long.parseLong(this.textField1.getText());
^
symbol: variable textField1
C:\Users\anderson\Documents\FlopstoGFlopsConverter1.java:85: error: cannot find symbol
this.textField2.setText(String.valueOf(gFlops));
^
symbol: variable textField2
2 errors
学习太难了。
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
public class FlopstoGFlopsConverter1 extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;
FlopstoGFlopsConverter1() {
setSize(500, 350);
setVisible(true);
JButton button1 = new JButton("Convert!");
button1.addActionListener(this);
JPanel panel = new JPanel();
panel.add(button1);
panel.setLayout(null);
this.add(panel);
button1.setBounds(190, 230, 100, 30);
JLabel label1 = new JLabel("Enter Flops");
panel.add(label1);
this.add(panel);
label1.setBounds(89, 52, 150, 50);
JTextField textArea1 = new JTextField(20);
JPanel p = new JPanel();
panel.add(textArea1);
this.add(panel);
textArea1.setBounds(160, 69, 160, 20);
JTextField textArea2 = new JTextField(20);
panel.add(textArea2);
this.add(panel);
textArea2.setBounds(159, 155, 160, 20);
JLabel label2 = new JLabel("Gigaflops ");
panel.add(label2);
this.add(panel);
label2.setBounds(91, 150, 200, 30);
}
public static void main(String[]args) {
new FlopstoGFlopsConverter1();
}
public void actionPerformed(ActionEvent e) {
System.out.println("");
try {
long flops = Long.parseLong(this.textField1.getText());
double gFlops = flops/1000000000;
this.textField2.setText(String.valueOf(gFlops));
} catch(Exception exception) {
}
}
}