There seems to be a misconception about what you want to do:
- You seem to want to call
Add()
on the MainWindow instance of your application - Your code tries to access the MainWindow class
To fix this, you need to hold a reference to your main window:
new MainWindow();
should beMainWindow myMainWindow=new MainWindow();
Light(int x, int y, int size) { MainWindow.win.Add(darea); }
should beLight(MainWindow theMainWindow, int x, int y, int size) { theMainWindow.win.Add(darea); }
- finally you need to glue the pieces together, so that the variable, that holds the reference, is passed into
Light()