compiler say invalid method declaration return type required

how can i have a return type in my constructor?. that does not make any sense. i have never seen a constructor asking for a return type why my compiler gives me this error?

here is my investmentdeposit class

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

class InvestmentDepositextends JFrame{

privatestaticfinalint FRAME_HEIGHT = 350;

privatestaticfinalint FRAME_WIDTH = 250;

privatestaticfinaldouble DEFAULT_RATE = 5;

privatestaticfinaldouble INITIAL_BALANCE = 1000;

private JTextField withdrawField;

private JTextField depositField;

private BankAccount account;

private JLabel rateLabel;

private JLabel resultLabel;

private JLabel depositLabel;

private JPanel panel;

private JButton button;

private JButton button1;

public InvestmentDepsoit(){

account =new BankAccount(INITIAL_BALANCE);

resultLabel =new JLabel("Balance: " + account.getBalance());

createTextField();

createWithdrawButton();

createDepositButton();

createPanel();

setSize(FRAME_WIDTH, FRAME_HEIGHT);

}

privatevoid createTextField(){

rateLabel =new JLabel("Withdraw Money ");

finalint FIELD_WIDTH = 10;

withdrawField =new JTextField(FIELD_WIDTH);

withdrawField.setText("" + DEFAULT_RATE);

depositLabel =new JLabel("Add Money ");

depositField =new JTextField(FIELD_WIDTH);

depositField.setText("" + DEFAULT_RATE);

}

privatevoid createWithdrawButton(){

button =new JButton("Withdraw");

class AddWithdrawListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent event){

double value = Double.parseDouble(withdrawField.getText());

account.withdraw(value);

resultLabel.setText("Balance: " + account.getBalance());

}

}

ActionListener listener =new AddWithdrawListener();

button.addActionListener(listener);

}

privatevoid createDepositButton(){

button1 =new JButton("Deposit ");

class AddDepositListenerimplements ActionListener{

publicvoid actionPerformed(ActionEvent event){

double value = Double.parseDouble(depositField.getText());

account.deposit(value);

resultLabel.setText("Balance " + account.getBalance());

}

}

ActionListener listener =new AddDepositListener();

button1.addActionListener(listener);

}

privatevoid createPanel(){

panel =new JPanel();

panel.add(rateLabel);

panel.add(withdrawField);

panel.add(button);

panel.add(depositLabel);

panel.add(depositField);

panel.add(button1);

panel.add(resultLabel);

add(panel);

}

}

here is the error

C:\Java programs\ch14\Investment2\InvestmentDeposit.java:20: invalid method declaration;return type required

public InvestmentDepsoit(){

^

1 error

[5903 byte] By [lrngjavaa] at [2007-11-26 23:46:39]
# 1
lol i changed my class name to DepositFrame and it works. so that means everytime i am extending my JFrame i need to have a class name which ends with Frame? like DepositFrame, IncidentFrame, etc...
lrngjavaa at 2007-7-11 15:20:13 > top of Java-index,Desktop,Core GUI APIs...
# 2

Misspelling:

InvestmentDepsoit

InvestmentDeposit

The Class name should match the name of the constructor (which should also match the name of the .java file.)

I highly recommend downloading one of the free IDEs which make it easy to catch and correct this kind of thing. I use Eclipse.

Message was edited by:

pthorson

pthorsona at 2007-7-11 15:20:13 > top of Java-index,Desktop,Core GUI APIs...
# 3

lol thanks. yes i will be using an IDE soon i just ordered ram upgrade. one more question is there a way to make a check on the two buttons like right now if someone enter 20.5 in the Withdraw text field and instead of hitting withdraw use hits deposit button how can i make a check to tell the user that you need to enter an amount in the deposit not in the withdraw field. hope i am making sense.

lrngjavaa at 2007-7-11 15:20:13 > top of Java-index,Desktop,Core GUI APIs...
# 4
You should be able to add any verification you need to the actionListeners for the buttons. Since the text fields are global, it should be no problem to look at the values entered.
pthorsona at 2007-7-11 15:20:13 > top of Java-index,Desktop,Core GUI APIs...
# 5
I have the same problem, except when I enter the void method declaration, the compiler gives me a bunch of baloney on not recognizing my package importations. I have JCreator LE.
Supercitesa at 2007-7-11 15:20:13 > top of Java-index,Desktop,Core GUI APIs...