Scala, Java, Unix, MacOS tutorials (page 373)

Java/Swing FAQ: How do I center a JDialog?

Answer: The answer here really depends on what you mean by "center". If you really want to center a JDialog on screen, you can use code like this:

// center a jdialog on screen
JDialog d = new JDialog();
d.setSize(400, 300);
d.setLocationRelativeTo(null);
d.setVisible(true);

By calling setLocationRelativeTo with null, the JDialog will be centered.

I’ve been an active investor in the stock market since the early 2000s, and almost everything I've learned can be found in the wonderful book, The Warren Buffett Way. Today I’d like to share some wonderful quotes from that book, along with many other wonder Warren Buffet quotes.

This is a bit of a “one off” post for this website, but I’ve been investing a lot lately, and I created the following “Warren Buffett Way” cheatsheet to help me when deciding to invest in a company, or not.

As that title implies, this cheatsheet is based on the wonderful book, The Warren Buffett Way, by Robert S. Hagstrom, Jr.

Java JFrame FAQ: How do I set the size of a JFrame?

Solution: There are several different ways to set the size of a Java JFrame, but I generally use the setPreferredSize method of the JFrame class in combination with the Java Dimension class, like this:

jframe.setPreferredSize(new Dimension(400, 300));

A JFrame size example

Here's the source code for a complete "JFrame size" example, showing how to use this setPreferredSize method call in an actual Java program.

In a note with the latest Mac OS X 10.5 software update, I read this blurb about Apple's Mac Java support:

Java for Mac OS X 10.5 Update 6 delivers improved compatibility, security, and reliability by updating J2SE 5.0 to 1.5.0_22, and updating Java SE 6 to 1.6.0_17 for 64-bit capable Intel-based Macs.

J2SE 1.4.2 is no longer being updated to fix bugs or security issues and is therefore disabled by default in this update.

Put another way, Java 1.4.x on Mac OS X is dead, long live Java 1.4. Not huge news, but noteworthy.

 

Perl lowercase/uppercase string FAQ: How do I convert a string to uppercase or lowercase in Perl?

Solution: To convert a string to all uppercase characters use the Perl uc function, and to convert them to lowercase use the lc function.

Here are a couple of examples to help demonstrate this Perl uppercase/lowercase string conversion.

Perl uppercase string conversion

Here's a Perl uppercase example, converting a Perl string from whatever it was to all uppercase characters:

Many thanks to Tristan and Bob for a great laugh on an Apple Java email thread concerning iPad Java support:

Question - Will the iPad have the great Java support that regular desktops and laptops have, or will we Java developers be SOL, like we are with the iPhone?

Mac online backup solutions FAQ: What do you know about Mac online backup solutions (Mac online backup services)?

Last year I bought my sister and her daughters an iMac for Christmas, and when I visited them again this year I realized how much data they had accumulated -- data that wasn't being backed up -- including music, photos, and school homework. I quickly realized that I needed to come up with a backup system for their Mac, and because I don't live near them, I knew this Mac backup solution needs to be both simple and automatic.

Haha, this is funny: I forgot that I wrote a review of a Tablet PC that I used back in 2004. I just found that article, and ran across this line:

"Having this Tablet PC ... is like having a sexy girlfriend who also has a lot of irritating habits and no substance. There's a lot of excitement at first, but when the excitement wears off, you've got a decision to make."

I haven't been in the market for a new laptop until recently, and I have to say, wow, I didn't know how much the prices had fallen in the PC laptop market. The entry-level PC models make the MacBook prices seem pretty outrageous.

Steve Jobs quotes: Like Steve Jobs or not, according to many of the quotes attributed to him, he has a way of cutting right to the point. There was definitely a time in my life that I would have loved working with him.

Earlier this morning I read on Daring Fireball that when he was shown an early Apple tablet prototype, he replied something like this:

Perl next loop FAQ: Can you demonstrate how to use the Perl next operator in a for loop?

Problem: You're writing code for a Perl loop, and you need to write some logic to skip over the current element in the loop, and move on to the next loop element.

Perl loop break FAQ: How do I break out of a Perl loop?

Problem: You're writing some Perl loop code (for, foreach, or while), and you have a condition where you need to break out of your loop early, and you quickly find out that Perl doesn't have a 'break' operator.

The Perl "break" statement

In many programming languages you use the break operator to break out of a loop like this, but in Perl you use the last operator to break out of a loop, like this:

Perl string length FAQ: How do I get the length of a Perl string?

To get the length of a string in Perl, use the Perl length function, like this:

# perl string length example
$size = length $last_name;

The variable $size will now contain the string length, i.e., the number of characters in the variable named $last_name.

Another Perl string length example

I just thought to write this article out here when I ran across the following Perl string length code:

iMac brightness FAQ: Is there a way I can control the iMac monitor brightness more than the standard iMac brightness control allows?

I bought a new iMac last year, and in general I like it. In fact, the only thing I can think of that I don't like is that my iMac is too bright. Even at the lowest brightness setting, the iMac display is too bright, especially when I'm working at night. (Makes me wonder if there will be an iMac brightness lawsuit one day.)

From the web browser news desk ... the people at Net Applications released their browser Market Share report recently, and here's a quick look at their numbers:

  • IE dropped 6.54% in 2009 to a 62.69% market share
  • Chrome gained 3.09% to a 4.63 share
  • Firefox gained 2.03% to a 24.61 share
  • Safari gained 0.99% to 4.46
  • Opera gained 0.21% to 2.40

After watching a young relative type on an iPhone recently, I realized he didn't know how to use the "iPhone caps lock" feature. I assumed a person younger than me would know how to use the iPhone caps lock feature, lol, but it's not too surprising, because enabling the caps lock feature isn't the most obvious thing in the world.

iPhone caps lock

To use the iPhone caps lock feature, whenever you're typing something -- like composing an email -- just tap the iPhone Shift button twice. You need to do this quickly, similar to a double-click.

I don't know about you, but I was surprised to read this morning that the iPhone user base has surpassed the Windows Mobile user base.

I never knew the numbers, so I always assumed the iPhone was this "premium" phone that a relatively small percentage of people owned, and that Windows Mobile was on a lot of phones.

Surprise!

Perl "hash key exists" FAQ: How can I test to see if a key exists in a Perl hash?

Many times when working with a Perl hash, you need to know if a certain key already exists in the hash. The Perl exists function lets you easily determine if a key already exists in the hash.

Perl hash tutorials FAQ: Can you share some Perl hash tutorials, or Perl hash examples?

I've recently written a number of articles about the Perl hash construct (or "Perl array hash"). In an effort to try to organize the Perl hash tutorials I've written, I've created this article to help link them all together.