Documentation Tutorial
API
Download

OOIT.com
Let's start with the ubiques Hello World example

First we need a HelloTrivialWorld bean. It has a HelloWorld label and a add button. The add button is ment to create another HelloTrivialWorld bean. (The number of worlds are reflected with a static counter.)

Remark: This class is just a regular bean. It has no JBFrame code what so ever!

			
public class HelloTrivialWorldBean extends JPanel
{
  public JButton addBt = new JButton("create a new world");
    
  private static int counter;
    
  public HelloTrivialWorldBean()
  {
    super(new BorderLayout(0,0));
    JLabel helloWorldLb = new JLabel("Hello World Nr. " + counter);
    counter ++;
    helloWorldLb.setFont(new Font("Helvetica", Font.BOLD, 24));
    helloWorldLb.setHorizontalAlignment(JLabel.CENTER);
    add(helloWorldLb, BorderLayout.CENTER);
    add(addBt, BorderLayout.SOUTH);
  }
    
  public JButton getAddButton()
  {
    return addBt;
  }
    
}

The following screen shows this bean in a regular JFrame:

  Now the next step will be, that we implement an adapter which will add this bean to the JBFrame and whenever the "create a new word" button is pressed, a sub-node with another HelloTrivialWorld bean is added and displayed.
 
   
   The adapter code for that example looks as follows:
 
			
public class HelloTrivialWorldBeanAdapter 
  
  extends JBDefaultAdapter 
  
  implements ActionListener
  
{
  // static counter
  private static int counter;
  
  private JBFrame jbframe;
  
  // the private instance of the bean in this adapter
  private HelloTrivialWorldBean helloTrivialWorldBean;
    
  public HelloTrivialWorldBeanAdapter(JBAdapter parent)
  {
    helloTrivialWorldBean = new HelloTrivialWorldBean();
    jbframe = JBDefaultFrame.getInstance();
    // setting the protected fields from the JBDefaultAdapter
    
    
    // the label which is displayed in the tree
    setLabel("HTW: " + counter);
    
    counter ++;
    
    // the display component is the bean itself
    setDisplayComponent(helloTrivialWorldBean);
      
    // this class is listening the bean add button for adding another
    // adapter
    helloTrivialWorldBean.getAddButton().addActionListener(this);
    setParent(parent);
  }
    
  public void actionPerformed(ActionEvent ae)
  {
    if (ae.getSource() == helloTrivialWorldBean.getAddButton())
    {
      // creating another adapter
      HelloTrivialWorldBeanAdapter next = new HelloTrivialWorldBeanAdapter(this);
      // adding it to the frame (jbframe == a protected field of the JBDefaultAdapter
      jbframe.addNode(next);
      // show the node
      jbframe.gotoNode(next);
    }
  }
   Putting the JBFrame and an instance of the JBAdapter together:
 
  
  public static void main(String a[])
  {
    // Setting the default nice icons of JBDefaultFrame
    JBDefaultFrame.initTreeIcons();
    
    // creating the JFrame (the JBFrame is only a lightweight component !)
    JFrame fr = new JFrame("HelloTrivialWorldBean");
      
    // get an instance of the JBFame
    JBDefaultFrame jbframe = JBDefaultFrame.getInstance();
    // create an initial adapter and add it to the JBFrame
    HelloTrivialWorldBeanAdapter htwa = new HelloTrivialWorldBeanAdapter(null);
    jbframe.addNode(htwa);
      
    // setting a default toolbar 
    JToolBar defaultToolbar = new JToolBar();
    (defaultToolbar.add(jbframe.new ExitAction())).setToolTipText("Exit Hello Trivial World");
    jbframe.setToolbar(defaultToolbar);
      
    // setting the JBFrame menu bar into the JFrame
    fr.setJMenuBar(jbframe.getMenuBar());
    
    // go to the initial node
    jbframe.gotoNode(htwa);
    
    // adding the jbframe component to the JFrame
    fr.getContentPane().add(jbframe);
    fr.setSize(new Dimension(500,300));
    fr.setVisible(true);
  }
   The TrivialWorld Example is part of the regular download.
   
  Last update : 24. August 2000 (c) 2000 OOIT.com AG