Java


List

Una List e' un elemento grafico costituito da una serie di righe all'interno di una area scrollabile (se necessario), consente la selezione di un Item tra quelli selezionabili (e' pero' possibile eseguire anche selezioni multiple).
In altri linguaggi, come Visual Basic, viene definito ListBox.

La classe List e' descritta nella documentazione come:
"Una lista scollabile di voci testuali."

Costruttori

Metodi

Examples

  public void testChoice()
  {
  }

Choice

Un Choice e' un elemento grafico che sostanzialmente assomiglia ad un Menu, consente la selezione di un Item tra quelli selezionabili.
In altri linguaggi, come Visual Basic, viene definito ComboBox.
Cliccando sul tasto a destra del Choice viene presentato l'elenco degli item da cui scegliere il desiderato.
Con un Choice e' possibile scegliere una sola tra piu' scelte.

Examples

  public void testChoice()
  {
    Button bu_ok     = new Button( "   OK   " );
    Choice ch_one    = new Choice();
    Choice ch_two    = new Choice();

    dlg = new DialogBase( form.frame, "testChoice", true );
    dlg.setSize( 400, 300 );
    dlg.setLayout( new FlowLayout() );

    // add listeners
    // bu_ok.addActionListener( this );
    ch_one.addItemListener( this );
    ch_two.addItemListener( this );

    ch_one.setName( "ONE" );          // set name of Choice
    ch_one.add( "1" );                // add items
    ch_one.add( "2" );
    ch_one.add( "3" );

    ch_two.setName( "TWO" );          // set name of Choice
    ch_two.add( "A" );                // add items
    ch_two.add( "B" );
    ch_two.add( "C" );

    // add objects to the Dialog
    dlg.add( ch_one );
    dlg.add( ch_two );
    dlg.add( bu_ok );

    dlg.setVisible( true );
  }

  // manage Choices
  public void itemStateChanged( ItemEvent e )
  {
    if( e.getSource() instanceof Choice )
    {
      String obj  = ((Component)e.getSource()).getName();
      String item = (String) e.getItem();
      if( obj.equals( "ONE" ) )
      {
        if( item.equals( "1" ) ) System.out.println( "(UNO:1)" );
        if( item.equals( "2" ) ) System.out.println( "(UNO:2)" );
        if( item.equals( "3" ) ) System.out.println( "(UNO:3)" );
      }
      else if( obj.equals( "TWO" ) )
      {
        if( item.equals( "A" ) ) System.out.println( "(UNO:A)" );
        if( item.equals( "B" ) ) System.out.println( "(UNO:B)" );
        if( item.equals( "C" ) ) System.out.println( "(UNO:C)" );
      }
    }
  }

Applets and Applications

La differenza tra un Applet e' una Applicazione e' data dalla differente dichiarazione della classe principale.
Nel caso di un Applet, si prevede che sia attivato all'interno di un browser del linguaggio html, come tale necessita della seguente dichiarativa:
public class XXX extends Applet
{
  public void init() {
    ...
  }
}
La prima riga indichera' al browser che la classe dovra' ereditare le caratteristiche della classe Applet.
Nel caso di una Applicazione deve esistere il metodo main perche' la JVM sappia come attivare l'istanza del programma:
public class XXX
{
  public static void main( String args[] ) {
    xxx  =  new XXX();
    ...
  }
}

Examples

public class XXX extends Applet
{
  static    XXX      xxx;
  GUI       gui;

  //----------------------------------------------------------------------------
  // main for start as applet
  public void init() {
    gui  =  new GUI();
  }

  //----------------------------------------------------------------------------
  // main for start as standalone application
  public static void main( String args[] ) {
    xxx  =  new XXX();
    xxx.init();
  }
}

Size

Use javac -O. This inlines functions (which makes the bytecode bigger) and removes line numbers (which makes it smaller). Unless you use lots of inlinable functions, the removal of line numbers will dominate and your bytecode will get smaller. However, note that things can sometimes be inlined when they shouldn't -- see the compilers page for details.

Varie

Center a Window

  Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
  awindow.move(   ( screen.width  - awindow.size().width  ) / 2,
                  ( screen.height - awindow.size().height ) / 2  );