You don't have a main() method (which may be intentional).
You did not define messageLabel to be of type JLabel.
You did not instantiate mileageLabel.
import javax.swing.*;
import java.awt.event.*;
public class KiloConvertorWindow extends JFrame
{
private JPanel panel;
private JLabel messageLabel;
private JLabel mileageLabel;
private JTextField kiloTextField;
private JTextField milesTextField;
private JButton calcButton;
private final int WINDOW_WIDTH = 370;
private final int WINDOW_HEIGHT = 150;
public KiloConvertorWindow()
{
setTitle("Kilometer Convertor");
setSize( WINDOW_WIDTH, WINDOW_HEIGHT );
setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
buildPanel();
add(panel);
setVisible( true );
}
public static void main(String[]a){new KiloConvertorWindow();}
public void buildPanel()
{
messageLabel = new JLabel( "Enter a distance in Kilometers:");
mileageLabel = new JLabel("km");
kiloTextField = new JTextField( 10 );
milesTextField = new JTextField( "The Miles are: ");
calcButton = new JButton( "Calculate");
milesTextField.setEditable( false );
calcButton.addActionListener( new CalcButtonListener());
panel = new JPanel();
panel.add( messageLabel );
panel.add( kiloTextField );
panel.add( mileageLabel );
panel.add( milesTextField );
panel.add( calcButton );
}
private class CalcButtonListener implements ActionListener
{
public void actionPerformed( ActionEvent evt )
{
String input;
double miles;
input = kiloTextField.getText();
miles = Double.parseDouble( input ) * .06214;
milesTextField.setText( Double.toString( miles ));
JOptionPane.showMessageDialog( null, input + " Kilometers is: " +
miles + " Miles.");
}
}
}
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68:





by: AgentC4Posted on 2009-08-13 at 15:35:24ID: 25093719
sorry, here is the error message:
0: incompatible types
KiloConvertorWindow.java:3
found : javax.swing.JLabel
required: javax.swing.JPanel
messageLabel = new JLabel( "Enter a distance in Kilometers:");
^