• Post Reply Bookmark Topic Watch Topic
  • New Topic

access from inner class

 
dejie lin
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,
I have one frame with two panels inside, code likes the following:
public class ShowChart extends JFrame{
.....
Container f = getContentPane();
f.setLayout(new BorderLayout());
JPanel chart=new drawChart();
JPanel setting=new settingChart(chart);
f.add(setting,java.awt.BorderLayout.WEST);
f.add(chart);
.....
}
class drawChart extends JPanel(){
.....
setTableWidth(int w){...}
.....
}
class settingChart extends JPanel(){
drawChart chart;
pubic settingChart(drawChart c){
chart=c;
JTextField width = new JTextField("9",4);
add(width);
.....
JButton change = new JButton("Change");
change.addActionListener(new changeHandle(chart));
add(change);
change.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent event){
int w = (int)Double.parseDouble(width.getText());

chart.setTableWidth(w);
}
});
}
}
Compilling error: local virable chart is accessed from within inner class, need to be declared as final. chart.setTabelWidth(w);
how can i deal with this problem? (i know it will be ok if i messy all the viriables and method of settingChart into the ShowChart class, but it seems not a nice way...)
thanks dejie
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!