Hi Experts
Using Eclipse and getting this error Syntax error on token "(", ; expected on line 59 it's the one with the main method on it.
It is saying something about the brackets not being right, i have tried commenting out lines and retyping the main method cannot seem to find whats wrong?
Any help will be greatly appriciated.
Code follows
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class PanelTest {
static Unit[] lengthArr = new Unit[11];
lengthArr[0] = new Unit("Centimeter", 100.0);
lengthArr[1] = new Unit("Feet", 3.280839895);
lengthArr[2] = new Unit("Inch", 39.37007874);
lengthArr[3] = new Unit("Kilometer", 0.001);
lengthArr[4] = new Unit("League", 0.000207123);
lengthArr[5] = new Unit("League(Nautical)", 1.0);
lengthArr[6] = new Unit("Meter", 1.0);
lengthArr[7] = new Unit("Microinch", 39370078.740157485);
lengthArr[8] = new Unit("Mile", 0.000621371);
lengthArr[9] = new Unit("Millimeter", 1000.0);
lengthArr[10] = new Unit("Yard", 1.093613298);
static JFrame myFrame = new JFrame("Test");
static JPanel container = new JPanel();
static JPanel LengthPane = new JPanel(new GridBagLayout());
static JPanel LiquidPane = new JPanel(new GridBagLayout());
static JPanel MassPane = new JPanel(new GridBagLayout());
static JPanel TempPane = new JPanel(new GridBagLayout());
static JButton convert = new JButton("Convert");
static JMenuBar menu1 = new JMenuBar();
static JMenu file = new JMenu("File");
static JMenu conversion = new JMenu("Conversion");
static JMenuItem exit = new JMenuItem("Exit");
static JMenuItem length = new JMenuItem("Length");
static JMenuItem liquid = new JMenuItem("Liquid");
static JMenuItem mass = new JMenuItem("Mass");
static JMenuItem temp = new JMenuItem("Temperature");
static JComboBox fromBox = new JComboBox(lengthArr);
static JComboBox toBox = new JComboBox(lengthArr);
static JTextField value = new JTextField(10);
public static void main(String[] args) {
// TODO Auto-generated method stub
ActionListener buttonListener = new MyListener(){
public void actionPerformed(ActionEvent e){
}
};
ActionListener menuListener = new MyListener(){
public void actionPerformed(ActionEvent e){
if(e.getActionCommand().equals("Length")){
container.removeAll();
container.add(LengthPane);
container.revalidate();
}
else if(e.getActionCommand().equals("Liquid")){
container.removeAll();
container.add(LiquidPane);
container.revalidate();
}
else if(e.getActionCommand().equals("Mass")){
container.removeAll();
container.add(MassPane);
container.revalidate();
}
else if(e.getActionCommand().equals("Temperature")){
container.removeAll();
container.add(TempPane);
container.revalidate();
}
}
};
//Menu bar ActionListeners
liquid.addActionListener(menuListener);
exit.addActionListener(menuListener);
length.addActionListener(menuListener);
mass.addActionListener(menuListener);
temp.addActionListener(menuListener);
//Length panel build
MyGrid.addItem(LengthPane, value,0,10,1,1,GridBagConstraints.WEST);
MyGrid.addItem(LengthPane, fromBox,0,12,1,1,GridBagConstraints.WEST);
MyGrid.addItem(LengthPane, toBox,0,14,1,1,GridBagConstraints.WEST);
container.add(LengthPane);
menu1.add(file);
menu1.add(conversion);
file.add(exit);
conversion.add(length);
conversion.add(liquid);
conversion.add(mass);
conversion.add(temp);
myFrame.setJMenuBar(menu1);
myFrame.setContentPane(container);
myFrame.setSize(300,400);
myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
myFrame.pack();
myFrame.setVisible(true);
}
}
}
Thanks
by: CEHJPosted on 2007-02-07 at 13:47:55ID: 18488984
Make PanelTest implement ActionListener and move this code inside the class
t e){ uals("Leng th")){ uals("Liqu id")){ uals("Mass ")){ uals("Temp erature")) {
public void actionPerformed(ActionEven
if(e.getActionCommand().eq
container.removeAll();
container.add(LengthPane);
container.revalidate();
}
else if(e.getActionCommand().eq
container.removeAll();
container.add(LiquidPane);
container.revalidate();
}
else if(e.getActionCommand().eq
container.removeAll();
container.add(MassPane);
container.revalidate();
}
else if(e.getActionCommand().eq
container.removeAll();
container.add(TempPane);
container.revalidate();
}
}
(Get rid of it elsewhere)