Monday, September 25, 2006

Blogger Categories and Beta Blogger

When are we going to be able to switch our existing blogs over to the new beta-blogger type blogs? I now have so many posts that I can't easily organize them. I even made a new blog to start organizing my posts with the Beta Blogger Categories feature.

Saturday, September 23, 2006

Marilyn Monroe - Death By Psychiatry?

On the CCHR website there is a section devoted to artists. As I am an artist this was struck home to me. Artists and succesful people are often found surrounded by "professionals" in the field of mental health.

I've heard many stories about what happened to Marilyn Monroe but this, from CCHR's website makes the most sense. Here is an excerpt:
"In 1960, Monroe saw psychiatrist Ralph Greenson, whose control over her was swift, severing all her close relationships. By 1962, she realized—too late—that she must "disconnect from Greenson." After spending six hours with him, she was found dead of a drug overdose. In the seven years prior to psychiatry’s influence, Monroe had made 23 movies. In the seven years of her psychiatric "care," she only made six films."
Check out the Citizen's Commission on Human Rights for more information on other famous artists whose lives have been destroyed by Psychiatry in the name of help.

Wednesday, September 20, 2006

How to Close a Swing JFrame Without Exiting?

I have a main JFrame and a sub JFrame that opens based on a double click event on a JTable. This second JFrame has details about the record double clicked. When trying to close the second JFrame the entire application closes. I just want the sub JFrame to close and return you to the original JFrame. Let's see what google says about this...

Google Search

From this I found a simple definition of the close function. Here it is.

I want to close my JFrame either by the user clicking on the "X" or when the user clicks on the "Save" button.

The simplest way to do this is to add one of the four to your JFrame code:
this.setDefaultCloseOperation ( JFrame.DISPOSE_ON_CLOSE );
this.setDefaultCloseOperation ( JFrame.HIDE_ON_CLOSE );
this.setDefaultCloseOperation ( JFrame.EXIT_ON_CLOSE );
this.setDefaultCloseOperation ( JFrame.DO_NOTHING_ON_CLOSE )
;

Sunday, September 17, 2006

How to Create Double-Click Event on a JTable in Swing?

I have created a basic application with buttons, combo boxes a JTable with a JScrollPane and want to have a double-click event on my JTable which opens an "Edit Detail" screen that pulls up the record's data and allows data to be filled in and then saved.

Here is how to set up a double-click event that opens a new form:

1) First set up Mouse Listener on your JTable:
  myJTable.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
JTable target = (JTable)e.getSource();
int row = target.getSelectedRow();
int column = target.getSelectedColumn();
// do some action
}
}
});
This will give you the row and column that was double clicked.

2) You can then use this to get the value of that row's ID and open a new form and populate it with this record's data. Here is how you would open a new form
   JFrame newFrame = new JFrame();
newFrame.setTitle("Detail Screen");

newFrame.setVisible(true);


The below link was useful in working out how to do this and has many other helpful items:

Detect Double Click


Saturday, September 16, 2006

Attack of the Killer Spinach

Over 10 states are now reporting cases of the killer spinach spawning the E. Coli bacteria. Federal health officials are advising Americans to throw out all the bagged spinach.

I never had a problem with throwing away spinach personally. I just wish this news story broke when I was a kid being forced to eat spinach - I would have really milked this one - years of spinach-free adolescence.

Has anyone heard any similar stories about brussel sprouts?

Friday, September 15, 2006

Refresh a JTable from a JDBC connection

I have a Swing application that uses a JTable and JScrollPane to display data from an Access database via a JDBC connection.

Even though I had properly coded the SQL INSERT statement and the data was loading into my database, the JTable was not refreshing with the new record. I tried the .revalidate() and the .repaint() methods to no avail.

Finally, after reading Ben Hendry's Mastering JTable I was able to sort this out.

In my JButton ActionListener I added the TableModel.addRow method and inserted the newly inserted records into the JTable as well. Followed by a .revalidate() and the data properly displayed without even a flicker in my application.

Moral of the story - always use Model-View-Control (MVC) architecture and separate your view from your data and controls.

Mastering the JTable

Hunting around the web looking for a way to "refresh" the JTable that is built from a database connection. I found the Bob Hendry articles which can be seen here. There are quite informative but don't answer the question in full. Still looking:

Mastering the JTable
Using JTable - part one
Using JTable - part two

How to Refresh a JTable in a JScrollPane?

I have created a Swing application that has a JTable with a JScrollPane that is populated with data from an Access database through a JDBC connection.

There are fields where you can add data and insert a record to this database. I am trying to add an event to the JButton so when you click the button and add a new record, that the JTable refreshes and newly queries the data source.

I've searched for how to handle this and tried the revalidate(), repaint() methods and these don't cause a change.

Tuesday, September 12, 2006

How to Create Directories in Java

Here is a link that describes how to create a directory in Java:

Java IO Reference

Java Swing Resource

Some great Java Swing resources:

Java Tips
Java Tutorial

Monday, September 11, 2006

Eclipse Visual Editor vs. Jigloo

Ok, I've been using the Eclipse Visual Editor for all of 15 minutes and I am sold. Up until now, I've been using Cloudgarden's Jigloo free version, yet after getting constantly annoyed by Jigloo's constant modifications to my code, prevention of using builders and the incessant warnings about how you are using the free version and that this can not be used for commercial use, I had it.

It is much easier to build with the Model View Control (MVC) architecture using the VE tool as opposed to the Jigloo builder.

Here are some comparisons and reviews of these GUI builder tools:

Jigloo Review
Comparison of Java GUI Builders
Comparison with Matisse
IBM Giving Away VE Source Code to Eclipse

How to Install VE (Visual Editor) in Eclipse

I've dabbled with Jigloo and found that Eclipse has its own GUI builder called VE. This needs the GEF and EMF plugins to work.

Here is an excellent resource that answers all the questions I had when getting started with VE, from the installation to how it works.

Sunday, September 10, 2006

JList or JTable - I need a multi-column display

I'm gradually coming to grips with programming user interfaces in Java. Read a bit on the MVC (Model View Control) concept and while I see its value, it is a bit too steep a gradient at this point. I am starting off getting the basics of the Swing GUI and have been using Jgoodies with the Jigloo Windows builder. Even that is a bit steep as I want to know how to build these from the ground up and using the drag and drop tools resulted in skipping some of the basics that left me hanging, when trying to modify and customize what Jigloo provide.d

What has helped learn this the fastest has been to work out some simple application that will be useful and then laying out a UML diagram including Use Case for the requirements, Activity Diagrams and Class Diagrams. A programmer is lost in the woods without these design tools. Then I've taken one element at a time, the JDBC database access, pulling up a list and displaying this, etc.

I am up to a point where I need to display a simple list of entries from a database. The list should have 3 columns. I've only been able to get this to work with one column so far. So what I am looking into is whether it would be better to just use the JTable or figure out a "multi-column" JList.

Here are some resources to figure this out:

Code Guru
Java Sun
Dream In Code

And don't forget to use your Study Tech!

Friday, September 08, 2006

Java isDate() Solved!

With the help of some friends in Javalobby I was able to get a solution to the isDate() issue for Java.
Below is a method that simulates the Visual Basic isDate() method and is configurable so you can set what you consider are the valid date formats.
I modifed this and added the "Jan|Feb|Mar|Apr..." and "JAN|FEB|MAR|APR|..." to the regex so that the method now validates the formats I needed to check.
I am now implementing this in my application.

-------------------------------------------------

import java.util.ArrayList;
import java.util.regex.Pattern;

public class IsDateTestClass {

public static boolean isDate(CharSequence date) {

// some regular expression
String time =
"(\\s(([01]?\\d)|(2[0123]))[:](([012345]\\d)|(60))"
+
"[:](([012345]\\d)|(60)))?"; // with a space before, zero or one time

// no check for leap years (Schaltjahr)
// and 31.02.2006 will also be correct
String day =
"(([12]\\d)|(3[01])|(0?[1-9]))"; // 01 up to 31
String month =
"((1[012])|(0\\d))"; // 01 up to 12
String year =
"\\d{4}";

// define here all date format
ArrayList patterns = new ArrayList();
patterns.add(Pattern.compile(day + "[-.]" + month + "[-.]" + year + time));
patterns.add(Pattern.compile(year + "-" + month + "-" + day + time));
// here you can add more date formats if you want

// check dates
for (Pattern p : patterns)
if (p.matcher(date).matches())
return true;

return false;

}

public static void main(String[] args) {

ArrayList dates = new ArrayList();
dates.add("05.10.1981"); // swiss date format (dd.MM.yyyy)
dates.add("05-10-1981");
dates.add("07-09-2006 23:00:33");
dates.add("2006-09-07 23:01:24");
dates.add("2003-08-30");
dates.add("2003-30-30"); // false
dates.add("some text"); // false

for (String d : dates)
System.out.println(isDate(d));

}

}
-------------------------------------------------


Thursday, September 07, 2006

Java isDate() Function

New to Java, but learning fast and definitely experiencing the "Paradigm Shift", however I find it odd that there is no isDate() function like there is in Visual Basic.

As mentioned in an earlier post, I ran into a Java Date Conversion issue where the date format that I was expecting and turned out in the live data tests, to be a different format. This was after building over 500 test cases that test each of the business rules programmed into a Drools Rules (now Jboss) processor.

So obviously, I want to have all possible date formats accounted for so the solution is to have a function that loops through each of the possible date formats and check if the string parses into a valid Date object using that particular SimpleDateFormat.

I know this can be done using try-catch blocks, but I want to create a more elegant approach calling my custom isDate() function.

Checking aroung Javalobby and other places to see if anyone has already solved this, or if I need to create from scratch.

Wednesday, September 06, 2006

Tom Cruise, Baby Suri, Photos Released


As you can see, Suri is absolutely a beautiful child. Vanity Fair has a major feature on Tom Cruise, Katie Holmes and Suri Cruise. This article dispels the rumors that have been generated by the media over the last several months.

Scientology Today New Site Design

There is a newly designed Scientology Today website. This has daily news about Scientology activities around the world. Scientologists, helping others, using Scientology technology to improve conditions in their environments.

Today's news story has a picture of a chinese VM and a little girl she is helping.

I've noticed the Scientology sites are getting more and more aesthetic and easier to get around in.
Some of the new sites that are stunning are the Youth For Human Rights and the Scientology Handbook sites.

Go and take a look at these sites and let me know your feedback...

Wednesday, August 30, 2006

ACM, Safari and the Professional Development Center

I found a gem. This is the ACM, Association for Computing Machinery. This association has a yearly membership of less than $100 and with this you get access to over 1000 online books, including the O'Reilly series and over 500 online courses.

I've enrolled in about 5 different courses and any one of these would have cost hundreds of dollars each if I had enrolled in one of the online college degree services or other online computer courses.
With this yearly membership you get full access to the Safari collection of books as well.

I am currently enrolled on the full OOAD, Object Oriented Analysis & Design curriculum which contains 6 different courses, gradiently walking you through from basic OO concepts all the way through detailed UML diagrams. Every course contains "Pre" and "Post" examinations so you if you already are an expert at a subject, the course is customized to fit what you still need to work on based on your "Pre" test results. Then you must get over 80% passing rate for you to be considered "complete" with any course. You are directed back to the exact point you missed and you can clear up any misunderstood words and re-study.

Definitely an "A+" for ACM and the Professional Development Center.

Tuesday, August 29, 2006

I know I have a Coffee Addiction, but a Mental Disorder?

The American Psychiatric Association has been at it again. One of the latest entries in the DSM "The Handbook of Mental Disorders", is the Caffeine Disorder. If you are a coffee drinker and get a headache when you don't drink coffee, you can now get free Prozac, paid for by your insurance company. This is because the DSM is used as a shopping list and if it is in the DSM, you can prescribe it. This is total B.S. The disorders entered into the DSM are voted on by a group of psychs each year and they have admitted there is no scientific evidence to back up these disorders. Here is the latest caffeine related disorder.
Anyone who feels this is a bunch of B.S. should check out the CCHR website as they are doing an excellent job of exposing these frauds.

Sunday, August 27, 2006

Star UML - pretty good... What about Poseidon?

Ok, Star UML is pretty good. It felt a little too restricted to code-direct diagrams as opposed to a more abstract modeling environment which is how I like to start.

Poseidon has been downloaded by over a million people. But there is no free version bar a 30-day free trial.

I am going to dig a little more into this and see if it can't just satisfy my UML needs.

Star UML Design Tool

Ok, I downloaded the Star UML Design tool. Looks like an open source UML tool. Sounds promising. I'll give it a review in a bit.

UML Free Tools

Searching the web, trying to find a good simple UML tool. After studying some basics on the UML method I am finding numerous applications where a UML design tool with be great. Of course one could be simulated using Word or Open Office, but it would be much nicer for a series of templates to be laid out ahead of time for each of the different types of diagrams and have these easily available.

I've tried the Visual Paradigm Community Edition which is free and is very nice however you can't print anything off without these annoying watermarks.

Saturday, August 26, 2006

Scientology Stress Tests - Do They Really Work?

Anyone been to the Big Apple lately or walked down Hollywood Blvd and seen the guys in red Dianetics shirts, with the E-Meters and big signs saying "FREE STRESS TEST"?

Here is how this works:

What they do is sit you down and give you a pair of cans to hold. You are asked to think about people and situations in your life that may be causing you stress. The meter reacts to thought as thought is energy. A small electrical current is passed from one hand, through your body and out the other hand. When you think of something stressful, your thought contains more electrical resistance which is measured on the E-Meter with a right motion of the needle.

I have seen this done myself and I have given Stress Tests. The result is quite impressive. I was able to pinpoint exact areas of people's lives that are causing them stress. After receiving the stress test, most people want to find out how to get rid of that stress.

This is what Dianetics is all about. Getting rid of the negative emotion of past incidents which cause you stress in the present.

Here is an on-line version of the Stress Test that you can do.

Friday, August 25, 2006

Java Date Conversion !?!@@#@:(

Is anyone else perturbed about Java dates! 2 weeks of programming based on what was thought to be the "expected" date format of "yyyy-mm-dd" and it turns out to be "dd-mmm-yyyy" and nothing works. Ok, but my program should be able to handle all the various types of common date formats that could be sent in. So I figure, sure, others must have run into this, let's find a library on the net. After nearly an hour of searching, no luck. I guess I'll just build my own...

Wednesday, August 23, 2006

SmallTalk approach to OOP

1. Everything is an object. Think of an object as a fancy variable; it stores data, but you can “make requests” to that object, asking it to perform operations on itself. In theory, you can take
any conceptual component in the problem you’re trying to solve (dogs, buildings, services, etc.) and represent it as an object in your program.

Some language designers have decided that object-oriented programming by itself is not adequate to easily solve all programming problems, and advocate the combination of various approaches into multiparadigm programming languages.

2. A program is a bunch of objects telling each other what to do by sending messages. To make a request of an object, you “send a message” to that object. More concretely, you can think of a message as a request to call a method that belongs to a particular object.

3. Each object has its own memory made up of other objects. Put another way, you create a new kind of object by making a package containing existing objects. Thus, you can build
complexity into a program while hiding it behind the simplicity of objects.

4. Every object has a type. Using the parlance, each object is an instance of a class, in which “class” is synonymous with “type.” The most important distinguishing characteristic of a class is “What messages can you send to it?”

5. All objects of a particular type can receive the same messages. This is actually a loaded statement, as you will see later. Because an object of type “circle” is also an object of type
“shape,” a circle is guaranteed to accept shape messages. This means you can write code that talks to shapes and automatically handle anything that fits the description of a shape. This
substitutability is one of the powerful concepts in OOP.

An excerpt from Thinking in Java.

Quoted

Tuesday, August 22, 2006

The Open Source Paradigm Shift

O'Reilly describes the Open Source Paradigm shift that is ongoing...

Jigloo Eclipse Windows Builder?

Building GUIs for rich client apps in Eclipse is not the easiest thing in the world. I'm looking for windows builders comparable to the Net Beans GUI builder.

I am downloading the Jigloo GUI builder which sounds pretty good but that is coming from company who made it.

What about WindowsBuilderPro? This is a commercial product, not free like Jigloo. How is it better?

I'll try both and see for myself...

On the install, Jigloo is very simple and is just like any other Eclipse plugins. Just copy to the features and plugins directories and your done. WindowBuilder on the other hand has you walk through a install wizard which took only a couple minutes to run through. (Make sure you don't have Eclipse running during the install).

WindowsBuilder has several example apps you can try. In 5 minutes of testing this builder I found it very user friendly. I liked the "quick view" feature where without even compiling you can get a feel for how your app will look during runtime. Now on to Jigloo.

After the few minutes I found it easy to create a basic app. Nothing difficult. I liked the two screen (code/app) view that shows the two-way changes so if you edit the GUI the code changes or you edit the code and the GUI changes.

So far they are both comparable products and I'll spend a bit more time using each on an actual application to see which is the better product.

The Set Interface

Here is how this works. Set is an interface that extends the Collections object. HashSet is an instance of "Set". You can't just instantiate the interface. You do this with the concrete HashSet, TreeSet or LinkedHashSet implementations. Each of these handle the Collection differently.

The HashSet doesn't care what sequence the data is in, but will ensure no duplicates are allowed.

The TreeSet will sort the data and keep it in that order and the LinkedHashSet will retain the sortation that it originally was stored in.

Pretty simple eh.

Using the for loop with a colon?

I've gone through the famous Eckel book on "Thinking in Java" and could not find the examples I've seen in various code, using a for loop with : instead of commas.

Here is an example of one:
class EnhancedForDemo {
public static void main(String[] args){
int[] numbers = {1,2,3,4,5,6,7,8,9,10};
for (int item : numbers) {
System.out.println("Count is: " + item);
}
}
}
While writing this entry, I found a site which gives some direction on this, but still I am not totally tracking. Looking for a better description.

This format of the "for" loop is generally called the "enhanced for loop" and is used with arrays and collections.

Enhanced For
The Enhanced For Loop

Looks like this was only released with JDK 5.0. No wonder I couldn't find it in my outdated reference books...

Collection Examples

I am drilling on using collections, specifically the "Set" collection.

Here is an example using a simple Set collection:

import java.util.*;

public class FindDups2 {
public static void main(String[] args) {
Set uniques = new HashSet();
Set dups = new HashSet();

for (String a : args)
if (!uniques.add(a))
dups.add(a);

// Destructive set-difference
uniques.removeAll(dups);

System.out.println("Unique words: " + uniques);
System.out.println("Duplicate words: " + dups);
}
}
The program is called with "java findDups2 (here you would pass the arguments)" The above will return you a list of the Unique words and the duplicate words passed in its arguments.

Based on the above, objects could also be checked for duplicates, or specific members of objects such as id numbers, names, addresses, etc.

Taking mental note of this for future operations...