|
Example1
// AFCExample1.java
//
import java.awt.*;
import com.ms.ui.*;
import com.ms.fx.*;
public class AFCExample1 extends AwtUIApplet
{
public AFCExample1 ()
{
super (new AFCExample1Implementation ());
}
// Stand-alone application only: entry point
public static void main(String args[])
{
// Create a frame to contain applet
AFCExample1Frame f = new AFCExample1Frame ("AFC Example 1");
f.setVisible (true);
f.setSize (320, 200);
// Create instance of applet and add to frame
AFCExample1Implementation applet = new AFCExample1Implementation ();
f.add (applet);
// Stand-alone application must explicitly call init()
applet.init ();
}
}
class AFCExample1Implementation extends UIApplet
{
// Applet entry point
public void init()
{
setBackground (FxColor.lightGray);
setLayout (new UIBorderLayout ());
add (new AFCExample1Panel ());
setValid (true);
}
}
// Stand-alone application only.
class AFCExample1Frame extends UIFrame
{
// Constructor
public AFCExample1Frame(String str)
{
super (str);
}
public boolean handleEvent (Event e)
{
switch (e.id)
{
case Event.WINDOW_DESTROY:
// Frame window closed, exit app
System.exit (0);
return true;
default:
return super.handleEvent (e);
}
}
}
class AFCExample1Panel extends UIPanel
{
private UIPanel p;
private UIPushButton b1, b2;
private UIStatus s;
// Constructor
public AFCExample1Panel ()
{
setLayout (new UIBorderLayout ());
// Create panel to contain buttons
p = new UIPanel ();
// Create buttons and add to ButtonPanel
p.add (b1 = new UIPushButton ("Red", UIPushButton.RAISED));
p.add (b2 = new UIPushButton ("Blue", UIPushButton.RAISED));
b1.setBackground (FxColor.lightGray);
b2.setBackground (FxColor.lightGray);
// Create status bar control
s = new UIStatus ("This is a UIStatus control.");
s.setBackground (FxColor.lightGray);
// Add button panel and status bar to AFCExample1Panel
add (p, "Center");
add (s, "South");
}
// Action event handler
public boolean action (Event e, Object o)
{
if (o == b1)
{
p.setBackground (FxColor.red);
p.repaint ();
s.setName ("Background color changed to red.");
}
else if (o == b2)
{
p.setBackground (FxColor.blue);
p.repaint ();
s.setName ("Background color changed to blue.");
}
return true;
}
public boolean handleEvent (Event e)
{
if ((e.id == Event.MOUSE_ENTER) && (e.target instanceof UIPushButton))
{
s.setName ("UIPushbutton object: MOUSE_ENTER event.");
return true;
}
else
{
return super.handleEvent (e);
}
}
}
|