Reputation: 1
can't get this code to compile, I get an error that says:
invalid method declaration;
return type required public MineFinderFrame(int nc, int nr,int mod)
please can anyone amend my code?
class MineFinderPanel extends JPanel implements MouseListener
{
int numCols;
int numRows;
int myModel;
public static void main(String[] args)
{
MineFinderFrame w = new MineFinderFrame(30,50,42);
w.numRows = 50; // 50 rows
w.numCols = 20; // 20 columns
w.myModel = 42;
w.setVisible(true);
}
public MineFinderFrame(int nc, int nr,int mod)
{
numCols = nc;
numRows = nr;
myModel = mod;
addMouseListener(this);
}
Upvotes: 0
Views: 124
Reputation: 12123
You need a class named MindFinderFrame
, if that's the type you are instantiating. Did you mean to name MindFinderPanel as MindFinderFrame? (Or, other way around, perhaps you should be calling,
MindFinderPanel m = new MindFinderPanel(...);
Upvotes: 1
Reputation: 7267
public MineFinderFrame (int nc, int nr,int mod)
is a constructor for a class called MineFinderFrame and you are trying to use it as a constructor of a class called MineFinderPanel.
Upvotes: 0
Reputation: 1985
Is MineFinderFrame
supposed to be a constructor?
If yes, it must have the same name as the class (MineFinderPanel
, not MineFinderFrame
).
Otherwise, it is a normal method and it must have a return type.
Upvotes: 1
Reputation: 9559
The method MineFinderFrame(int nc, int nr,int mod) does not say what type it returns.
Did you mean it to be the constructor? If so, is should be the same name as the class:
public MineFinderPanel(int nc, int nr,int mod) {
numCols = nc;
numRows = nr;
myModel = mod;
addMouseListener(this);
}
Upvotes: 1
Reputation: 20969
If you rename your class, you also have to rename the constructor in this class.
So I would start with this:
public MineFinderPanel(int nc, int nr,int mod)
{
numCols = nc;
numRows = nr;
myModel = mod;
addMouseListener(this);
}
And then, you would also have to change the first line in your main method to
MineFinderPanel w = new MineFinderPanel(30,50,42);
Upvotes: 4
Reputation: 429
Your second function needs to declare a return type.
If your function is not supossed to return anything use void:
public void MineFinderFrame(int nc, int nr, int mod)
Upvotes: 1