Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp

Piet Souris

Master Rancher
+ Follow
since Mar 08, 2009
Netherlands
Cows and Likes
Cows
Total received
91
In last 30 days
8
Total given
62
Likes
Total received
482
Received in last 30 days
17
Total given
50
Given in last 30 days
5
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Piet Souris

Well,

it is an ever going on discussion about beginners and an IDE. I used an IDE right after I tried to compile my first program and couldn't believe the misery I got on my screen. See for instance this old discussion:

old discussion
7 hours ago
Four years ago I followed the Scala course at Coursera, from Martin Odersky (one of the finest courses I've ever had, thoroughly recommended), and there I used an Eclipse version with a Scala REPL, and I found it really great! I made all my assignments in the REPL, sometimes trying to send in my REPL instead of a decent Application!

But using a decent IDE is fine enough for me as well, have never missed a Java REPL. Wonder if I have to change my opinion.
1 day ago

Rob Camick wrote:Again, I repeat you should not be using the getGraphics() method to draw onto a Swing component. You use the Graphics object passed to the paintComponent() method of the component.


Interesting. I just stated that that technique works, and you state that one should not use it. But let us not pollute this topic, I hope OP has enough information to solve his problem, and maybe we can come back on this subject later, in some other topic, perhaps.
1 day ago
Well, had to adjust JAVA_HOME and my Path, but then JShell in the cmd worked first time!

And so far, works a treat.The only thing really missing is when I type, say, 'IntStream.' and being used to a popping up list of all that I can type, I now get nothing and have to do it from memory. Culture shock! But I have just started investigating, who knows what I will discover...
1 day ago
I will, but as a convinced command line hater I must first find out how that works!    
2 days ago
You're welcome! Since this all is a bit unusual, please let us know about your experiences, whether there are other problems that were unforeseen.
2 days ago
I see. If editability is not relevant for your application, then I would go with Rob: use a BufferedImage to do your drawings (ironically, you must use the bi.getGraphics() for that as well), and in your paintComponent draw that bi. I guess the examples will make it clear how to do that.

For text input, I was thinking of adding a JLabel for that, or use the Graphics method g.drawString(...). Well, let us know if you need more help.
2 days ago
Hmm... it IS working, but that JShell looks to be bug ridden. I've had lots of null pointer exceptions. If I want to type 'var a = 9', I get the NPE after typing 'va'.

Anyone using NetBeans 9, having such experiences?
2 days ago
If done carefully, the technique of using both the getGraphics to do direct drawing and using paintComponent certainly does work beautifully, in my experience. Just make sure that whatever you do in the getGraphics, is reflected in your data structure, so that in a later paintComponent that same situation can be restored.

For instance, if you are drawing lots of shapes on some panel with other components on it, then you could have a List<MyShapes> and a currentShape. Change the current shape with the direct method, and in the paintComponent you simple redraw the List. Is relatively easy to implement, and relying solely on the paintComponent would be far too slow. If anything of that is applicable here, I don't know, but I could have a look.
2 days ago
Enjoy the lead (and a cow) while you still can... I'll be catching up real soon!  
2 days ago
Hmm, solved it, I hope,

It is about the file 'C:\Program Files\NetBeans 9 RC\etc\netbeans.conf'. Near the bottom there is the outcommented line:

#netbeans_jdkhome="path/to/jdk"

that must be changed to

netbeans_jdkhome="C:\Program Files\Java\jdk-10.0.1"

(or whereever you put your jdk)

But o horror: whatever I tried, I lacked the right to save that editted file! So I messed around with privileges and similar things, not knowing what I was doing, but finally got it somehow working. Hopefully, next time Apache delivers some decent installers... Brrrr.
2 days ago
hi all,

Today I installed java 10 and NetBeans 9 RC, on both my PC and a laptop.

However, whatever I do, I see no sign of JShell, both on laptop as on the PC. Not in the Tool menu, not in the test library's, not in my run configuration. Spent hours on the problem, but in vain, sofar.

Looking at Google, it seems as if I am the only one suffering from this problem. Is there anyone who has any idea what I might have missed or where I should look for possible problems?

Thanks in advance!
2 days ago
Now that you've come to mention it....

In the insurance business reporting and pricing are based on what we call market consistent valuation. The regimes, like IFRS4 and beyond (especially the current IFRS17) and Solvency II, are extremely strict. Every simplification that you make in your models, every approaching way has to be clearly explained and the least thing is that you come up what the financial impact of such a simplification is (even in the cases where you make a simplification because the real thing is far too complex to model, or would require too much time to calculate). And the reviewers (be it the accountant offices or the insurance government institues) are very very strict.

For the calculations: think about a large insurance portfolio that you calculate the cashflows for the next 80 years, using tens of thousands of scenario's and assumptions for the coming 80 years.

But so far, no reviewer has ever come up with the question what the impact is of using 64 bit doubles, compared to using infinite precision floating point (no idea how we are supposed to do that). And how could we? At the moment the deadlines are very strict. To gather all the data, to make the many million calculations every month, do the reporting, we only have about 5 working days available. So speed is of the utmost importance. But interesting question, though.

I'm content with the current longs, doubles and (hardly ever use them) BigDecimals. If ever, getting rid of the primitives, operator overloading, scala's type and being able to write a.method(b) as a method b, and a Tuple class would be my priorities.
4 days ago
If the code is executed on the EDT, and the submitted task is taking a while, then you would expect the GUI to freeze up for a moment.
You can easily test if the code is running from the EDT, by invoking

If that is the problem, then execute that submit-task in a SwingWorker in its own Thread. Its 'done' method is executed on the EDT as well, so that would make it very easy to get the result.

For the API, see    SwingWorker
and for a tutorial    tutorial
4 days ago
For a start: look at the code in your opening post:

You do not implement an ActionListener at all. In fact, code is executed (lines 2-8) in a place where that should not be allowed. See Campbells remark about this.

But normally an Action is of the form:

and perhaps a little later:

I wrote a small program with two frames and a button in one of them, and that button controlls the visibility of the second frame. It is not exactly what your program does, but it shows that the second frame is not blank, and how to keep the visibility and the button in sync. Using two frames and controlling when one of them is closed, or iconified et cetera is certainly not so easy.

My demo, in case you are interested, can be found on my GitHub account, GitHub , in the src map, ScottEricCatalano.java
5 days ago