Rob Ross

Bartender
+ Follow
since Jan 07, 2002
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
7
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Rob Ross

Originally posted by Mike Lipay:
I am writing a desktop application and want to include a background image, but I can't find a container type that will hold an image. How can I do this?



You can use a JLayered pane. Add your component to a layer far behind your normal components. You'll have to call setOpaque(false) on all the components that draw on top of the background image in order to see the background.

JFrame has a root pane which is already a JLayered pane, so you can just add your component to that.
15 years ago

Originally posted by Jennifer Sohl:
Hi there. I have some applications that I want to enable users to do print screens on. I have been able to get the screen to print, however part of the screen gets cut off when printing on 8-1/2 x 11. Is there any way that I can automatically tell it to "Fit to Page" when printing? This is currently what I'm using to print:

...

Another thing.... I got this code from the web, but I don't think I really understand it. At what point does the paint(Grahpics g,PageFormat pf,int pageIndex) method ever get called? I had put a System.out.println in this method and it never showed up when I ran the program.
Thanks for any help!

[ June 27, 2008: Message edited by: Jennifer Sohl ]



You need to apply a scale transform on the Graphics. After you call translate, call scale, which takes doubles for x,y that represent the scale factor. You can think of it as a percentage. 1.0 means no change, 2.0 means twice as big, .5 means half size, etc.

You'll have to calculate how much you need to scale. Get the size of you component, compare to the size of your imageable area to compute a ratio, and that will tell you the scale factor. You'll want to keep the same aspect ratio though, so you want to pass the same values for x,y to scale, so just use the smaller of the ratios of the width,height of your component.

The printer job calls your paint() method whenever it needs it to paint a page. It can call it multiple times per page, so don't change any object state in your paint() method.

Printing is done internally on a background thread, so that's why you don't see any println output. It's a pain in the you-know-what to debug printing problems. I've taken to actually using drawString commands, so I can just paint debug messages to the Graphics when I'm having trouble. When debugging I always just do a print-preview from my OS print dialog so I don't waste paper.

Hope this helps.
15 years ago

Originally posted by Ernest Friedman-Hill:
The "brace-on-the-same-line" style originated with Kernighan and Ritchie's "The C Programming Language". They have gone on record saying that this was only done to save vertical space in the book, enabling them to keep listings together on a single page.



I've seen this mentioned a few times on the internet, but I could never find an actual source for this. So I emailed K&R, and got a reply back from Brian Kernighan, the 'K' in K&R. He does not recall ever saying this. He writes :

"My memory of the indentation quote (if it really existed) is dim at
best. The basic style is pretty much what was used in the Unix kernel
and other software written by Ken Thompson, Dennis, and others; it was
pretty much homogeneous except that Ken had a weird way of formatting
else clauses that I thought was deceptive, and he didn't put the
semicolon of an empty block on a separate line, which again I thought
bad. It is true that in general we were working on devices with a
limited number of lines -- either terminals with actual paper, or
screens with 24 lines. Those both encouraged a reasonably compact
style.

I still prefer the style that Ken and Dennis came up with, and still for
the same reasons: it fits somewhat more code on a screen than putting
braces on separate lines, without interfering with readability. But
it's still sort of a religious issue, and I don't mind people who
believe differently."

So this idea that they wrote their braces in the K&R style for publishing reasons is false.

Just thought you'd want to know.
15 years ago

Originally posted by colin shuker:

I'm shocked that java wont let you plot a point.
Why isn't there a method plotPoint(x,y) or something???



One reason may be that in Java 2D, points are infinitely small. They have no spatial extent. A *range* of points, however, can be rendered, such as a line, or a rectangle.

Just my quick 2 cents.
[ June 25, 2005: Message edited by: Rob Ross ]
18 years ago
I just want to add one observation.

Right now, and for the last month, Sun's Java people resources will have all been in heads-down bunker mode getting ready for Java One. It's pretty much like this every year about this time.

Java One will be over on July 1, but then most of these same people have the following week off.

So, it's a bit of bad timing to be sure, but I would really be patient and try to understand that the people who would be in charge of dealing with your issue probably aren't going to be able to look at it until at least the week of July 11th.
18 years ago
Invocation order is covered in chapter 11, and yes it will be on the test. I've noticed that sometimes, the mock exams reference topics that haven't been covered yet, but if they're important for the test, rest assured that they will be covered at some point.

Btw, it's a good idea in general to at least browse through the JSP and Servlet spec, just to get an idea of what's in there, so if you have any questions you'll know where to find more detail.
What is the problem you are having? I could not tell by your description what is not working for you.
You've already been able to get certified in SCJP and SCBCD, so you must be very familiar with how to go about studying for another certification.

Here's a link that has the objectives and a study guide that looks interesting:

study guide

and here is another one. (I was able to find both by doing a google search on "Java WCD objectives.")
I'm not sure what study you were reading, but the one linked by William Brogden above shows that Java 1.4.2 either beat or compared very favorably to both C++, Visual C++, as well as C# .Net. The only area it lagged behind in was in calling trigonometric functions, but the author of the study himself admited he wasn't sure if there was a better way to call the functions than the methods he used.

Read the study again, and keep in mind that SMALLER numbers are better.
19 years ago
Well, I originally got my SCJP cert because I wanted to challenge myself and really kick up my skill level a notch. Studying for the exam and the strengthening of my Java knowledge were the biggest benefits I got from taking the SCJP. The paper itself hasn't done much for me.
19 years ago
I've developed several detailed build.xml scripts, one for stand-alone projects, and one for web apps. When I start a new project, all I have to do is customize a few parameters in the build.properities file for that new project, and I never have to edit my build.xml file. That makes it easy to maintain a small group of build.xml scripts and just customize a single file with a few properties for each new project.
[ April 25, 2004: Message edited by: Rob Ross ]
19 years ago
In general yes, but if you use multiple hosts (virtual hosts) or if you use clustering, there will be multiple instances of the JVM running, and your singleton will only be unique to each instance. For cases like these, you'll have to use some sort of database repository if you only want one instance of something represented accross multiple hosts/clusters.
19 years ago
My guess would be it uses whatever the value in JAVA_HOME is.
19 years ago
You can add the jar file to your IDEA project's classpath, then make sure that you have set the property on the build.xml file (from within IDEA) to include your project's classpath when IDEA runs your xml script.