Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy do I keep getting an error in this Java Code?
    text
    copied!<p>I'm writing a program that lets the user select a type of currency, then when they enter in the number and click the 'convert button' the conversion is displayed in a text box. But I keep getting an error on line 36 that says 'class or interface expected public void init ()'</p> <pre><code>import java.applet.*; import java.awt.*; import java.awt.event.*; public class CurrencyConversionApplet implements ActionListener, ItemListener { // Variables double dollars, pounds, euros, ruble, price; Image dollarSign; Label lblTitle = new Label ("Enter the dollar amount (do not use commas or dollar signs): "); Label lblOutput = new Label (" "); TextField txtDollar = new TextField(10); Button convButton = new Button("Convert"); CheckboxGroup chkGroup = new CheckboxGroup(); Checkbox chkPounds = new Checkbox("British Pounds",false,chkGroup); Checkbox chkEuro = new Checkbox("Euros",false,chkGroup); Checkbox chkRuble = new Checkbox("Russian Ruble",false,chkGroup); Checkbox hiddenBox = new Checkbox("",true,chkGroup); Image dollarSign; } public void init() { add(lblTitle); add(txtDollar); add(convButton); add(chkPounds); add(chkEuro); add(chkRuble); chkPounds.addItemListener(this); chkEuro.addItemListener(this); chkRuble.addItemListener(this); dollarSign=getImage(getDocumentBase(), "dollar.jpg"); setBackground(Color.blue); setForeground(Color.yellow); convButton.addActionListener(this); } public void paint(Graphics g) { g.drawImage(dollarSign, 0, 28, this); } public void itemStateChanged(ItemEvent choice) { dollars = Double.parseDouble(txtDollar.getText()); pounds = dollars * .62 euros = dollars * .71 ruble = dollars * .03 if(chkPounds.getState()) price = pounds; if(chkEuro.getState()) price = euros; if(chkRuble.getState()) price = ruble; } public void actionPerformed(ActionEvent e) { lblOutput.setText(Double.toString(price)); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload