• Post Reply Bookmark Topic Watch Topic
  • New Topic

Running a protected abstract class  RSS feed

 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm working on a sudoku program where I kindof put together pieces of the program to finish it.
I''m not that experienced with Java and I'm having trouble with some abstract classes.

Long story short, what I need to do is start the "tegnBrett" method in the protected abstract class SudokuPanel.
I tried doing this by just calling it with "tegnBrett()", but then I get the error "the method tegnBrett is undefined for the type SudokuGUI".



I can see that tegnBrett is in a class inside a class. I can't remember dealing with such before, and I don't have alot of idea for how to deal with it. I can't just call it normally, abstract classes can't be instanciated directly and I don't think I'm supposed to use a subclass for this.
Can anyone help me?
[ March 28, 2008: Message edited by: Kari Nordmann ]
 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Kari,

you're just calling the method tegnBrett() in your constructor of SudokuGUI without giving a object so it's called directly on your SudokuGUI object which doesn't have such a method like the compiler told you

You first have to create an instance of your static nested class SudokuPanel with the operator "new" and call tegnBrett() on this object!

Separate from this problem the design of your application looks a little strange. Do you really want this nested class if you're new to Java and don't really understand what it does? And using an abstract class for your main Swing frame looks weird, too. Perhaps you should improve the design of this application.

Marco
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!