Hi, I'm new to Java and still trying to get a handle on all this object oriented stuff but I would appreciate it if one of you guys could explain this;

Suppose I create a class which is a panel with a combobox on it. I create two instances of this class and add them to the content pane. I also add a panel with a JButton on it to the content pane.

I want to select a number from each combobox so that when I press the JButton the actionPerformed method adds the two numbers I selected.

My problem is the actionPerformed method seems to be a static method (is this true ?) as a result JBuilder keeps telling me "non-static variable cannot be referenced from a static context". Does this mean I can never use clicking a button to perform a job that involves manipulating instance variables belonging to an object, surely this can't be true.

Here is my code...




import java.awt.event.*;
import javax.swing.*;
import java.awt.*;


public class combo extends JFrame
{
public PanelWithCombo firstPanel = new PanelWithCombo();
public PanelWithCombo secondPanel = new PanelWithCombo();
private PanelWithButton buttonPanel = new PanelWithButton();
private JPanel MainPanel = new JPanel();

public static void main(String[] args)
{
new combo();
}

combo()
{
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setSize(600,200);
this.setLocationRelativeTo(null);
this.getContentPane().add(MainPanel);
MainPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 10,30));
MainPanel.add(firstPanel);
MainPanel.add(secondPanel);
MainPanel.add(buttonPanel);
this.setVisible(true);
}
}


class PanelWithCombo extends JPanel implements ItemListener
{
public int number;
private String[] contents = {"1","2","3"};
private JComboBox myCombo = new JComboBox(contents);


public PanelWithCombo()
{
myCombo.addItemListener(this);
this.add(myCombo);
}


public void itemStateChanged(ItemEvent e)
{
number = Integer.parseInt((String) myCombo.getSelectedItem());
}

public int getNumber()
{
return number;
}
}




class PanelWithButton extends JPanel implements ActionListener
{
private JButton btnGenerate = new JButton("Generate");

PanelWithButton()
{
this.add(btnGenerate);
btnGenerate.addActionListener(this);
}

public void actionPerformed(ActionEvent ex)
{
int sum = combo.firstPanel.getNumber() + combo.secondPanel.getNumber();
}
}



As I say I am new to object oriented programming and its quite possible that i have completely gone off on a tangent with this one but if anyone has any thoughts or suggestions I would really appreciate it.

Thanks