File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Applets and the fly likes Getting Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Applets
Bookmark "Getting "Type expected" when trying to compile applet" Watch "Getting "Type expected" when trying to compile applet" New topic
Author

Getting "Type expected" when trying to compile applet

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
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

Joined: Jul 30, 2002
Posts: 1
you have two '}' after 'if'. Delete one.
Also there are some other problems with the code. You can correct them.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Getting "Type expected" when trying to compile applet