0

I have problems with enum and radiobuttons. I'm making a program where the user can choose different types of payments, the types are saved in class Type.java, see code:

public enum Type 
{
    ENGANGSUTBETALING, FASTUTBETALING, ENGANGSINNBETALING, FASTINNBETALING
}

I have a GUI where you can choose the different types listed above. Then i have a method for collecting the data from the text fields, the user inputs amount and description and some other values and chooses one of the radiobuttons.

However, I can't get the type to get the desired ENUM-value. This is my code on that bit:

 Type t;
     if(f_fast.isSelected())
          t=Type.FASTUTBETALING;
     else if(f_engangs.isSelected())
         t=Type.ENGANGSUTBETALING;

Eclipse is telling me "FASTUTBETALING cannot be resolved or is not a field" / "ENGANGSUTBETALING cannot be resolved or is not a field"

In the constructor for registering the payment, I use similar bits of code.

public void leggTilTransaksjon(Type t, double belop, Calendar dato, String avsender, String beskrivelse) 
{
    Transaksjon tr;
    if (t == Type.ENGANGSINNBETALING)
        tr = new EngangsInnbetaling(belop, dato, avsender, beskrivelse)};

This works fine. Does anybody know why I have the problem with designating the ENUM-value based on the radiobutton?

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
Michael
  • 56
  • 2

1 Answers1

1

My guess is that you import the wrong Type class. Make sure you import the correct one.

Another solution is to use meaningful (and less-used) class names.

BobTheBuilder
  • 18,858
  • 6
  • 40
  • 61