Hi everybody,
I am new at GUI and I need your help..
I have a JPanel, named "holdAll", layout of which is set to BorderLayout. I have implemented all other JPanels in different class files. For example, I have TopPanel, LeftPanel, etc. as shown below
LeftPanel myLeft = new LeftPanel();
holdAll.add(myLeft, BorderLayout.WEST);
RightPanel myRight = new RightPanel();
holdAll.add(myRight, BorderLayout.EAST);
TopPanel myTop = new TopPanel();
holdAll.add(myTop, BorderLayout.NORTH);
MiddlePanel myMiddle = new MiddlePanel();
holdAll.add(myMiddle, BorderLayout.CENTER);
BottomPanel myBottom = new BottomPanel();
holdAll.add(myBottom, BorderLayout.SOUTH);
That works well but I have difficulties in ActionListeners.. For example, in my TopPanel class I have the code below:
public void actionPerformed(ActionEvent e) {
if (e.getSource() == btnInsert) {
int returnVal = fc.showOpenDialog(fc);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
myImage newImage = new myImage(file);
System.out.println(newImage.myHashCode());
}
}
}
Here, if I have upload new image, then I have to update the listImage in the LeftPanel class.. But, I could not access the lstImage object in the LeftPanel class from the actionListener event in the TopPanel class.
What should I do? Is my design poor?