程序不能执行..请各位大侠帮忙看下,.
本来程序应该是,输入 华氏温度 和 风速 ,就可以得出风寒指数...
package windchill;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;public class Windchill implements ActionListener{
private static final int WINDOW_WIDTH = 350;
private static final int WINDOW_HEIGHT = 285;
private static final int FIELD_WIDTH = 20;
private static final int AREA_WIDTH = 40;

private static final FlowLayout LAYOUT_STYLE = new FlowLayout();
private static final String LEGEND = "This windchill " + "Calculator is intended for elocities greater than 4 mph.";
//window of GUI
private JFrame window = new JFrame("WindChill Calculator");
//legend
private JTextArea legendarea = new JTextArea(LEGEND,2,AREA_WIDTH);

//user entry area for temperature
private JLabel fahrTag = new JLabel("Fahrenheit temperature");
private JTextField fahrtext = new JTextField(FIELD_WIDTH);

//user entry area for windspeed
private JLabel windTag = new JLabel("    WindSpeed(mph)");
private JTextField windText = new JTextField(FIELD_WIDTH);

//entry area for windchill result
private JLabel chillTag = new JLabel(" WindChill Temperature");
private JTextField chillText = new JTextField(FIELD_WIDTH);

//run button
private JButton runButton = new JButton("Run");
public Windchill(){
window.setSize(WINDOW_WIDTH,WINDOW_HEIGHT);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

legendarea.setEditable(false);
legendarea.setLineWrap(true);
legendarea.setWrapStyleWord(true);
legendarea.setBackground(window.getBackground());

chillText.setEditable(false);
chillText.setBackground(Color.WHITE);

Container c = window.getContentPane();
c.setLayout(LAYOUT_STYLE);

c.add(legendarea);
c.add(fahrTag);
c.add(fahrtext);
c.add(windTag);
c.add(windText);
c.add(chillTag);
c.add(chillText);
c.add(runButton);

window.setVisible(true);
}

public void actionPerformed(ActionEvent e){
String response1 = fahrtext.getText();
double t = Double.parseDouble(response1);
String response2 = windText.getText();
double v = Double.parseDouble(response2);

double windchillTemperature = 0.081*(t-91.4)*(3.71*Math.sqrt(v)+5.81-0.25*v)+91.4;
int perceivedTemperature = (int)Math.round(windchillTemperature);

String output = String.valueOf(perceivedTemperature);
chillText.setText(output);
} public static void main(String[] args) {
// TODO Auto-generated method stub
Windchill gui1 = new Windchill();
}
}

解决方案 »

  1.   

    window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    runButton.addActionListener(this);
      

  2.   

    window.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
    window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    runButton.addActionListener(this);
      

  3.   

    在public Windchill(){ }里
    加上这一句:runButton.addActionListener(this);