我的程序正在编译但没有运行

时间:2017-01-31 05:18:03

标签: java swing applet

import javax.swing.*;
import java.awt.event.*;
import java.text.DecimalFormat;

public class NewClass implements ActionListener {
    JButton cnv;
    JTextField f1;
    JTextField c1;
    JLabel f2;
    JLabel c2;

    public static void main(String[] args) {
        NewClass n = new NewClass();
        n.go();
        n.defc();
        n.deff();
    }

    public void go() {
        JFrame f = new JFrame("Converter");
        cnv = new JButton("Convert");
        cnv.addActionListener(this);
        f.setSize(300, 300);
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setVisible(true);
        f.add(f1);
        f.add(f2);
        f.add(c1);
        f.add(c2);
    }

    public void deff() {
        f1 = new JTextField(10);
        f2 = new JLabel("Farenhiet");
    }

    public void defc() {
        c1 = new JTextField(10);
        c2 = new JLabel("Celsius");
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        double ftmp,ctmp;
        DecimalFormat formatter = new DecimalFormat("0.0");
        ftmp = Double.parseDouble(f1.getText());
        ctmp = (5.0 / 9.0) * (ftmp - 32);
        c1.setText(formatter.format(ctmp));
    }
}

0 个答案:

没有答案