Lost in life
Lost in life
Lost in life
Often the most important part of the news is what they didn't tell.
Campbell Ritchie wrote:Also, what is ProgList (I have answered that for myself)? Why does your listener class extend it, and have a reference to it as a field? I would regard those two features as mutually incompatible. I suspect you probably don't want either.
You have gone to lots of trouble to ensure values for min and max, but what happens if somebody enters min=6 and max=3?
Lost in life
Tim Holloway wrote:Swing is one of those funny cases where you'd define an anonymous inner class implementation of Listeners and override only the methods of interest. That usually ran to 5 lines of code, give or take and wasn't worth breaking out into an independent class definition file. Plus, being anonymous you couldn't - external classes have to have names.
But since around Java 8, the language has supported Lambdas, which were intended to do the same thing in a more elegant way. I don't have any recent Swing code, but perhaps someone here could give an example?
Lost in life
Lost in life
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:hi Suane,
that is because you initialize some fields as follows:
So, your program IS running, it is just waiting for some input!
But, you are right when stating your code is a little messy![]()
Lost in life
There are three kinds of actuaries: those who can count, and those who can't.
Piet Souris wrote:
a way is to put this part in main(), and give these variables as arguments to your constructor. What I would certainly do is to put some text before usng scanner,nextInt, for instance:
Then the user sees that he/she is supposed to input something.
Lost in life
Carey Brown wrote:
Lost in life
There are three kinds of actuaries: those who can count, and those who can't.
Lost in life
There are three kinds of actuaries: those who can count, and those who can't.
Lost in life
Lost in life
There are three kinds of actuaries: those who can count, and those who can't.
There are three kinds of actuaries: those who can count, and those who can't.
Lost in life
Lost in life
Suane Mane wrote:Trying to tackle some error handling if a user enters a double instead of int. I used a try/catch but it still stopped the program when the exception occurred. Am I placing it in the wrong place?
Lost in life
Suane Mane wrote:Also I thought the "else..." part of the code covered the part that would have to be in the try block because that covers all the numbers that can be entered from 0 to 9, which means it can hold 2.5, 4.6, 7.3 etc.
Paul Clapham wrote:
Suane Mane wrote:Also I thought the "else..." part of the code covered the part that would have to be in the try block because that covers all the numbers that can be entered from 0 to 9, which means it can hold 2.5, 4.6, 7.3 etc.
No. A try-block is specifically for catching exceptions. It's the Integer.parseInt() method that will throw an exception, so it's the code that needs to be in the try-block. The rest of the code checking for < 0 and > 9 doesn't need to be in the try-block and the code might be clearer if it wasn't.
Lost in life
There are three kinds of actuaries: those who can count, and those who can't.
Space pants. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
|