
|
|
A1. Making the Transition from OS/2 to Java
This section contains several examples of OS/2 programs and their
Java counterparts. You may find it useful to compare analagous OS/2
and Java programming idioms when you are converting OS/2 programs from
C to Java.
Note that in some cases the OS/2 C version of the C program may not
be exactly the same as the Java versions. One of the major
differences is that the C version does not support layout managers, so
resizing a window will not resize the contents of that window.
Also, in each of the examples below, the OS/2 C source code is
listed as the contents of the "rc" file followed by the header file,
and finally the actual C source code.
Most of the Java code was generated using VisualAge for Java's
Visual Composition Editor. (Thus explaining the mechanical looking component names
such as button1, button2...)
A final note:
This section may appear extra wide in some browsers. This is because of the
width of the source code contained within it.
This example creates an applet that can change it's
background color by having the user select a color via a ColorEditor
bean.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - ColorLis
*
* This demo is intended for comparison with the ColorChoiceApplet.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "colrpane.h"
ICON ID_WINDOW colrpane.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - ColoredPanes
*
* This demo is intended for comparison with the ColoredPanes.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_STATIC1 251
#define ID_STATIC2 252
#define ID_STATIC3 253
#define ID_STATIC4 254
#define ID_WINDOW 256
#define ID_FILE 257
#define ID_EXITPROG 261
/*****************************************************************************
* OS/2 PM/C Language Demo - ColorPanes
*
* This demo is intended for comparison with the ColoredPanes.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include "colrpane.h" /* Resource symbolic identifiers*/
static HWND CreateColorPanel(HWND hwndParent, LONG Xpos, LONG Ypos, ULONG wndID,
ULONG colorID);
#define STRINGLENGTH 20 /* Length of string */
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndStatic1 = NULLHANDLE; /* Static box 1 window handle */
HWND hwndStatic2 = NULLHANDLE; /* Static box 2 window handle */
HWND hwndStatic3 = NULLHANDLE; /* Static box 3 window handle */
HWND hwndStatic4 = NULLHANDLE; /* Static box 4 window handle */
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 300, 330, /* and size 300, 330. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
LONG i;
switch( msg )
{
case WM_CREATE:
hwndStatic1 = CreateColorPanel(
hwnd, /* Parent window */
0, /* x position */
150, /* y position */
ID_STATIC1, /* Window identifier */
CLR_BLACK); /* Set the color here */
hwndStatic2 = CreateColorPanel(
hwnd, /* Parent window */
150, /* x position */
150, /* y position */
ID_STATIC2, /* Window identifier */
CLR_RED); /* Set the color here */
hwndStatic3 = CreateColorPanel(
hwnd, /* Parent window */
0, /* x position */
0, /* y position */
ID_STATIC3, /* Window identifier */
CLR_PINK); /* Set the color here */
hwndStatic4 = CreateColorPanel(
hwnd, /* Parent window */
150, /* x position */
0, /* y position */
ID_STATIC4, /* Window identifier */
CLR_YELLOW); /* Set the color here */
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
/*****************************************************************************
* This function emulates the subclass constructor in the Java Magercise.
*****************************************************************************/
static HWND CreateColorPanel(HWND hwndParent, LONG Xpos, LONG Ypos, ULONG wndID,
ULONG colorID)
{
HWND hwnd =
WinCreateWindow(
hwndParent, /* Parent window */
WC_STATIC, /* Window class */
"", /* Window text */
WS_VISIBLE | /* Make it visible */
SS_FGNDRECT, /* Static-text control */
Xpos, /* x position */
Ypos, /* y position */
150, /* Width */
150, /* Height */
hwndParent, /* Owner window */
HWND_TOP, /* Top of z-order */
wndID, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
WinSetPresParam(hwnd, PP_FOREGROUNDCOLORINDEX, sizeof(colorID), &colorID);
return hwnd;
}
Here's the Java code:
// Copyright 1996, MageLang Institute.
import java.awt.*;
public class ColoredPanes extends java.applet.Applet {
public void init() {
setLayout(new GridLayout(2,2));
add(new ColorCanvas(Color.black));
add(new ColorCanvas(Color.red));
add(new ColorCanvas(Color.orange));
add(new ColorCanvas(Color.yellow));
}
}
class ColorCanvas extends java.awt.Canvas {
private java.awt.Color color;
public ColorCanvas() {
super();
}
public ColorCanvas ( java.awt.Color color ) {
this.color = color;
}
public void paint(java.awt.Graphics g) {
g.setColor(color);
g.fillRect(0, 0, size().width, size().height);
return;
}
}
This example creates an applet that has buttons at all points of the
compass and the center position of a BorderLayout.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - CompassPoints
*
* This demo is intended for comparison with the CompassPoints.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "compspts.h"
ICON ID_WINDOW compspts.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - CompassPoints
*
* This demo is intended for comparison with the CompassPoints.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_BUTTON1 251
#define ID_BUTTON2 252
#define ID_BUTTON3 253
#define ID_BUTTON4 254
#define ID_BUTTON5 255
#define ID_WINDOW 256
#define ID_FILE 257
#define ID_EXITPROG 261
/*****************************************************************************
* OS/2 PM/C Language Demo - CompassPoints
*
* This demo is intended for comparison with the CompassPoints.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include "compspts.h" /* Resource symbolic identifiers*/
static HWND CreateButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID);
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndButton1 = NULLHANDLE; /* Button 1 window handle */
HWND hwndButton2 = NULLHANDLE; /* Button 2 window handle */
HWND hwndButton3 = NULLHANDLE; /* Button 3 window handle */
HWND hwndButton4 = NULLHANDLE; /* Button 4 window handle */
HWND hwndButton5 = NULLHANDLE; /* Button 5 window handle */
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 305, 345, /* and size 305, 345. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
LONG i;
switch( msg )
{
case WM_CREATE:
hwndButton1 = CreateButton(
hwnd, /* Parent window */
0, /* x position */
250, /* y position */
300, /* width */
50, /* height */
"North", /* Caption */
ID_BUTTON1); /* Window ID */
hwndButton2 = CreateButton(
hwnd, /* Parent window */
0, /* x position */
50, /* y position */
50, /* width */
200, /* height */
"West", /* Caption */
ID_BUTTON2); /* Window ID */
hwndButton3 = CreateButton(
hwnd, /* Parent window */
50, /* x position */
50, /* y position */
200, /* width */
200, /* height */
"Center", /* Caption */
ID_BUTTON3); /* Window ID */
hwndButton4 = CreateButton(
hwnd, /* Parent window */
250, /* x position */
50, /* y position */
50, /* width */
200, /* height */
"East", /* Caption */
ID_BUTTON4); /* Window ID */
hwndButton5 = CreateButton(
hwnd, /* Parent window */
0, /* x position */
0, /* y position */
300, /* width */
50, /* height */
"South", /* Caption */
ID_BUTTON5); /* Window ID */
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
/*****************************************************************************
* Convenience function to create buttons.
*****************************************************************************/
static HWND CreateButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID)
{
HWND hwnd =
WinCreateWindow(
hwndParent, /* Parent window */
WC_BUTTON, /* Window class */
Caption, /* Window text */
WS_VISIBLE |
BS_PUSHBUTTON |
BS_AUTOSIZE, /* Button style */
Xpos, /* x position */
Ypos, /* y position */
width, /* Width */
height, /* Height */
hwndParent, /* Owner window */
HWND_TOP, /* Top of z-order */
wndID, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
return hwnd;
}
Here's the Java code:
import java.applet.*;
import java.awt.*;
/**
* This applet was generated by a SmartGuide.
*
*/
public class CompassPoints extends Applet {
private Button ivjButton1 = null;
private Button ivjButton2 = null;
private Button ivjButton3 = null;
private Button ivjButton4 = null;
private Button ivjButton5 = null;
/**
* Gets the applet information.
* @return java.lang.String
*/
public String getAppletInfo() {
return "CompassPoints created using VisualAge for Java.";
}
/**
* Return the Button1 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton1() {
if (ivjButton1 == null) {
try {
ivjButton1 = new java.awt.Button();
ivjButton1.setName("Button1");
ivjButton1.setLabel("West");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton1;
}
/**
* Return the Button2 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton2() {
if (ivjButton2 == null) {
try {
ivjButton2 = new java.awt.Button();
ivjButton2.setName("Button2");
ivjButton2.setLabel("North");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton2;
}
/**
* Return the Button3 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton3() {
if (ivjButton3 == null) {
try {
ivjButton3 = new java.awt.Button();
ivjButton3.setName("Button3");
ivjButton3.setLabel("East");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton3;
}
/**
* Return the Button4 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton4() {
if (ivjButton4 == null) {
try {
ivjButton4 = new java.awt.Button();
ivjButton4.setName("Button4");
ivjButton4.setLabel("South");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton4;
}
/**
* Return the Button5 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton5() {
if (ivjButton5 == null) {
try {
ivjButton5 = new java.awt.Button();
ivjButton5.setName("Button5");
ivjButton5.setLabel("Center");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton5;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Handle the Applet init method.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void init() {
super.init();
try {
setName("CompassPoints");
setLayout(new java.awt.BorderLayout());
setSize(426, 240);
this.add("West", getButton1());
this.add("North", getButton2());
this.add("East", getButton3());
this.add("South", getButton4());
this.add("Center", getButton5());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
java.awt.Frame frame;
try {
Class aFrameClass = Class.forName("uvm.abt.edit.TestFrame");
frame = (java.awt.Frame)aFrameClass.newInstance();
} catch (java.lang.Throwable ivjExc) {
frame = new java.awt.Frame();
}
CompassPoints aCompassPoints = new CompassPoints();
frame.add("Center", aCompassPoints);
frame.setSize(aCompassPoints.getSize());
aCompassPoints.init();
aCompassPoints.start();
frame.setVisible(true);
aCompassPoints.destroy();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
}
}
}
This example uses Graphics methods to draw a stick figure.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - Drawing
*
* This demo is intended for comparison with the Drawing.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "drawing.h"
ICON ID_WINDOW drawing.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - Drawing
*
* This demo is intended for comparison with the Drawing.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_STATIC1 251
#define ID_STATIC2 252
#define ID_STATIC3 253
#define ID_STATIC4 254
#define ID_WINDOW 256
#define ID_FILE 257
#define ID_EXITPROG 261
/*****************************************************************************
* OS/2 PM/C Language Demo - Drawing
*
* This demo is intended for comparison with the Drawing.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include "drawing.h" /* Resource symbolic identifiers*/
void DrawStickBoy(HPS hps, INT xo);
#define STRINGLENGTH 20 /* Length of string */
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 300, 330, /* and size 300, 330. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
return 0;
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
static POINTL start;
static POINTL curr;
switch( msg )
{
case WM_CREATE:
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_PAINT:
/*
* Window contents are drawn here in WM_PAINT processing.
*/
{
HPS hps; /* Presentation Space handle */
RECTL rc; /* Rectangle coordinates */
/* Create a presentation space */
hps = WinBeginPaint( hwnd, 0L, &rc );
WinFillRect( hps, &rc, SYSCLR_WINDOW);
DrawStickBoy(hps,0);
DrawStickBoy(hps,100);
WinEndPaint( hps ); /* Drawing is complete */
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
/******************************************************************************
* Convenience function for drawing stick figure in presentation space.
******************************************************************************/
void DrawStickBoy(HPS hps, INT xo)
{
POINTL pt;
GpiSetColor(hps, CLR_BLUE);
pt.x = xo + 52; pt.y = 178;
GpiSetCurrentPosition(hps, &pt);
pt.x += 46; pt.y -= 74;
GpiBox(hps, DRO_FILL, &pt, 0, 0);
GpiSetColor(hps, CLR_BLACK);
pt.x = xo + 76; pt.y = 104;
GpiSetCurrentPosition(hps, &pt);
pt.x = xo + 43; pt.y = 40;
GpiLine(hps, &pt);
pt.x = xo + 76; pt.y = 104;
GpiSetCurrentPosition(hps, &pt);
pt.x = xo + 107; pt.y = 40;
GpiLine(hps, &pt);
pt.x = xo + 99; pt.y = 172;
GpiSetCurrentPosition(hps, &pt);
pt.x = xo + 134; pt.y = 200;
GpiLine(hps, &pt);
pt.x = xo + 52; pt.y = 172;
GpiSetCurrentPosition(hps, &pt);
pt.x = xo + 35; pt.y = 115;
GpiLine(hps, &pt);
pt.x = xo + 26; pt.y = 114;
GpiSetCurrentPosition(hps, &pt);
GpiFullArc(hps, DRO_OUTLINE, MAKEFIXED(8,0));
pt.x = xo + 134; pt.y = 210;
GpiSetCurrentPosition(hps, &pt);
GpiFullArc(hps, DRO_OUTLINE, MAKEFIXED(8,0));
pt.x = xo + 75; pt.y = 200;
GpiSetCurrentPosition(hps, &pt);
GpiFullArc(hps, DRO_OUTLINE, MAKEFIXED(16,0));
pt.x = xo + 36; pt.y = 40;
GpiSetCurrentPosition(hps, &pt);
pt.x += 16; pt.y -= 9;
GpiBox(hps, DRO_OUTLINE, &pt, 0, 0);
pt.x = xo + 99; pt.y = 40;
GpiSetCurrentPosition(hps, &pt);
pt.x += 16; pt.y -= 9;
GpiBox(hps, DRO_OUTLINE, &pt, 0, 0);
pt.x = xo + 55; pt.y = 12;
GpiSetCurrentPosition(hps, &pt);
GpiCharString(hps, 9, "Stick Boy");
}
And here's the Java code:
import java.applet.*;
import java.awt.*;
/**
* This applet was generated by a SmartGuide.
*
*/
public class Drawing extends Applet {
private StickyBoy ivjStickyBoy1 = null;
private StickyBoy ivjStickyBoy11 = null;
/**
* Gets the applet information.
* @return java.lang.String
*/
public String getAppletInfo() {
return "Drawing created using VisualAge for Java.";
}
/**
* Return the StickyBoy1 property value.
* @return StickyBoy
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private StickyBoy getStickyBoy1() {
if (ivjStickyBoy1 == null) {
try {
ivjStickyBoy1 = new StickyBoy();
ivjStickyBoy1.setName("StickyBoy1");
ivjStickyBoy1.setBounds(42, 45, 150, 150);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjStickyBoy1;
}
/**
* Return the StickyBoy11 property value.
* @return StickyBoy
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private StickyBoy getStickyBoy11() {
if (ivjStickyBoy11 == null) {
try {
ivjStickyBoy11 = new StickyBoy();
ivjStickyBoy11.setName("StickyBoy11");
ivjStickyBoy11.setBounds(234, 45, 150, 150);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjStickyBoy11;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Handle the Applet init method.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void init() {
super.init();
try {
setName("Drawing");
setLayout(null);
setSize(426, 240);
add(getStickyBoy1(), getStickyBoy1().getName());
add(getStickyBoy11(), getStickyBoy11().getName());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
java.awt.Frame frame;
try {
Class aFrameClass = Class.forName("uvm.abt.edit.TestFrame");
frame = (java.awt.Frame)aFrameClass.newInstance();
} catch (java.lang.Throwable ivjExc) {
frame = new java.awt.Frame();
}
Drawing aDrawing = new Drawing();
frame.add("Center", aDrawing);
frame.setSize(aDrawing.getSize());
aDrawing.init();
aDrawing.start();
frame.setVisible(true);
aDrawing.destroy();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
}
}
}
public StickyBoy() {
super();
}
/**
* This method was created by a SmartGuide.
* @param g java.awt.Graphics
*/
public void paint(Graphics g) {
g.setColor(Color.blue);
g.fillRect(52,52,46,74);
g.setColor(Color.black);
g.drawLine(76,126,43,190);
g.drawLine(76,126,107,190);
g.drawLine(99,58,134,30);
g.drawLine(52,58,35,115);
g.drawOval(26,114,12,12);
g.drawOval(134,20,12,12);
g.drawOval(63,27,27,25);
g.drawRect(36,190,16,8);
g.drawRect(99,190,16,9);
g.drawString("Stick Boy", 55,218);
return;
}
}
This example creates an applet containing a phone keypad full of buttons
laid out with GridLayout.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - PhonePad
*
* This demo is intended for comparison with the PhonePad.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "phonepad.h"
ICON ID_WINDOW phonepad.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - PhonePad
*
* This demo is intended for comparison with the PhonePad.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_BUTTON0 250
#define ID_BUTTON1 251
#define ID_BUTTON2 252
#define ID_BUTTON3 253
#define ID_BUTTON4 254
#define ID_BUTTON5 255
#define ID_BUTTON6 256
#define ID_BUTTON7 257
#define ID_BUTTON8 258
#define ID_BUTTON9 259
#define ID_BUTTONP 260
#define ID_BUTTONF 261
#define ID_WINDOW 266
#define ID_FILE 267
#define ID_EXITPROG 271
/*****************************************************************************
* OS/2 PM/C Language Demo - PhonePad
*
* This demo is intended for comparison with the PhonePad.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include "phonepad.h" /* Resource symbolic identifiers*/
static HWND CreateButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID);
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndButton0 = NULLHANDLE; /* Button 0 window handle */
HWND hwndButton1 = NULLHANDLE; /* Button 1 window handle */
HWND hwndButton2 = NULLHANDLE; /* Button 2 window handle */
HWND hwndButton3 = NULLHANDLE; /* Button 3 window handle */
HWND hwndButton4 = NULLHANDLE; /* Button 4 window handle */
HWND hwndButton5 = NULLHANDLE; /* Button 5 window handle */
HWND hwndButton6 = NULLHANDLE; /* Button 6 window handle */
HWND hwndButton7 = NULLHANDLE; /* Button 7 window handle */
HWND hwndButton8 = NULLHANDLE; /* Button 8 window handle */
HWND hwndButton9 = NULLHANDLE; /* Button 9 window handle */
HWND hwndButtonP = NULLHANDLE; /* Button # window handle */
HWND hwndButtonF = NULLHANDLE; /* Button * window handle */
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 200, 300, /* and size 200, 300. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
return 0;
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
LONG i;
switch( msg )
{
case WM_CREATE:
hwndButtonP = CreateButton(
hwnd, /* Parent window */
50, /* x position */
110, /* y position */
30, /* width */
30, /* height */
"#", /* Caption */
ID_BUTTONP); /* Window ID */
hwndButton0 = CreateButton(
hwnd, /* Parent window */
85, /* x position */
110, /* y position */
30, /* width */
30, /* height */
"0", /* Caption */
ID_BUTTON0); /* Window ID */
hwndButtonF = CreateButton(
hwnd, /* Parent window */
120, /* x position */
110, /* y position */
30, /* width */
30, /* height */
"*", /* Caption */
ID_BUTTONF); /* Window ID */
hwndButton1 = CreateButton(
hwnd, /* Parent window */
50, /* x position */
145, /* y position */
30, /* width */
30, /* height */
"1", /* Caption */
ID_BUTTON1); /* Window ID */
hwndButton2 = CreateButton(
hwnd, /* Parent window */
85, /* x position */
145, /* y position */
30, /* width */
30, /* height */
"2", /* Caption */
ID_BUTTON2); /* Window ID */
hwndButton3 = CreateButton(
hwnd, /* Parent window */
120, /* x position */
145, /* y position */
30, /* width */
30, /* height */
"3", /* Caption */
ID_BUTTON3); /* Window ID */
hwndButton4 = CreateButton(
hwnd, /* Parent window */
50, /* x position */
180, /* y position */
30, /* width */
30, /* height */
"4", /* Caption */
ID_BUTTON4); /* Window ID */
hwndButton5 = CreateButton(
hwnd, /* Parent window */
85, /* x position */
180, /* y position */
30, /* width */
30, /* height */
"5", /* Caption */
ID_BUTTON5); /* Window ID */
hwndButton6 = CreateButton(
hwnd, /* Parent window */
120, /* x position */
180, /* y position */
30, /* width */
30, /* height */
"6", /* Caption */
ID_BUTTON6); /* Window ID */
hwndButton7 = CreateButton(
hwnd, /* Parent window */
50, /* x position */
215, /* y position */
30, /* width */
30, /* height */
"7", /* Caption */
ID_BUTTON7); /* Window ID */
hwndButton8 = CreateButton(
hwnd, /* Parent window */
85, /* x position */
215, /* y position */
30, /* width */
30, /* height */
"8", /* Caption */
ID_BUTTON8); /* Window ID */
hwndButton9 = CreateButton(
hwnd, /* Parent window */
120, /* x position */
215, /* y position */
30, /* width */
30, /* height */
"9", /* Caption */
ID_BUTTON9); /* Window ID */
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
/*****************************************************************************
* Convenience function to create buttons.
*****************************************************************************/
static HWND CreateButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID)
{
HWND hwnd =
WinCreateWindow(
hwndParent, /* Parent window */
WC_BUTTON, /* Window class */
Caption, /* Window text */
WS_VISIBLE |
BS_PUSHBUTTON |
BS_AUTOSIZE, /* Button style */
Xpos, /* x position */
Ypos, /* y position */
width, /* Width */
height, /* Height */
hwndParent, /* Owner window */
HWND_TOP, /* Top of z-order */
wndID, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
return hwnd;
}
Here's the Java code:
import java.applet.*;
import java.awt.*;
/**
* This applet was generated by a SmartGuide.
*
*/
public class PhonePadTest extends Applet {
private Button ivjButton1 = null;
private Button ivjButton10 = null;
private Button ivjButton11 = null;
private Button ivjButton12 = null;
private Button ivjButton2 = null;
private Button ivjButton3 = null;
private Button ivjButton4 = null;
private Button ivjButton5 = null;
private Button ivjButton6 = null;
private Button ivjButton7 = null;
private Button ivjButton8 = null;
private Button ivjButton9 = null;
private GridLayout ivjPhonePadTestGridLayout = null;
/**
* Gets the applet information.
* @return java.lang.String
*/
public String getAppletInfo() {
return "PhonePadTest created using VisualAge for Java.";
}
/**
* Return the Button1 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton1() {
if (ivjButton1 == null) {
try {
ivjButton1 = new java.awt.Button();
ivjButton1.setName("Button1");
ivjButton1.setLabel("#");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton1;
}
/**
* Return the Button10 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton10() {
if (ivjButton10 == null) {
try {
ivjButton10 = new java.awt.Button();
ivjButton10.setName("Button10");
ivjButton10.setLabel("3");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton10;
}
/**
* Return the Button11 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton11() {
if (ivjButton11 == null) {
try {
ivjButton11 = new java.awt.Button();
ivjButton11.setName("Button11");
ivjButton11.setLabel("2");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton11;
}
/**
* Return the Button12 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton12() {
if (ivjButton12 == null) {
try {
ivjButton12 = new java.awt.Button();
ivjButton12.setName("Button12");
ivjButton12.setLabel("1");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton12;
}
/**
* Return the Button2 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton2() {
if (ivjButton2 == null) {
try {
ivjButton2 = new java.awt.Button();
ivjButton2.setName("Button2");
ivjButton2.setLabel("0");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton2;
}
/**
* Return the Button3 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton3() {
if (ivjButton3 == null) {
try {
ivjButton3 = new java.awt.Button();
ivjButton3.setName("Button3");
ivjButton3.setLabel("*");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton3;
}
/**
* Return the Button4 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton4() {
if (ivjButton4 == null) {
try {
ivjButton4 = new java.awt.Button();
ivjButton4.setName("Button4");
ivjButton4.setLabel("9");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton4;
}
/**
* Return the Button5 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton5() {
if (ivjButton5 == null) {
try {
ivjButton5 = new java.awt.Button();
ivjButton5.setName("Button5");
ivjButton5.setLabel("8");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton5;
}
/**
* Return the Button6 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton6() {
if (ivjButton6 == null) {
try {
ivjButton6 = new java.awt.Button();
ivjButton6.setName("Button6");
ivjButton6.setLabel("7");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton6;
}
/**
* Return the Button7 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton7() {
if (ivjButton7 == null) {
try {
ivjButton7 = new java.awt.Button();
ivjButton7.setName("Button7");
ivjButton7.setLabel("6");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton7;
}
/**
* Return the Button8 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton8() {
if (ivjButton8 == null) {
try {
ivjButton8 = new java.awt.Button();
ivjButton8.setName("Button8");
ivjButton8.setLabel("5");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton8;
}
/**
* Return the Button9 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton9() {
if (ivjButton9 == null) {
try {
ivjButton9 = new java.awt.Button();
ivjButton9.setName("Button9");
ivjButton9.setLabel("4");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton9;
}
/**
* Return the PhonePadTestGridLayout property value.
* @return java.awt.GridLayou
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private GridLayout getPhonePadTestGridLayout() {
java.awt.GridLayout ivjPhonePadTestGridLayout = null;
try {
/* Create part */
ivjPhonePadTestGridLayout = new java.awt.GridLayout(4, 3);
} catch (java.lang.Throwable ivjExc) {
handleException(ivjExc);
};
return ivjPhonePadTestGridLayout;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Handle the Applet init method.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void init() {
super.init();
try {
setName("PhonePadTest");
setLayout(getPhonePadTestGridLayout());
setSize(426, 240);
add(getButton12(), getButton12().getName());
add(getButton11(), getButton11().getName());
add(getButton10(), getButton10().getName());
add(getButton9(), getButton9().getName());
add(getButton8(), getButton8().getName());
add(getButton7(), getButton7().getName());
add(getButton6(), getButton6().getName());
add(getButton5(), getButton5().getName());
add(getButton4(), getButton4().getName());
add(getButton3(), getButton3().getName());
add(getButton2(), getButton2().getName());
add(getButton1(), getButton1().getName());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
java.awt.Frame frame;
try {
Class aFrameClass = Class.forName("uvm.abt.edit.TestFrame");
frame = (java.awt.Frame)aFrameClass.newInstance();
} catch (java.lang.Throwable ivjExc) {
frame = new java.awt.Frame();
}
PhonePadTest aPhonePadTest = new PhonePadTest();
frame.add("Center", aPhonePadTest);
frame.setSize(aPhonePadTest.getSize());
aPhonePadTest.init();
aPhonePadTest.start();
frame.setVisible(true);
aPhonePadTest.destroy();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
}
}
}
As was seen with the previous examples, many, if not most, GUIs can
be laid out using the flexible layout managers. Occasionally, though,
you may simply want to lay out your components in fixed positions and
sizes.
Although we do not recommend constructing user-interfaces in this
manner, this example nontheless lays out a number of components this
way for the purposes of illustration.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - XYLayou
*
* This demo is intended for comparison with the XYLayout.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "xylayout.h"
ICON ID_WINDOW xylayout.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - XYLayou
*
* This demo is intended for comparison with the XYLayout.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_STATIC1 250
#define ID_STATIC2 251
#define ID_BUTTON1 252
#define ID_BUTTON2 253
#define ID_BUTTON3 254
#define ID_BUTTON4 255
#define ID_BUTTON5 256
#define ID_WINDOW 257
#define ID_FILE 258
#define ID_EXITPROG 261
/*****************************************************************************
* OS/2 PM/C Language Demo - XYLayou
*
* This demo is intended for comparison with the XYLayout.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include "xylayout.h" /* Resource symbolic identifiers*/
static HWND CreateButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID);
static HWND CreateRadioButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID);
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndStatic1 = NULLHANDLE; /* Static 1 window handle */
HWND hwndStatic2 = NULLHANDLE; /* Static 2 window handle */
HWND hwndButton1 = NULLHANDLE; /* Button 1 window handle */
HWND hwndButton2 = NULLHANDLE; /* Button 2 window handle */
HWND hwndButton3 = NULLHANDLE; /* Button 3 window handle */
HWND hwndButton4 = NULLHANDLE; /* Button 4 window handle */
HWND hwndButton5 = NULLHANDLE; /* Button 5 window handle */
CHAR szStatic1[20] = "Small";
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 200, 250, /* and size 200, 250. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
return 0;
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
switch( msg )
{
case WM_CREATE:
hwndStatic1 = WinCreateWindow(
hwnd, /* Parent window */
WC_STATIC, /* Window class */
szStatic1, /* Window text */
WS_VISIBLE | /* Make it visible */
SS_TEXT | /* Static-text control */
DT_VCENTER | /* Center text vert. */
DT_LEFT, /* Left Justify horiz. */
95, /* x position */
170, /* y position */
75, /* Width */
20, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_STATIC1, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
hwndStatic2 = WinCreateWindow(
hwnd, /* Parent window */
WC_STATIC, /* Window class */
"Font Size : ", /* Window text */
WS_VISIBLE | /* Make it visible */
SS_TEXT | /* Static-text control */
DT_VCENTER | /* Center text vert. */
DT_RIGHT, /* Right Justify horiz. */
20, /* x position */
170, /* y position */
75, /* Width */
20, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_STATIC2, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
hwndButton1 = CreateRadioButton(
hwnd, /* Parent window */
20, /* x position */
140, /* y position */
100, /* width */
20, /* height */
"Small", /* Caption */
ID_BUTTON1); /* Window ID */
hwndButton2 = CreateRadioButton(
hwnd, /* Parent window */
20, /* x position */
110, /* y position */
100, /* width */
20, /* height */
"Medium", /* Caption */
ID_BUTTON2); /* Window ID */
hwndButton3 = CreateRadioButton(
hwnd, /* Parent window */
20, /* x position */
80, /* y position */
100, /* width */
20, /* height */
"Large", /* Caption */
ID_BUTTON3); /* Window ID */
hwndButton4 = CreateButton(
hwnd, /* Parent window */
120, /* x position */
130, /* y position */
60, /* width */
30, /* height */
"Quit", /* Caption */
ID_BUTTON4); /* Window ID */
hwndButton5 = CreateButton(
hwnd, /* Parent window */
120, /* x position */
90, /* y position */
60, /* width */
30, /* height */
"Submit", /* Caption */
ID_BUTTON5); /* Window ID */
/* Set button 1 to selected. */
WinSendMsg(hwndButton1, BM_SETCHECK, MPFROMSHORT(TRUE), (MPARAM)0);
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_CONTROL:
/*
* Handle the radio button selection notification
* message.
*/
{
USHORT control; /* WM_CONTROL control id */
control = SHORT1FROMMP(mp1); /* Extract the control id */
switch (control)
{
case ID_BUTTON1:
if (SHORT2FROMMP(mp1) == BN_CLICKED)
{
WinQueryWindowText(hwndButton1, sizeof(szStatic1), szStatic1);
WinSetWindowText(hwndStatic1,szStatic1);
}
break;
case ID_BUTTON2:
if (SHORT2FROMMP(mp1) == BN_CLICKED)
{
WinQueryWindowText(hwndButton2, sizeof(szStatic1), szStatic1);
WinSetWindowText(hwndStatic1,szStatic1);
}
break;
case ID_BUTTON3:
if (SHORT2FROMMP(mp1) == BN_CLICKED)
{
WinQueryWindowText(hwndButton3, sizeof(szStatic1), szStatic1);
WinSetWindowText(hwndStatic1,szStatic1);
}
}
}
break;
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
/*****************************************************************************
* Convenience function to create buttons.
*****************************************************************************/
static HWND CreateButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID)
{
HWND hwnd =
WinCreateWindow(
hwndParent, /* Parent window */
WC_BUTTON, /* Window class */
Caption, /* Window text */
WS_VISIBLE |
BS_PUSHBUTTON |
BS_AUTOSIZE, /* Button style */
Xpos, /* x position */
Ypos, /* y position */
width, /* Width */
height, /* Height */
hwndParent, /* Owner window */
HWND_TOP, /* Top of z-order */
wndID, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
return hwnd;
}
/*****************************************************************************
* Convenience function to create buttons.
*****************************************************************************/
static HWND CreateRadioButton(HWND hwndParent, LONG Xpos, LONG Ypos,
LONG width, LONG height, PCHAR Caption, ULONG wndID)
{
HWND hwnd =
WinCreateWindow(
hwndParent, /* Parent window */
WC_BUTTON, /* Window class */
Caption, /* Window text */
WS_VISIBLE |
BS_AUTORADIOBUTTON, /* Button style */
Xpos, /* x position */
Ypos, /* y position */
width, /* Width */
height, /* Height */
hwndParent, /* Owner window */
HWND_TOP, /* Top of z-order */
wndID, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
return hwnd;
}
Here's the Java code:
import java.applet.*;
import java.awt.*;
/**
* This applet was generated by a SmartGuide.
*
*/
public class XYLayout extends Applet {
private Button ivjButton11 = null;
private Label ivjLabel11 = null;
private TextField ivjTextField11 = null;
/**
* Gets the applet information.
* @return java.lang.String
*/
public String getAppletInfo() {
return "XYLayout created using VisualAge for Java.";
}
/**
* Return the Button11 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton11() {
if (ivjButton11 == null) {
try {
ivjButton11 = new java.awt.Button();
ivjButton11.setName("Button11");
ivjButton11.setBounds(150, 37, 125, 30);
ivjButton11.setLabel("Button1");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton11;
}
/**
* Return the Label11 property value.
* @return java.awt.Label
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Label getLabel11() {
if (ivjLabel11 == null) {
try {
ivjLabel11 = new java.awt.Label();
ivjLabel11.setName("Label11");
ivjLabel11.setText("Label1");
ivjLabel11.setBounds(150, 104, 125, 30);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjLabel11;
}
/**
* Return the TextField11 property value.
* @return java.awt.TextField
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private TextField getTextField11() {
if (ivjTextField11 == null) {
try {
ivjTextField11 = new java.awt.TextField();
ivjTextField11.setName("TextField11");
ivjTextField11.setBounds(150, 171, 125, 30);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjTextField11;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Handle the Applet init method.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void init() {
super.init();
try {
setName("XYLayout");
setLayout(null);
setSize(426, 240);
add(getTextField11(), getTextField11().getName());
add(getButton11(), getButton11().getName());
add(getLabel11(), getLabel11().getName());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
java.awt.Frame frame;
try {
Class aFrameClass = Class.forName("uvm.abt.edit.TestFrame");
frame = (java.awt.Frame)aFrameClass.newInstance();
} catch (java.lang.Throwable ivjExc) {
frame = new java.awt.Frame();
}
XYLayout aXYLayout = new XYLayout();
frame.add("Center", aXYLayout);
frame.setSize(aXYLayout.getSize());
aXYLayout.init();
aXYLayout.start();
frame.setVisible(true);
aXYLayout.destroy();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
}
}
}
This example creates an applet that can change it's background
color by having the user select a color via a ColorEditor bean.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - ColorLis
*
* This demo is intended for comparison with the ColorChoiceApplet.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "colorlst.h"
ICON ID_WINDOW colorlst.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - ColorLis
*
* This demo is intended for comparison with the ColorChoiceApplet.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_LISTWINDOW 250
#define ID_STATIC1 251
#define ID_STATIC2 252
#define ID_STATIC3 253
#define ID_WINDOW 256
#define ID_FILE 257
#define ID_EXITPROG 261
/*****************************************************************************
* OS/2 PM/C Language Demo - ColorLis
*
* This demo is intended for comparison with the ColorChoiceApplet.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include /* for strlen prototype */
#include "colorlst.h" /* Resource symbolic identifiers*/
#define STRINGLENGTH 20 /* Length of string */
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndComboBox = NULLHANDLE; /* Combo Box window handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndStatic1 = NULLHANDLE; /* Static label 1 window handle */
HWND hwndStatic2 = NULLHANDLE; /* Static label 2 window handle */
HWND hwndStatic3 = NULLHANDLE; /* Static box 3 window handle */
PCHAR szColors[] = {"black",
"red",
"green",
"blue",
"pink",
"yellow",
"gray",
NULL};
INT iColors[] = {CLR_BLACK,
CLR_RED,
CLR_GREEN,
CLR_BLUE,
CLR_PINK,
CLR_YELLOW,
CLR_PALEGRAY,
0};
CHAR szString[STRINGLENGTH];
CHAR szStatic1[] = "Color : ";
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 400, 300, /* and size 400, 300. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
return 0;
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
LONG i;
switch( msg )
{
case WM_CREATE:
hwndComboBox = WinCreateWindow(hwnd, /* Parent */
WC_COMBOBOX, /* Class */
"", /* Name */
WS_VISIBLE | LS_NOADJUSTPOS, /* Style */
10, 10, /* x, y */
110, 200, /* cx, cy */
hwnd, /* Owner */
HWND_TOP, /* Behind */
ID_LISTWINDOW, /* ID */
NULL, /* Control data */
NULL); /* parameters */
/* Disable updates while filling the list. */
WinEnableWindowUpdate(hwndComboBox, FALSE);
for (i = 0; szColors[i]; i++)
WinInsertLboxItem(hwndComboBox, i, szColors[i]);
/* Now cause the window to update and show the new information. */
WinShowWindow(hwndComboBox, TRUE);
hwndStatic1 = WinCreateWindow(
hwnd, /* Parent window */
WC_STATIC, /* Window class */
szStatic1, /* Window text */
WS_VISIBLE | /* Make it visible */
SS_TEXT | /* Static-text control */
DT_VCENTER | /* Center text vert. */
DT_RIGHT, /* Right Justify horiz. */
75, /* x position */
220, /* y position */
75, /* Width */
20, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_STATIC1, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
hwndStatic2 = WinCreateWindow(
hwnd, /* Parent window */
WC_STATIC, /* Window class */
szColors[0], /* Window text */
WS_VISIBLE | /* Make it visible */
SS_TEXT | /* Static-text control */
DT_VCENTER | /* Center text vert. */
DT_LEFT, /* Left Justify horiz. */
150, /* x position */
220, /* y position */
75, /* Width */
20, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_STATIC2, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
hwndStatic3 = WinCreateWindow(
hwnd, /* Parent window */
WC_STATIC, /* Window class */
"", /* Window text */
WS_VISIBLE | /* Make it visible */
SS_FGNDRECT, /* Static-text control */
150, /* x position */
100, /* y position */
100, /* Width */
100, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_STATIC3, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_CONTROL:
/*
* Handle the list box selection notification
* message.
*/
{
USHORT control; /* WM_CONTROL control id */
control = SHORT1FROMMP(mp1); /* Extract the control id */
switch (control)
{
case ID_LISTWINDOW:
if (SHORT2FROMMP(mp1) == CBN_EFCHANGE)
{
ULONG ulColorIndex = 3;
WinQueryWindowText(hwndComboBox, sizeof(szString), szString);
WinSetWindowText(hwndStatic2,szString);
for (i = 0; szColors[i] && strcmp(szString, szColors[i]) != 0 ; i++);
if (szColors[i])
{
ulColorIndex = (ULONG)iColors[i];
WinSetPresParam(hwndStatic3,PP_FOREGROUNDCOLORINDEX,
sizeof(ulColorIndex), &ulColorIndex);
}
}
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
Here's the Java code:
import java.applet.*;
import java.awt.*;
/**
* This applet was generated by a SmartGuide.
*
*/
public class ColorList extends Applet implements java.awt.event.ActionListener {
private Button ivjButton1 = null;
private sun.beans.editors.ColorEditor ivjColorEditor1 = null;
/**
* Method to handle events for the ActionListener interface.
* @param e java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void actionPerformed(java.awt.event.ActionEvent e) {
// user code begin {1}
// user code end
if ((e.getSource() == getButton1()) ) {
conn0(e);
}
// user code begin {2}
// user code end
}
/**
* conn0: (Button1.action.actionPerformed(java.awt.event.ActionEvent) -->
ColorList.background)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn0(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
this.setBackground((java.awt.Color)getColorEditor1().getValue());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* Gets the applet information.
* @return java.lang.String
*/
public String getAppletInfo() {
return "ColorList created using VisualAge for Java.";
}
/**
* Return the Button1 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton1() {
if (ivjButton1 == null) {
try {
ivjButton1 = new java.awt.Button();
ivjButton1.setName("Button1");
ivjButton1.setBounds(94, 227, 151, 32);
ivjButton1.setLabel("Button1");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton1;
}
/**
* Return the ColorEditor1 property value.
* @return sun.beans.editors.ColorEditor
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private sun.beans.editors.ColorEditor getColorEditor1() {
if (ivjColorEditor1 == null) {
try {
ivjColorEditor1 = new sun.beans.editors.ColorEditor();
ivjColorEditor1.setName("ColorEditor1");
ivjColorEditor1.setBounds(28, 121, 324, 38);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjColorEditor1;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Handle the Applet init method.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void init() {
super.init();
try {
setName("ColorList");
setLayout(null);
setSize(439, 408);
add(getButton1(), getButton1().getName());
add(getColorEditor1(), getColorEditor1().getName());
initConnections();
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* Initializes connections
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() {
// user code begin {1}
// user code end
getButton1().addActionListener(this);
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
java.awt.Frame frame;
try {
Class aFrameClass = Class.forName("uvm.abt.edit.TestFrame");
frame = (java.awt.Frame)aFrameClass.newInstance();
} catch (java.lang.Throwable ivjExc) {
frame = new java.awt.Frame();
}
ColorList aColorList = new ColorList();
frame.add("Center", aColorList);
frame.setSize(aColorList.getSize());
aColorList.init();
aColorList.start();
frame.setVisible(true);
aColorList.destroy();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
}
}
}
This example creates an applet that creates and shows a FileDialog. I
uses the file property of a FileDialog bean to obtain the selected
file name and display it in a textfield on the applet.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - DisplayFileDialog
*
* This demo is intended for comparison with the DisplayFileDialog.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "dispfdlg.h"
ICON ID_WINDOW dispfdlg.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "~Open", ID_FILEOPEN, MIS_TEXT
MENUITEM "E~xit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - DisplayFileDialog
*
* This demo is intended for comparison with the DisplayFileDialog.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_STATIC1 250
#define ID_STATIC2 251
#define ID_FILEOPEN 252
#define ID_WINDOW 256
#define ID_FILE 257
#define ID_EXITPROG 261
/*****************************************************************************
* OS/2 PM/C Language Demo - DisplayFileDialog
*
* This demo is intended for comparison with the DisplayFileDialog.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#define INCL_DOSFILEMGR
#define INCL_DOSERRORS
#include /* PM header file */
#include /* for strlen prototype */
#include "dispfdlg.h" /* Resource symbolic identifiers*/
static BOOL DoFileDialog(HWND hwnd, PCHAR pchFile);
#define STRINGLENGTH 200 /* Length of string */
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndStatic1 = NULLHANDLE; /* Static label 1 window handle */
HWND hwndStatic2 = NULLHANDLE; /* Static label 2 window handle */
CHAR szStatic1[] = "Filename : ";
CHAR szStatic2[STRINGLENGTH] = "";
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 400, 200, /* and size 400, 200. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
return 0;
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
switch( msg )
{
case WM_CREATE:
hwndStatic1 = WinCreateWindow(
hwnd, /* Parent window */
WC_STATIC, /* Window class */
szStatic1, /* Window text */
WS_VISIBLE | /* Make it visible */
SS_TEXT | /* Static-text control */
DT_VCENTER | /* Center text vert. */
DT_RIGHT, /* Right Justify horiz. */
15, /* x position */
120, /* y position */
75, /* Width */
20, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_STATIC1, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
hwndStatic2 = WinCreateWindow(
hwnd, /* Parent window */
WC_STATIC, /* Window class */
szStatic2, /* Window text */
WS_VISIBLE | /* Make it visible */
SS_TEXT | /* Static-text control */
DT_VCENTER | /* Center text vert. */
DT_LEFT, /* Left Justify horiz. */
30, /* x position */
90, /* y position */
350, /* Width */
20, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_STATIC2, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_FILEOPEN:
if (DoFileDialog(hwnd, szStatic2))
WinSetWindowText(hwndStatic2,szStatic2);
break;
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
/*****************************************************************************
* Convenience function to display the file dialog for us.
*****************************************************************************/
static BOOL DoFileDialog(HWND hwnd, PCHAR pchFile)
{
FILEDLG FileDlg;
memset(&FileDlg, 0, sizeof(FILEDLG));
FileDlg.cbSize = sizeof(FILEDLG);
FileDlg.fl = FDS_CENTER | FDS_OPEN_DIALOG | FDS_PRELOAD_VOLINFO;
if (WinFileDlg(HWND_DESKTOP, hwnd, &FileDlg) != DID_OK)
{
WinAlarm(HWND_DESKTOP, WA_ERROR);
return FALSE;
}
strcpy(pchFile, FileDlg.szFullFile);
return TRUE;
}
Here's the Java code:
import java.applet.*;
import java.awt.*;
/**
* This applet was generated by a SmartGuide.
*
*/
public class DisplayFileDialog extends Applet
implements java.awt.event.ActionListener {
private Button ivjButton1 = null;
private FileDialog ivjFileDialog1 = null;
private Label ivjLabel1 = null;
private TextField ivjTextField1 = null;
/**
* Method to handle events for the ActionListener interface.
* @param e java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void actionPerformed(java.awt.event.ActionEvent e) {
// user code begin {1}
// user code end
if ((e.getSource() == getButton1()) ) {
conn0(e);
}
if ((e.getSource() == getButton1()) ) {
conn1(e);
}
if ((e.getSource() == getButton1()) ) {
conn2(e);
}
// user code begin {2}
// user code end
}
/**
* conn0: (Button1.action.actionPerformed(java.awt.event.ActionEvent) -->
FileDialog1.show())
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn0(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getFileDialog1().show();
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn1: (Button1.action.actionPerformed(java.awt.event.ActionEvent) -->
FileDialog1.dispose())
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn1(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getFileDialog1().dispose();
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn2: (Button1.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn2(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getFileDialog1().getFile());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* Gets the applet information.
* @return java.lang.String
*/
public String getAppletInfo() {
return "DisplayFileDialog created using VisualAge for Java.";
}
/**
* Return the Button1 property value.
* @return java.awt.Button
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Button getButton1() {
if (ivjButton1 == null) {
try {
ivjButton1 = new java.awt.Button();
ivjButton1.setName("Button1");
ivjButton1.setBounds(28, 172, 125, 30);
ivjButton1.setLabel("Select a file");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjButton1;
}
/**
* Return the FileDialog1 property value.
* @return java.awt.FileDialog
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private FileDialog getFileDialog1() {
if (ivjFileDialog1 == null) {
try {
ivjFileDialog1 = new java.awt.FileDialog(new java.awt.Frame());
ivjFileDialog1.setName("FileDialog1");
ivjFileDialog1.setLayout(null);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjFileDialog1;
}
/**
* Return the Label1 property value.
* @return java.awt.Label
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Label getLabel1() {
if (ivjLabel1 == null) {
try {
ivjLabel1 = new java.awt.Label();
ivjLabel1.setName("Label1");
ivjLabel1.setText("File Selected:");
ivjLabel1.setBounds(29, 24, 125, 30);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjLabel1;
}
/**
* Return the TextField1 property value.
* @return java.awt.TextField
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private TextField getTextField1() {
if (ivjTextField1 == null) {
try {
ivjTextField1 = new java.awt.TextField();
ivjTextField1.setName("TextField1");
ivjTextField1.setBounds(186, 24, 125, 30);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjTextField1;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Handle the Applet init method.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void init() {
super.init();
try {
setName("DisplayFileDialog");
setLayout(null);
setSize(426, 240);
add(getButton1(), getButton1().getName());
add(getLabel1(), getLabel1().getName());
add(getTextField1(), getTextField1().getName());
initConnections();
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* Initializes connections
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() {
// user code begin {1}
// user code end
getButton1().addActionListener(this);
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
java.awt.Frame frame;
try {
Class aFrameClass = Class.forName("uvm.abt.edit.TestFrame");
frame = (java.awt.Frame)aFrameClass.newInstance();
} catch (java.lang.Throwable ivjExc) {
frame = new java.awt.Frame();
}
DisplayFileDialog aDisplayFileDialog = new DisplayFileDialog();
frame.add("Center", aDisplayFileDialog);
frame.setSize(aDisplayFileDialog.getSize());
aDisplayFileDialog.init();
aDisplayFileDialog.start();
frame.setVisible(true);
aDisplayFileDialog.destroy();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
}
}
}
This example illustrates the technique called
double-buffering, which is used to achieve smooth screen updates for
drawing and animation. This is accomplished by performing redraws in a
background buffer (thus hiding it from the viewer), which is then in
one smooth motion, copied to the visible drawing buffer.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - DoubleBuffer
*
* This demo is intended for comparison with the DoubleBuffer.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "doublbfr.h"
ICON ID_WINDOW doublbfr.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - DoubleBuffer
*
* This demo is intended for comparison with the DoubleBuffer.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_STATIC1 251
#define ID_STATIC2 252
#define ID_STATIC3 253
#define ID_STATIC4 254
#define ID_WINDOW 256
#define ID_FILE 257
#define ID_EXITPROG 261
/*****************************************************************************
* OS/2 PM/C Language Demo - DoubleBuffer
*
* This demo is intended for comparison with the DoubleBuffer.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include "doublbfr.h" /* Resource symbolic identifiers*/
#define STRINGLENGTH 20 /* Length of string */
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 300, 330, /* and size 300, 330. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
return 0;
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
static POINTL start;
static POINTL curr;
static BOOL track = FALSE;
switch( msg )
{
case WM_CREATE:
break;
case WM_BUTTON1DOWN:
WinSetActiveWindow(HWND_DESKTOP, hwnd);
start.x = SHORT1FROMMP(mp1);
start.y = SHORT2FROMMP(mp1);
track = TRUE;
break;
case WM_MOUSEMOVE:
curr.x = SHORT1FROMMP(mp1);
curr.y = SHORT2FROMMP(mp1);
WinInvalidateRegion(hwnd, 0L, FALSE);
break;
case WM_BUTTON1UP:
track = FALSE;
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_PAINT:
/*
* Window contents are drawn here in WM_PAINT processing.
*/
{
HPS hps; /* Presentation Space handle */
RECTL rc; /* Rectangle coordinates */
if (track)
{ /* Create a presentation space */
hps = WinBeginPaint( hwnd, 0L, &rc );
WinFillRect( hps, &rc, SYSCLR_WINDOW);
GpiSetCurrentPosition(hps, &start);
GpiSetColor( hps, CLR_NEUTRAL ); /* colour of the text, */
GpiSetBackColor( hps, CLR_BACKGROUND ); /* its background and */
GpiSetBackMix( hps, BM_OVERPAINT ); /* how it mixes, */
GpiBox( hps, DRO_OUTLINE, &curr, 0, 0); /* and draw the box */
WinEndPaint( hps ); /* Drawing is complete */
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
/*****************************************************************************
* This function emulates the subclass constructor in the Java Magercise.
*****************************************************************************/
static HWND CreateColorPanel(HWND hwndParent, LONG Xpos, LONG Ypos, ULONG wndID,
ULONG colorID)
{
HWND hwnd =
WinCreateWindow(
hwndParent, /* Parent window */
WC_STATIC, /* Window class */
"", /* Window text */
WS_VISIBLE | /* Make it visible */
SS_FGNDRECT, /* Static-text control */
Xpos, /* x position */
Ypos, /* y position */
150, /* Width */
150, /* Height */
hwndParent, /* Owner window */
HWND_TOP, /* Top of z-order */
wndID, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
WinSetPresParam(hwnd, PP_FOREGROUNDCOLORINDEX, sizeof(colorID), &colorID);
return hwnd;
}
And here's the Java code:
// Copyright 1996, MageLang Institute.
import java.awt.*;
import java.applet.Applet;
public class DoubleBuffer extends Applet {
public void init() {
SimpleDrawingRegion r = new SimpleDrawingRegion(this,
200,
200);
add(r);
}
}
// Copyright 1996, MageLang Institute.
import java.awt.*;
public class SimpleDrawingRegion extends Canvas {
protected int drawingAreaWidth;
protected int drawingAreaHeight;
private java.applet.Applet applet;
protected static Color backgroundColor = Color.white;
protected static Color drawColor = Color.black;
protected static Color dragColor = Color.red;
// a double buffer to record old rectangles
protected Image buffer;
protected Graphics bufferGr;
protected int downX, downY; // where the mouse goes down at start of draw
protected int w=0,h=0; // how wide is the rectangle?
public SimpleDrawingRegion(java.applet.Applet applet, int w, int h) {
this.applet = applet;
drawingAreaWidth = w;
drawingAreaHeight = h;
resize(w,h);
setBackground(backgroundColor);
// create the drawing area
buffer = applet.createImage(drawingAreaWidth, drawingAreaHeight);
bufferGr = buffer.getGraphics();
// make the double-buffer white so it is consistent across platforms
bufferGr.setColor(Color.white);
bufferGr.fillRect(0,0,drawingAreaWidth, drawingAreaHeight);
// draw in black
bufferGr.setColor(drawColor);
repaint();
}
/** Clip the x,y coordinate to with [1,w-1],[1-h] */
protected Point clip(int x, int y) {
if ( x>=drawingAreaWidth ) x = drawingAreaWidth-2;
else if ( x<1 ) x = 1;
if ( y>=drawingAreaHeight ) y = drawingAreaHeight-2;
else if ( y<1 ) y = 1;
return new Point(x,y);
}
/** Set a corner of the bounding box enclosing tool */
public boolean mouseDown(Event e, int x, int y) {
downX = x;
downY = y;
w = h = 0;
return true; // say that we handled this even
}
/** Draw (rubberband) on screen buffer */
public boolean mouseDrag(Event e, int x, int y) {
int xorColor = backgroundColor.getRGB() ^ dragColor.getRGB();
Graphics g = getGraphics(); // graphics perspective on canvas
g.setXORMode(new Color(xorColor));
g.drawRect(downX, downY, w, h); // draw over old one to erase i
// compute new w, h (clip so can't leave drawing region)
Point clipped = clip(x,y);
w = clipped.x-downX;
h = clipped.y-downY;
// can't have negative w,h; can only drag down,righ
if ( w<0 ) {
w=0;
}
if ( h<0 ) {
h=0;
}
// NO REPAINT, we use XORing to leave the background alone!
g.drawRect(downX, downY, w, h); // draw new one at new location
return true;
}
/** Draw the rectangle on the background buffer and repaint */
public boolean mouseUp(Event e, int x, int y) {
bufferGr.drawRect(downX, downY, w, h);
repaint();
return true;
}
/**Make the double-buffer appear in the applet window.
*/
public void paint(Graphics g) {
g.drawImage(buffer, 0, 0, this);
g.drawRect(0,0,drawingAreaWidth-1,drawingAreaHeight-1);
}
/** Normally update erases then calls paint. Erasing is
* a waste of time as we paste a whole background image to screen.
*/
public void update(Graphics g) {
paint(g);
}
}
This example creates an applet that constructs a Frame containing a
"File" menu, and a "Help" menu.
Here's the OS/2 C source code:
/*****************************************************************************
* OS/2 PM/C Language Demo - Menus
*
* This demo is intended for comparison with the Menus.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#include
#include "menus.h"
ICON ID_WINDOW menus.ico
MENU ID_WINDOW PRELOAD
BEGIN
SUBMENU "~File", ID_FILE
BEGIN
MENUITEM "Open", ID_OPENFILE, MIS_TEXT
MENUITEM "Close", ID_CLOSEFILE, MIS_TEXT
MENUITEM "Exit", ID_EXITPROG, MIS_TEXT
END
SUBMENU "~Help", ID_HELPITEM1, MIS_TEXT
BEGIN
MENUITEM "Fundamentals", ID_HELPITEM2, MIS_TEXT
MENUITEM "Advanced", ID_HELPITEM3, MIS_TEXT
MENUITEM SEPARATOR
MENUITEM "Have Read The Manual", ID_HELPITEM4, MIS_TEXT
MENUITEM "Have Read The Tutorial", ID_HELPITEM5, MIS_TEXT
SUBMENU "Misc", ID_HELPITEM6, MIS_TEXT
BEGIN
MENUITEM "Help!!!", ID_HELPITEM7, MIS_TEXT
MENUITEM "Why Did That Happen?", ID_HELPITEM8, MIS_TEXT
END
END
END
ACCELTABLE ID_WINDOW PRELOAD
BEGIN
VK_F3, ID_EXITPROG, VIRTUALKEY
END
/*****************************************************************************
* OS/2 PM/C Language Demo - Menus
*
* This demo is intended for comparison with the Menus.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#pragma linkage (main,optlink)
INT main(VOID);
extern VOID AbortProgram(HWND hwndFrame,HWND hwndClient);
#define MSGBOXID 1001
#define ID_LISTBOX1 250
#define ID_WINDOW 251
#define ID_FILE 258
#define ID_OPENFILE 260
#define ID_CLOSEFILE 261
#define ID_EXITPROG 262
#define ID_HELPITEM1 271
#define ID_HELPITEM2 272
#define ID_HELPITEM3 273
#define ID_HELPITEM4 274
#define ID_HELPITEM5 275
#define ID_HELPITEM6 276
#define ID_HELPITEM7 277
#define ID_HELPITEM8 278
#define ID_HELPITEM9 279
/*****************************************************************************
* OS/2 PM/C Language Demo - Menus
*
* This demo is intended for comparison with the MenuTest.java
* Magercise.
*
* Copyright 1997, MageLang Institute.
******************************************************************************/
#define INCL_WIN
#define INCL_GPI
#include /* PM header file */
#include /* for strcpy, strcat */
#include /* for sprintf */
#include "menus.h" /* Resource symbolic identifiers*/
/*
* Function prototypes
*/
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 );
/* Define parameters by type */
HAB hab; /* PM anchor block handle */
HWND hwndFrame = NULLHANDLE; /* Frame window handle */
HWND hwndClient = NULLHANDLE; /* Client area window handle */
HWND hwndListBox1 = NULLHANDLE; /* List Box 1 window handle */
CHAR szMenu1[40] = "";
CHAR szWork[100] = "";
PSZ pszErrMsg;
INT main (VOID)
{
HMQ hmq; /* Message queue handle */
QMSG qmsg; /* Message from message queue */
ULONG flCreate; /* Window creation control flags*/
if ((hab = WinInitialize(0)) == 0L) /* Initialize PM */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if ((hmq = WinCreateMsgQueue( hab, 0 )) == 0L)/* Create a msg queue */
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
if (!WinRegisterClass( /* Register window class */
hab, /* Anchor block handle */
(PSZ)"MyWindow", /* Window class name */
(PFNWP)MyWindowProc, /* Address of window procedure */
CS_SIZEREDRAW, /* Class style */
0 /* No extra window words */
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
flCreate = FCF_STANDARD & /* Set frame control flags to */
~FCF_SHELLPOSITION; /* standard except for shell */
/* positioning. */
if ((hwndFrame = WinCreateStdWindow(
HWND_DESKTOP, /* Desktop window is parent */
0, /* STD. window styles */
&flCreate, /* Frame control flag */
"MyWindow", /* Client window class name */
"", /* No window text */
0, /* No special class style */
(HMODULE)0L, /* Resource is in .EXE file */
ID_WINDOW, /* Frame window identifier */
&hwndClient /* Client window handle */
)) == 0L)
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
WinSetWindowText(hwndFrame, "MageLang OS/2 Sample");
if (!WinSetWindowPos( hwndFrame, /* Shows and activates frame */
HWND_TOP, /* window at position 100, 100, */
100, 100, 500, 400, /* and size 500, 400. */
SWP_SIZE | SWP_MOVE | SWP_ACTIVATE | SWP_SHOW
))
AbortProgram(hwndFrame, hwndClient); /* Terminate the application */
/*
* Get and dispatch messages from the application message queue
* until WinGetMsg returns FALSE, indicating a WM_QUIT message.
*/
while( WinGetMsg( hab, &qmsg, 0L, 0, 0 ) )
WinDispatchMsg( hab, &qmsg );
WinDestroyWindow(hwndFrame); /* Tidy up... */
WinDestroyMsgQueue( hmq ); /* Tidy up... */
WinTerminate( hab ); /* Terminate the application */
return 0;
} /* End of main */
MRESULT EXPENTRY MyWindowProc( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 )
{
static INT LboxNum =0;
switch( msg )
{
case WM_CREATE:
hwndListBox1 = WinCreateWindow(
hwnd, /* Parent window */
WC_LISTBOX, /* Window class */
"", /* Window text */
WS_VISIBLE | /* Make it visible */
LS_NOADJUSTPOS, /* List Box Options */
20, /* x position */
20, /* y position */
400, /* Width */
300, /* Height */
hwnd, /* Owner window */
HWND_TOP, /* Top of z-order */
ID_LISTBOX1, /* Window identifier */
NULL, /* Control data */
NULL); /* Presentation parameters*/
break;
case WM_COMMAND:
/*
* When Exit is chosen, the application posts itself a WM_CLOSE
* message.
*/
{
USHORT command; /* WM_COMMAND command value */
command = SHORT1FROMMP(mp1); /* Extract the command value */
switch (command)
{
case ID_OPENFILE:
case ID_CLOSEFILE:
{
MENUITEM mi;
HWND hwndSrc;
HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
WinSendMsg(hwndMenu, /* Handle of menu bar */
MM_QUERYITEMTEXT, /* Message */
MPFROM2SHORT(command, 32), /* Submenu identifier */
szMenu1); /* Pointer to String */
sprintf(szWork, "Selected FileMenu %s", szMenu1);
WinInsertLboxItem(hwndListBox1, LIT_END, szWork);
}
break;
case ID_HELPITEM1:
case ID_HELPITEM2:
case ID_HELPITEM3:
case ID_HELPITEM4:
case ID_HELPITEM5:
case ID_HELPITEM6:
case ID_HELPITEM7:
case ID_HELPITEM8:
{
MENUITEM mi;
HWND hwndSrc;
HWND hwndMenu = WinWindowFromID(hwndFrame, FID_MENU);
WinSendMsg(hwndMenu, /* Handle of menu bar */
MM_QUERYITEMTEXT, /* Message */
MPFROM2SHORT(command, 32), /* Submenu identifier */
szMenu1); /* Pointer to String */
WinInsertLboxItem(hwndListBox1, LIT_END, szMenu1);
}
break;
case ID_EXITPROG:
WinPostMsg( hwnd, WM_CLOSE, (MPARAM)0, (MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
break;
}
case WM_ERASEBACKGROUND:
/*
* Return TRUE to request PM to paint the window background
* in SYSCLR_WINDOW.
*/
return (MRESULT)( TRUE );
case WM_CLOSE:
/*
* This is the place to put termination routines
*/
WinPostMsg( hwnd, WM_QUIT, (MPARAM)0,(MPARAM)0 );
break;
default:
return WinDefWindowProc( hwnd, msg, mp1, mp2 );
}
return (MRESULT)FALSE;
} /* End of MyWindowProc */
VOID AbortProgram(HWND hwndFrame, HWND hwndClient)
{
PERRINFO pErrInfoBlk;
PSZ pszOffSet;
void stdprint(void);
DosBeep(100,10);
if ((pErrInfoBlk = WinGetErrorInfo(hab)) != (PERRINFO)NULL)
{
pszOffSet = ((PSZ)pErrInfoBlk) + pErrInfoBlk->offaoffszMsg;
pszErrMsg = ((PSZ)pErrInfoBlk) + *((PSHORT)pszOffSet);
if((INT)hwndFrame && (INT)hwndClient)
WinMessageBox(HWND_DESKTOP, /* Parent window is desk top */
hwndFrame, /* Owner window is our frame */
(PSZ)pszErrMsg, /* PMWIN Error message */
"Error Msg", /* Title bar message */
MSGBOXID, /* Message identifier */
MB_MOVEABLE | MB_CUACRITICAL | MB_CANCEL ); /* Flags */
WinFreeErrorInfo(pErrInfoBlk);
}
WinPostMsg(hwndClient, WM_QUIT, (MPARAM)NULL, (MPARAM)NULL);
} /* End */
Here's the Java code:
import java.applet.*;
import java.awt.*;
/**
* This applet was generated by a SmartGuide.
*
*/
public class MenuTest extends Applet
implements java.awt.event.ActionListener,
java.awt.event.ComponentListener,
java.awt.event.ItemListener {
private CheckboxMenuItem ivjCheckboxMenuItem1 = null;
private CheckboxMenuItem ivjCheckboxMenuItem2 = null;
private Frame ivjFrame1 = null;
private MenuBar ivjFrame1MenuBar = null;
private Menu ivjMenu1 = null;
private Menu ivjMenu2 = null;
private Menu ivjMenu3 = null;
private MenuItem ivjMenuItem1 = null;
private MenuItem ivjMenuItem2 = null;
private MenuItem ivjMenuItem3 = null;
private MenuItem ivjMenuItem4 = null;
private MenuItem ivjMenuItem5 = null;
private MenuItem ivjMenuItem6 = null;
private MenuItem ivjMenuItem7 = null;
private MenuItem ivjMenuItem8 = null;
private TextField ivjTextField1 = null;
/**
* Method to handle events for the ActionListener interface.
* @param e java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void actionPerformed(java.awt.event.ActionEvent e) {
// user code begin {1}
// user code end
if ((e.getSource() == getMenuItem3()) ) {
conn1(e);
}
if ((e.getSource() == getMenuItem2()) ) {
conn3(e);
}
if ((e.getSource() == getMenuItem1()) ) {
conn5(e);
}
if ((e.getSource() == getMenuItem5()) ) {
conn7(e);
}
if ((e.getSource() == getMenuItem4()) ) {
conn9(e);
}
if ((e.getSource() == getMenuItem8()) ) {
conn15(e);
}
if ((e.getSource() == getMenuItem7()) ) {
conn17(e);
}
// user code begin {2}
// user code end
}
/**
* Method to handle events for the ComponentListener interface.
* @param e java.awt.event.ComponentEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void componentHidden(java.awt.event.ComponentEvent e) {
// user code begin {1}
// user code end
// user code begin {2}
// user code end
}
/**
* Method to handle events for the ComponentListener interface.
* @param e java.awt.event.ComponentEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void componentMoved(java.awt.event.ComponentEvent e) {
// user code begin {1}
// user code end
// user code begin {2}
// user code end
}
/**
* Method to handle events for the ComponentListener interface.
* @param e java.awt.event.ComponentEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void componentResized(java.awt.event.ComponentEvent e) {
// user code begin {1}
// user code end
// user code begin {2}
// user code end
}
/**
* Method to handle events for the ComponentListener interface.
* @param e java.awt.event.ComponentEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void componentShown(java.awt.event.ComponentEvent e) {
// user code begin {1}
// user code end
if ((e.getSource() == this) ) {
conn0(e);
}
// user code begin {2}
// user code end
}
/**
* conn0: (MenuTest.component.componentShown(java.awt.event.ComponentEvent) -->
Frame1.show())
* @param arg1 java.awt.event.ComponentEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn0(java.awt.event.ComponentEvent arg1) {
try {
// user code begin {1}
// user code end
getFrame1().show();
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn1: (MenuItem3.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn1(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getMenuItem3().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn11: (CheckboxMenuItem1.item.itemStateChanged(java.awt.event.ItemEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ItemEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn11(java.awt.event.ItemEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getCheckboxMenuItem1().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn13: (CheckboxMenuItem2.item.itemStateChanged(java.awt.event.ItemEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ItemEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn13(java.awt.event.ItemEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getCheckboxMenuItem2().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn15: (MenuItem8.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn15(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getMenuItem8().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn17: (MenuItem7.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn17(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getMenuItem7().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn3: (MenuItem2.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn3(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getMenuItem2().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn5: (MenuItem1.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn5(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getMenuItem1().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn7: (MenuItem5.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn7(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getMenuItem5().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* conn9: (MenuItem4.action.actionPerformed(java.awt.event.ActionEvent) -->
TextField1.text)
* @param arg1 java.awt.event.ActionEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void conn9(java.awt.event.ActionEvent arg1) {
try {
// user code begin {1}
// user code end
getTextField1().setText(getMenuItem4().getLabel());
// user code begin {2}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {3}
// user code end
handleException(ivjExc);
}
}
/**
* Gets the applet information.
* @return java.lang.String
*/
public String getAppletInfo() {
return "MenuTest created using VisualAge for Java.";
}
/**
* Return the CheckboxMenuItem1 property value.
* @return java.awt.CheckboxMenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private CheckboxMenuItem getCheckboxMenuItem1() {
if (ivjCheckboxMenuItem1 == null) {
try {
ivjCheckboxMenuItem1 = new java.awt.CheckboxMenuItem();
ivjCheckboxMenuItem1.setLabel("Have read the manual");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjCheckboxMenuItem1;
}
/**
* Return the CheckboxMenuItem2 property value.
* @return java.awt.CheckboxMenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private CheckboxMenuItem getCheckboxMenuItem2() {
if (ivjCheckboxMenuItem2 == null) {
try {
ivjCheckboxMenuItem2 = new java.awt.CheckboxMenuItem();
ivjCheckboxMenuItem2.setLabel("Have read the tutorial");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjCheckboxMenuItem2;
}
/**
* Return the Frame1 property value.
* @return java.awt.Frame
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Frame getFrame1() {
if (ivjFrame1 == null) {
try {
ivjFrame1 = new java.awt.Frame();
ivjFrame1.setName("Frame1");
ivjFrame1.setMenuBar(getFrame1MenuBar());
ivjFrame1.setLayout(null);
ivjFrame1.setBounds(60, 269, 426, 240);
ivjFrame1.add(getTextField1(), getTextField1().getName());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjFrame1;
}
/**
* Return the Frame1MenuBar property value.
* @return java.awt.MenuBar
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuBar getFrame1MenuBar() {
if (ivjFrame1MenuBar == null) {
try {
ivjFrame1MenuBar = new java.awt.MenuBar();
ivjFrame1MenuBar.add(getMenu1());
ivjFrame1MenuBar.add(getMenu2());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjFrame1MenuBar;
}
/**
* Return the Menu1 property value.
* @return java.awt.Menu
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Menu getMenu1() {
if (ivjMenu1 == null) {
try {
ivjMenu1 = new java.awt.Menu();
ivjMenu1.setLabel("File");
ivjMenu1.add(getMenuItem3());
ivjMenu1.add(getMenuItem2());
ivjMenu1.add(getMenuItem1());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenu1;
}
/**
* Return the Menu2 property value.
* @return java.awt.Menu
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Menu getMenu2() {
if (ivjMenu2 == null) {
try {
ivjMenu2 = new java.awt.Menu();
ivjMenu2.setLabel("Help");
ivjMenu2.add(getMenuItem5());
ivjMenu2.add(getMenuItem4());
ivjMenu2.add(getMenuItem6());
ivjMenu2.add(getCheckboxMenuItem1());
ivjMenu2.add(getCheckboxMenuItem2());
ivjMenu2.add(getMenu3());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenu2;
}
/**
* Return the Menu3 property value.
* @return java.awt.Menu
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private Menu getMenu3() {
if (ivjMenu3 == null) {
try {
ivjMenu3 = new java.awt.Menu();
ivjMenu3.setLabel("Misc");
ivjMenu3.add(getMenuItem8());
ivjMenu3.add(getMenuItem7());
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenu3;
}
/**
* Return the MenuItem1 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem1() {
if (ivjMenuItem1 == null) {
try {
ivjMenuItem1 = new java.awt.MenuItem();
ivjMenuItem1.setLabel("Exit");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem1;
}
/**
* Return the MenuItem2 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem2() {
if (ivjMenuItem2 == null) {
try {
ivjMenuItem2 = new java.awt.MenuItem();
ivjMenuItem2.setLabel("Close");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem2;
}
/**
* Return the MenuItem3 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem3() {
if (ivjMenuItem3 == null) {
try {
ivjMenuItem3 = new java.awt.MenuItem();
ivjMenuItem3.setLabel("Open");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem3;
}
/**
* Return the MenuItem4 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem4() {
if (ivjMenuItem4 == null) {
try {
ivjMenuItem4 = new java.awt.MenuItem();
ivjMenuItem4.setLabel("Advanced");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem4;
}
/**
* Return the MenuItem5 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem5() {
if (ivjMenuItem5 == null) {
try {
ivjMenuItem5 = new java.awt.MenuItem();
ivjMenuItem5.setLabel("Fundamentals");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem5;
}
/**
* Return the MenuItem6 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem6() {
if (ivjMenuItem6 == null) {
try {
ivjMenuItem6 = new java.awt.MenuItem();
ivjMenuItem6.setLabel("-");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem6;
}
/**
* Return the MenuItem7 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem7() {
if (ivjMenuItem7 == null) {
try {
ivjMenuItem7 = new java.awt.MenuItem();
ivjMenuItem7.setLabel("Sub-item2");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem7;
}
/**
* Return the MenuItem8 property value.
* @return java.awt.MenuItem
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private MenuItem getMenuItem8() {
if (ivjMenuItem8 == null) {
try {
ivjMenuItem8 = new java.awt.MenuItem();
ivjMenuItem8.setLabel("Sub-item1");
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjMenuItem8;
}
/**
* Return the TextField1 property value.
* @return java.awt.TextField
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private TextField getTextField1() {
if (ivjTextField1 == null) {
try {
ivjTextField1 = new java.awt.TextField();
ivjTextField1.setName("TextField1");
ivjTextField1.setBounds(80, 81, 125, 30);
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
};
return ivjTextField1;
}
/**
* Called whenever the part throws an exception.
* @param exception java.lang.Throwable
*/
private void handleException(Throwable exception) {
/* Uncomment the following lines to print uncaught exceptions to stdout */
// System.out.println("--------- UNCAUGHT EXCEPTION ---------");
// exception.printStackTrace(System.out);
}
/**
* Handle the Applet init method.
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void init() {
super.init();
try {
setName("MenuTest");
setLayout(null);
setSize(426, 240);
initConnections();
// user code begin {1}
// user code end
} catch (java.lang.Throwable ivjExc) {
// user code begin {2}
// user code end
handleException(ivjExc);
}
}
/**
* Initializes connections
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void initConnections() {
// user code begin {1}
// user code end
this.addComponentListener(this);
getMenuItem3().addActionListener(this);
getMenuItem2().addActionListener(this);
getMenuItem1().addActionListener(this);
getMenuItem5().addActionListener(this);
getMenuItem4().addActionListener(this);
getCheckboxMenuItem1().addItemListener(this);
getCheckboxMenuItem2().addItemListener(this);
getMenuItem8().addActionListener(this);
getMenuItem7().addActionListener(this);
}
/**
* Method to handle events for the ItemListener interface.
* @param e java.awt.event.ItemEven
*/
/* WARNING: THIS METHOD WILL BE REGENERATED. */
public void itemStateChanged(java.awt.event.ItemEvent e) {
// user code begin {1}
// user code end
if ((e.getSource() == getCheckboxMenuItem1()) ) {
conn11(e);
}
if ((e.getSource() == getCheckboxMenuItem2()) ) {
conn13(e);
}
// user code begin {2}
// user code end
}
/**
* main entrypoint - starts the part when it is run as an application
* @param args java.lang.String[]
*/
public static void main(java.lang.String[] args) {
try {
java.awt.Frame frame;
try {
Class aFrameClass = Class.forName("uvm.abt.edit.TestFrame");
frame = (java.awt.Frame)aFrameClass.newInstance();
} catch (java.lang.Throwable ivjExc) {
frame = new java.awt.Frame();
}
MenuTest aMenuTest = new MenuTest();
frame.add("Center", aMenuTest);
frame.setSize(aMenuTest.getSize());
aMenuTest.init();
aMenuTest.start();
frame.setVisible(true);
aMenuTest.destroy();
} catch (Throwable exception) {
System.err.println("Exception occurred in main() of java.applet.Applet");
}
}
}
|