Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

access from inner class  RSS feed

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);
class drawChart extends JPanel(){
setTableWidth(int w){...}
class settingChart extends JPanel(){
drawChart chart;
pubic settingChart(drawChart c){
JTextField width = new JTextField("9",4);
JButton change = new JButton("Change");
change.addActionListener(new changeHandle(chart));
change.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent event){
int w = (int)Double.parseDouble(width.getText());

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!