• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting "Type expected" when trying to compile applet

 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is my code:
< code starts here>
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TempConversion extends JApplet implements ActionListener {

// graphical user interface components
JLabel celLabel, fahLabel, convertLabel;
JTextField celsiusOne, fahrenheitTwo, conversion;
JButton convert;
// setup graphical user interface components
public void init()
{
Container c = getContentPane();
c.setLayout( new FlowLayout() );
celLabel= new JLabel( "Celsius" );
c.add(celLabel);
celsiusOne = new JTextField( 10 );
celsiusOne.setEditable( true );
c.add(celsiusOne);
fahLabel= new JLabel( "Fahrenheit" );
c.add( fahLabel);
fahrenheitTwo = new JTextField( 10 );
fahrenheitTwo.setEditable( true );
c.add(fahrenheitTwo);
convertLabel= new JLabel( "Conversion is" );
c.add( convertLabel);
conversion = new JTextField( 10 );
conversion.setEditable( false );
c.add(conversion);
convert = new JButton( "Convert Temperature" );
convert.addActionListener( this );
c.add( convert);
}
// call method convertTemp when button is pressed
public void actionPerformed( ActionEvent e )
{
convertTemp();
}
// process temperature conversion
public void convertTemp()
{
double celsius = 0, fahrenheit = 0;
double C = 0, F = 0;
//process celsius conversion here
if (getContentPane() == celsiusOne){
celsius = 5.0 / 9.0 * (F - 32);
celsiusOne.setText( Double.toString( celsius ) );
}
}
// process fahrenheit conversion here
else {
getContentPane() == fahrenheitTwo;
fahrenheit = 9.0 / 5.0 * C + 32;
fahrenheitTwo.setText( Double.toString( fahrenheit) );
}

return ;
<code ends here>
 
deb
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have two '}' after 'if'. Delete one.
Also there are some other problems with the code. You can correct them.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic