• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Getting "Type expected" when trying to compile applet

 
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>
 
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.
 
Do you pee on your compost? Does this tiny ad?
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic