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...