![]()
This first tutorial is your basic "Hello world" program. The program consists of a window with the words "Hello world" displayed in the center. It is made up of three files - the source and header for the object that contains the window, and the source that contains the function main.
/******************************************************************************
HelloWorldDir.cc
BASE CLASS = JXWindowDirector
Written by Glenn Bach - 1997.
******************************************************************************/
#include "HelloWorldDir.h"
#include <JXWindow.h>
#include <JXStaticText.h>
#include <jAssert.h>
/******************************************************************************
Constructor
******************************************************************************/
HelloWorldDir::HelloWorldDir
(
JXDirector* supervisor
)
:
JXWindowDirector(supervisor)
{
// Create the Hello World window
JXWindow* window = new JXWindow(this, 200,100, "Hello World Program");
// Make sure that new succeeded
assert( window != NULL );
// Tell the window director that this is its window
SetWindow(window);
// Set the min and max size of the window.
// This particular pair of operations can also be done
// by calling window->LockCurrentSize().
window->SetMinSize(200,100);
window->SetMaxSize(200,100);
// Create the object to hold our "Hello World" message.
// We do not need to keep a pointer to it because the
// framework will delete it automatically when the window
// is closed.
JXStaticText* text =
new JXStaticText("Hello World", window,
JXWidget::kFixedLeft, JXWidget::kFixedTop,
20, 40, 160, 20);
assert( text != NULL );
}
/******************************************************************************
Destructor
******************************************************************************/
HelloWorldDir::~HelloWorldDir()
{
}
/******************************************************************************
HelloWorldDir.h
Interface for the HelloWorldDir class
Written by Glenn Bach - 1997.
******************************************************************************/
#ifndef _H_HelloWorldDir
#define _H_HelloWorldDir
#include <JXWindowDirector.h>
class HelloWorldDir : public JXWindowDirector
{
public:
HelloWorldDir(JXDirector* supervisor);
virtual ~HelloWorldDir();
private:
// not allowed
HelloWorldDir(const HelloWorldDir& source);
const HelloWorldDir& operator=(const HelloWorldDir& source);
};
#endif
/******************************************************************************
hello_world.cc
Written by Glenn Bach - 1997.
******************************************************************************/
#include "HelloWorldDir.h"
#include <JXApplication.h>
#include <jAssert.h>
/******************************************************************************
main
******************************************************************************/
int
main
(
int argc,
char* argv[]
)
{
// Create the application object - there should only be one of these
JXApplication* app = new JXApplication(&argc, argv);
// Make sure that new succeeded
assert( app != NULL );
// Create the window director to maintain the Hello World window
HelloWorldDir* mainDir = new HelloWorldDir(app);
assert( mainDir != NULL );
// Show the window and activate it
mainDir->Activate();
// Start the event loop
app->Run();
return 0;
}