ClassX is a Lightweight Java GUI alternative to Swing.



Download all source code and images in one zipped file (click on image)


JAVA ClassX GUI Framework  
Overview
An overview of the ClassX Implementation. Includes an explanation of Main.java and the Menu classes.
   
Menu.java
An outline of how to use each of the menu java files, defining the makeup of each display page on the applet.
   
Main.java
An outline of how to use the main commanding class file that controls the whole GUI.
   
ClassX.java
An outline of how to use any of the ClassX class files that control the GUI.
   

JAVA ClassX Components  
ScrollTree
The ScrollTree Component.
   
ScrollList
The ScrollList Component.
   
TextArea
A full set of components that can be used as an alternative to Swing.
   
PieChart
A full set of components that can be used as an alternative to Swing.
   
BarChart
A full set of components that can be used as an alternative to Swing.
   
Button
A full set of components that can be used as an alternative to Swing.
   
CheckBox
A full set of components that can be used as an alternative to Swing.
   
ImageLabel
A full set of components that can be used as an alternative to Swing.
   

 

 


Overview

ClassX is a Lightweight Java GUI alternative to Swing.

ClassX was written as a pretty GUI that would run on Java 1.x machines, without the need for Swing to be installed. For the most part this has been achieved, it is also very small (50k jar file for the demonstartion applet without the images). For the most part I believe it's quite attractive as an interface, especially with the pie and bar chart components, though I feel a lot could be done with it's appearance, if anyone out there wants to skin or beatify it please go ahead. Part of the reason for giving out the source code and graphics for this project is so maybe someone will do just that. If you do please let me know at the email address at the bottom of this page.


The code is free to download, if anyone wants to adapt/improve/change it please go ahead, all I ask is if you could let me know if you do anything quite interesting with it.

Menu.java
The class that defines a page of the GUI.

Each display page of the final GUI is defined in a single java Menu file. I have used the convention that each display page is of the form _____Menu.java so I instantly know which pages are display pages, you can use any convention you want. In a java Menu page the display page is defined in terms of it's components and is functionality is programmed, below is an example (the TextArea display page from the demonstration).

public class DemoTextMenu extends ClassX {

TextArea T1,T2,T3;

public DemoTextMenu(Main parent) {

this.parent=parent;
title="TextArea";
uid="text";

T1=new TextArea(parent,parent.oG,10,60,200,30,16,0);
T2=new TextArea(parent,parent.oG,10,100,200,30,16,1);
T3=new TextArea(parent,parent.oG,10,150,480,160,1250,0);

Classes.addElement(T1);
Classes.addElement(T2);
Classes.addElement(T3);

}

public void setup() {

T1.append("A TextArea.",1);
T2.append("1234567890",1);
T3.append("Hello.",1);


}

public void update(boolean flag) {
}

public void fire(int idn,String sel) {

switch (idn) {
case 0: System.out.println("Pressed Enter in First Text Field");
    break;
case 1: System.out.println("Pressed Enter in Second Text Field");
    break;
case 2: System.out.println("Pressed Enter in Third Text Field");
    break;
}

}

}

As with all files except Main.java all files extend ClassX.java.

First(in blue) the name of this display page is defined, how it will appear on the screen ("TextArea") and how it will be defined within the program ("text"). Then components to be used are defined (in red), and added to the screen (light green). A number of functions are carried out in the setup method (in orange). And finally in dark Green there is the fire method, which catches interaction from the user for all three components, a case statement for each component (if a button is pressed or a list item chosen it triggers the fire method).

In this example the fire method prints out a line of text, but of course this would be different for each page.


Main.java
The controlling class file that runs the GUI.

On the whole, an applet can be written without the need for really any changes to the Main.java source. There are however some changes that must be made. Each page of the tabbed display is created in a java file usually with the Menu.java extension, each one of these display pages to be used must be included in the setup and setMenu methods of Main.java.


public void setup() {


Classes.removeAllElements();
Classes.addElement(new DemoVariousMenu(this));
Classes.addElement(new DemoListMenu(this));
Classes.addElement(new DemoTextMenu(this));
Classes.addElement(new DemoPieMenu(this));
Classes.addElement(new DemoBarMenu(this));

for (int loop=0;loop<Classes.size();loop++)
    ((ClassX)Classes.elementAt(loop)).setup();

setMenu("0");
update=true;
mode=1;

}

public void setMenu(String sel) {

if (sel.intern()==currentMenu.intern()) return;
for (int loop=0;loop<Classes.size();loop++) {
    ((ClassX)Classes.elementAt(loop)).setVisible(false);
}
if (sel.intern()=="0".intern()) {
    ((ClassX)Classes.elementAt(0)).setVisible(true);
    ((ClassX)Classes.elementAt(1)).setVisible(true);
    ((ClassX)Classes.elementAt(2)).setVisible(true);
    ((ClassX)Classes.elementAt(3)).setVisible(true);
    ((ClassX)Classes.elementAt(4)).setVisible(true);
    ((ClassX)Classes.elementAt(0)).select();
}

currentMenu=sel;
updateBar();
update=true;

}

Here is a excerpt of a listing of Main.java taken from the demonstration applet, each of the display pages to be used are intialised in blue, their order being the order they will appear on the tabs. In red then next a menu is defined, all display pages to be used being set visible, and the one showing to be selected. This can be done for any number of menus, of arrangements of display pages, from within a menu page you then simply call parent.setMenu("1"); say for menu "1" definition. Likewise if you want to access the components/methods of another display page say the display page DemoTextMenu.java (from within another display page), defined within the code as "text" and you want to run a method called setup() you can call ((DemoTextMenu)parent.get("text")).setup();

ClassX.java

The class that defines each component of a page.

Each display page and component extends the class ClassX, and as such has various methods associated with it.
For example a ScrollList called S1 can be enabled or disabled using :-

S1.enable();
S1.disable();

Similarly a display page has the method onLeave for when a user leaves the page, by putting this method in a ____Menu.java file it will be called when the page is left.

Main.java
The controlling class file that runs the GUI.

On the whole, an applet can be written without the need for really any changes to the Main.java source. There are however some changes that must be made. Each page of the tabbed display is created in a java file usually with the Menu.java extension, each one of these display pages to be used must be included in the setup and setMenu methods of Main.java.


public void setup() {


Classes.removeAllElements();
Classes.addElement(new DemoVariousMenu(this));
Classes.addElement(new DemoListMenu(this));
Classes.addElement(new DemoTextMenu(this));
Classes.addElement(new DemoPieMenu(this));
Classes.addElement(new DemoBarMenu(this));

for (int loop=0;loop<Classes.size();loop++)
    ((ClassX)Classes.elementAt(loop)).setup();

setMenu("0");
update=true;
mode=1;

}

public void setMenu(String sel) {

if (sel.intern()==currentMenu.intern()) return;
for (int loop=0;loop<Classes.size();loop++) {
    ((ClassX)Classes.elementAt(loop)).setVisible(false);
}
if (sel.intern()=="0".intern()) {
    ((ClassX)Classes.elementAt(0)).setVisible(true);
    ((ClassX)Classes.elementAt(1)).setVisible(true);
    ((ClassX)Classes.elementAt(2)).setVisible(true);
    ((ClassX)Classes.elementAt(3)).setVisible(true);
    ((ClassX)Classes.elementAt(4)).setVisible(true);
    ((ClassX)Classes.elementAt(0)).select();
}

currentMenu=sel;
updateBar();
update=true;

}

Here is a excerpt of a listing of Main.java taken from the demonstration applet, each of the display pages to be used are intialised in blue, their order being the order they will appear on the tabs. In red then next a menu is defined, all display pages to be used being set visible, and the one showing to be selected. This can be done for any number of menus, of arrangements of display pages, from within a menu page you then simply call parent.setMenu("1"); say for menu "1" definition. Likewise if you want to access the components/methods of another display page say the display page DemoTextMenu.java (from within another display page), defined within the code as "text" and you want to run a method called setup() you can call ((DemoTextMenu)parent.get("text")).setup();

ScrollTree
The controlling class file that runs the GUI.



This component can be created using

S1=new ScrollTree(parent,parent.oG,10,40,200,200,list);

Arguments :-

parent (always present)
parent.oG (always present)
10,40 (The x and y position on the page)
200,200 (The width and height of the component)
list (a vector containing details of the tree, made up from items)

ScrollTree S1;
Vector list=new Vector();
Vector list1=new Vector();
Vector list2=new Vector();
Vector list3=new Vector();
Vector list4=new Vector();
Vector list5=new Vector();
Image pic0,pic1,pic2,pic3;

pic0=parent.getImage("base.gif");
pic1=parent.getImage("folder.gif");
pic2=parent.getImage("openfolder.gif");
pic3=parent.getImage("page.gif");
//parent.getImage is called to load various images for use in the tree

list2.addElement(new item("ScrollList","1",null,2,false,pic3,pic3));
list2.addElement(new item("ScrollTree","2",null,2,false,pic3,pic3));
//An item is made by creating a new item with arguments
//Its title on the screen
//Its selection value (when selected the value it returns)
//A vector of it descendants
//It's type (0 for the base,1 for a folder,2 for a selectable page)
//Whether its open or closed (true or false)
//The picture to be used when open
//The picture to be used when closed

list3.addElement(new item("TextArea","3",null,2,false,pic3,pic3));

list4.addElement(new item("Pie Chart","4",null,2,false,pic3,pic3));
list4.addElement(new item("Trends Chart","5",null,2,false,pic3,pic3));

list5.addElement(new item("Button","6",null,2,false,pic3,pic3));
list5.addElement(new item("CheckBox","7",null,2,false,pic3,pic3));
list5.addElement(new item("ImageLabel","8",null,2,false,pic3,pic3));

list1.addElement(new item("List Components","0",list2,1,false,pic1,pic2));
list1.addElement(new item("Text Components","0",list3,1,false,pic1,pic2));
list1.addElement(new item("Graph Components","0",list4,1,false,pic1,pic2));
list1.addElement(new item("Other Components","0",list5,1,false,pic1,pic2));

list.addElement(new item("ClassX Components","0",list1,0,true,pic0,pic0));
//The main list is made up of vectors of vectors,
//each branching out to the vector below it

S1=new ScrollTree(parent,parent.oG,10,40,200,200,list);

Its selection is then captured in the fire method.

ScrollList
The ScrollList component.



This component can be created using

S1=new ScrollList(parent,parent.oG,20,50,460,60,list);

Arguments :-

parent (always present)
parent.oG (always present)
20,50 (The x and y position on the page)
460,60 (The width and height of the component)
list (a vector containing details of the list, made up from items)


ScrollList S2;
Vector list2=new Vector();
Image pic0,pic1,pic2,pic3;

pic0=parent.getImage("base.gif");
pic1=parent.getImage("folder.gif");
pic2=parent.getImage("openfolder.gif");
pic3=parent.getImage("page.gif");
//parent.getImage is called to load various images for use in the list

for (int loop=0;loop<50;loop++) {
    list2.addElement(new item("List Item "+loop,""+loop,"0",(loop%4==0)?pic0:(loop%4==1)?pic1:(loop%4==2)?pic2:pic3));
}

//An item is made by creating a new item with arguments
//Its title on the screen
//Its selection value (when selected the value it returns)
//It's type, irrelevent here
//The picture to be associated with it

S2=new ScrollList(parent,parent.oG,20,130,220,170,list2);

S2.unSelect(true);
S2.Pics(true);
S2.setMultiple(true);
S2.DblClick(false);


The lists type is then set as -

S2.unSelect(true);

can unselect a list item when it is clicked when already selected.

S2.Pics(true);

Pictures are associated wih each item

S2.setMultiple(true);

It is to have multiple selection properties

S2.DblClick(false);

It can be selected with a single (not double) click

Default is single click, single selection without pictures.

For a single selection list in the fire method the selected item can be refered to as :-
(item)S2.names.elementAt(S2.selected)

For a multiple selection list in the fire method it's selection is a vector and has to be obtained using:-
Vector selectionlist=S2.catchMultiple();

TextArea
The TextArea Component.



Under Construction.

Pie Chart
The PieChart Component.



Under Construction.

Bar Chart
The BarChart Component.



Under Construction.

Button
The Button Component.


This component can be created using

B1=new Button(parent,parent.oG,10,250,"Button 1",0,220);

Arguments :-

parent (always present)
parent.oG (always present)
10,250 (The x and y position on the page)
"Button 1" (The text on the front of the button)
0 (A value 0 indicating left alignment, 1 indicating center alignment, 2 indicating right alignment)
220 (The x width across which to align the button)

If pressed the method fire is called.

CheckBox
The CheckBox Component.



This component can be created using

C1=new CheckBox(parent,parent.oG,100,250,false);

Arguments :-

parent (always present)
parent.oG (always present)
100,250 (The x and y position on the page)
false (Its initial state, checked or unchecked, in this case unchecked)

The methods
C1.set(true) or C1.set(false) can also be used on this component.

If pressed the method fire is called. Its value is determined by C1.get() which returns true or false.

ImageLabel
The ImageLabel Component.



This component can be created using

I1=new ImageLabel(parent,"ClassX.gif",255,250);

Arguments :-

parent (always present)
"ClassX.gif" (the name of the gif/jpg image to be shown)
255,250 (The x and y position on the page)

The method fire is not called for this component.