Is there a way to setup a jFormatted Field and retrieve a int value using getValue()... I am abit lost.

private jFormattedField CsNumber = new JFormattedField();

Also is there a way of restricting the value being input to only being a number and not negative?

Do you mean a JFormattedTextField? And you'd do something like

Integer.parseInt(textField.getValue());

Keep in mind that you should use a try catch in case of input error. Double has a similar method if you want to parse a double.

Hmmm ok and how do i use the try catch method? and where do i throw it to?

Hmmm ok and how do i use the try catch method? and where do i throw it to?

try{
int number = Integer.parseInt("Some string here");
if (number > 0) // YAY!
else //BOO!
}catch(Exception e){
//WTH! Problem!
}

And instead of doing whatever gangsta is pointing you towards, just use an if statement, lol.

if this is a homework, go with whatever Jew.

but you like my advise if you want your program to be cool.

My suggestion is much easier so whether or not it is a homework assignment is irrelevant. It isn't a contest, I'm just giving the OP what I think is a better solution.

no, its not a contest.
Its ok for him to use your try-catch approach. Generally everybody uses this approach and so do I.

But try-catch approach does not respond the following question totally.

Also is there a way of restricting the value being input to only being a number and not negative?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.