Friday, February 24, 2012

Virtual Developer Day - Java (free event)

Example of Java Swing desktop application without the JSR - 1


From NetBeans 7.1, Swing application framework (JSR) left being supported by NetBeans, and is no longer part of the official JDK (Java Development Kit).

So, in this article, and the next one, we'll make a small application with Swing classes without using the Swing application framework.

We will make use of the application layers previously developed in:

     - Example of Java Swing Application with Oracle Database – 1 (database creation)
     - Example of Java Swing Application with Oracle Database – 2 (HelperDB project for accessing the database)
     - Example of Java Swing Application with Oracle Database – 3 (librarySystemBLL project / BLL classes)

So, after creating the database, and having present projects HelperDB and librarySystemBLL, we will create a new project (librarySystemGUI) for the user interface.
Firstly, we will see how to import a project to NetBeans, having only the java sources developed in any IDE.

Thursday, February 23, 2012

Swing-based desktop applications after NetBeans 7.1

In the articles
     - Example of Java Swing Application with Oracle Database – 1
     - Example of Java Swing Application with Oracle Database – 2
     - Example of Java Swing Application with Oracle Database – 3
     - Example of Java Swing Application with Oracle Database – 4

we developed a small example application, for desktop, using Java/JavaSwing.
For that we used NetBeans IDE, and created a project of type Java Desktop Application for the user interface.

Since NetBeans 7.1, however, Swing application framework is no longer supported by NetBeans, and stopped being part of the official JDK (Java Development Kit). In fact, in NetBeans 7.0.1, the following message already appeared every time one created a Java Desktop Application project:


In NetBeans 7.1 we have, at least, two alternatives:
  • To create an application from scratch, or
  • To create a project of type Netbeans Platform Application
In the next article we will address the first option, lefting the second alternative to a future article.


Friday, February 17, 2012

First Eclipse Modeling Framework (EMF) example - 3

In the previous article we've created a domain model for a Library Management System, and we've generated a set of corresponding Java classes, by using Eclipse Modeling Framework (EMF).

Now, we're going to test those classes through a new Eclipse project, which references the one with the generated classes.

So, we now create a new plug-in project:
                                     File --> Create --> New --> Project... --> Plug-in Project.


And, in folder src, we create a new class with a stub for method main:


And we create, in method main(), a few lines of code:

package javaUsingEMFModel.LibrarySystem;

import org.eclipse.emf.ecore.*;
import LibraryModel.*;
import LibraryModel.impl.*;
import LibraryModel.util.*;

public class MainClass {
    public static void main(String[] args) {

// Inicialize the LibraryModelPackageImpl
        LibraryModelPackageImpl.init();

        LibraryModelFactory factory = LibraryModelFactory.eINSTANCE;
       
        // Create a new Book
        Book book = factory.createBook();

        // Give a title to the book
        book.setTitle("Os Lusiadas");
       
        // Create an Author, and define his/her name and surname
        Author author1 = factory.createAuthor();
        author1.setName("Luis");
        author1.setSurname("Camoes");
       
        // Add that author as an author of the previously created book
        book.getAuthors().add(author1);
       
       
        System.out.println(book.getTitle());
    }
}

This is only the beginning. Now you should create instances of the remaining classes, inter-relate them, and query its attribute values and the values of the relation attributes.

Related articles:
        - First Eclipse Modeling Framework (EMF) example - 1
        - First Eclipse Modeling Framework (EMF) example - 2




Thursday, February 16, 2012

First Eclipse Modeling Framework (EMF) example - 2

In the previous article we started exploring Eclipse EMF. In this article we will build a domain model (persistent data model) of a small library management system.

To start, let us create a new project:

        - select File --> New --> Project
        - Then, in the opening window, select Eclipse Modeling Framework --> Empty EMF Project



Let's name our project testemf.

Then, in folder model, use the mouse's right button,



and select New --> Other. A new window opens:



Here, select EcoreTools --> Ecore Diagram. The goal is to create a domain model by using the UML class diagram editor.

Creating the Ecore Diagram is a nice way of creating an Ecore model, instance of the Ecore metamodel. We can, then, understand this as the creation of a DSL (Domain Specific Language). Let us name our DSL as LibraryModel.

Tuesday, February 14, 2012

First Eclipse Modeling Framework (EMF) example - 1

Eclipse is an IDE (Interactive Development Environment) that allows the development of programs in different programming languages. Some characteristics of Eclipse are the use of the Standard Widget Toolkit (SWT) as graphics library, instead of Swing, the plugin oriented way of programming, and its extensibility, there existing lots of projects that extend Eclipse in diverse directions.
One of those directions is model-driven-development, and the subsequent code generation from models. Eclipse Modeling Framework (EMF) project is a modeling environment and code generation functionality that enables the construction of tools and other software applications based on a structured data model (domain model). From a domain model specified in XMI, or in another supported format, EMF provides tools and runtime support for the production of Java classes that implement the model, and a set of adapter classes that allow editting and viewing the model through Java code, and a basic model editor.

Tuesday, February 7, 2012

Example of Java Swing Application with Oracle Database – 4

In this article we're going to develop the presentation layer of our software application. This layer is also know as User Interface or Graphical User Interface Layer.

In blog entry Example of Java Swing Application with Oracle Database - 1, the first one of this series, we've handled the Oracle database creation. In the 2nd article a database access package has been created, HelperDB. The 3rd article addressed the creation of a class library at the level of business logic layer and data access layer.

This article addresses the construction of the user interface project (GUI - Graphical User Interface) using Java Swing classes. To do that, we need to create a new Net Beans project, which we will name LibrarySystem:


This project must be a Java Desktop Application. This kind of project supplies a template with the basic infrastructure of a desktop application, such as a main window with a menu bar and a status bar.

Then, we select Basic Application (the other type, Database Application, will be treated in another series of articles).

This kind of project creates beforehand 3 classes:
- LibrarySystemApp.java - this is the application's main class. The main method will launch the main window. From there, the whole application will be event-driven.