Wednesday, May 27, 2009

Java Basics Using Qt Jambi Tutorial

Java Main Program

Explaining Java Language By Example

Now, that you have successfully create, run your first Qt Java Program, let's go and look at the details on how it works.

package helloworld; //packages make your classes and interfaces unique by grouping of related types (classes, interfaces, enumerations, and annotations).

import com.trolltech.qt.gui.*; //this imports the package so that we could use the classes and methods.

public class Main { //this creates a class called Main (should be the same name of the saved file

public //modifiers static //associated with outer class void //return type main//function name (String[] args){ //this is the method or function which every main application must contain.

Qapplication.initialize(args); //this initializes the Qt Application with args as the java JAR name which is Main.jar

Note: As you will notice when using the Qt Framework, classes starts with “Q” such as QApplication, QWindow, etc.

QMainWindow window = new QMainWindow(); //creates an instance of the class QMainWindow since we created a MainWindow in Qt designer which is (public void setupUi(QMainWindow helloworldMainWindow)).

Ui_helloWorldMainWindow ui = new Ui_helloWorldMainWindow(); //creates an instance of (public class Ui_helloWorldMainWindow).

ui.setupUi(window); //calls the method setupUi of class Ui_helloWorldMainWindow and parses window to QmainWindow in (public void setupUi(QMainWindow helloWorldMainWindow)) as an argument.; //calls the window (QMainWindow) method show which shows the window.

QApplication.exec(); //executes the method exec of the QApplication Main.jar.

to be continued...

No comments: