classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cp-patches] New example code for demos


From: Mark Wielaard
Subject: [cp-patches] New example code for demos
Date: Tue, 27 Jul 2004 01:25:14 +0200

Hi all,

Now that our GUI implementation is maturing so fast it seemed like a
good idea to include a couple of demos in GNU Classpath. The idea is
that we will distribute a small collection of example code to show what
can be done with the GNU Classpath library.

The following patch adds a example directory, the first demos and the
build infrastructure to create an examples.zip file that can be
installed together with the actual sources and resources so hackers can
immediately start exploring the possibilities of GNU Classpath

2004-07-26  Mark Wielaard  <address@hidden>

       * NEWS: Mention new examples.
       * Makefile.am (SUBDIRS): Add examples directory.
       * configure.ac (AC_CONFIG_FILES): Add examples/Makefile.
       * lib/standard.omit: Remove TestAWT.java and Test.java
       * gnu/java/awt/peer/gtk/TestAWT.java: Removed.
       * gnu/java/awt/peer/gtk/Test.java: Removed.
       * examples/README: New file.
       * examples/Makefile.am: New file.
       * examples/gnu/classpath/examples/icons/*.png: New icon resources.
       * examples/gnu/classpath/examples/awt/Demo.java: New class.
       * examples/gnu/classpath/examples/swing/Demo.java: New class.

The first examples to include are the old TestAWT and Test code merged
into aAWTDemo and the activityboard and testswing code merged into a
SwingDemo.

This is how it currently looks:
http://www.klomp.org/mark/classpath/awtdemo-2004-jul-25.png
http://www.klomp.org/mark/classpath/swingdemo-2004-jul-25.png

What do you think? Is this a reasonable setup?
It should be easy to add new examples (IODemo, NetDemo, BeanDemo,
CollectionsDemo, RegexDemo, RMIDemo, NIODemo, TextDemo, SQLDemo,
MathDemo, GeomDemo, ...) by just adding a new directory under
gnu/classpath/examples/ in the examples dir and to add a Demo.java (and
possibily some helper classes).

Tested to make sure make distcheck works correctly and that the result
can be run out of the box with gcj/gij, kaffe, jamvm and kissme. (kissme
is still a bit fragile though.)

Cheers,

Mark
Index: NEWS
===================================================================
RCS file: /cvsroot/classpath/classpath/NEWS,v
retrieving revision 1.46
diff -u -r1.46 NEWS
--- NEWS        22 Jul 2004 19:45:38 -0000      1.46
+++ NEWS        26 Jul 2004 23:20:58 -0000
@@ -12,6 +12,7 @@
 * java.awt.image LookupTables and kernel support.
 * Improved java.awt.image.BufferedImage support.
 * AWT 1.0 event model support.
+* GNU Classpath now comes with some example programs (see examples/README).
 
 New in release 0.10 (Jul 9, 2004)
 
Index: Makefile.am
===================================================================
RCS file: /cvsroot/classpath/classpath/Makefile.am,v
retrieving revision 1.32
diff -u -r1.32 Makefile.am
--- Makefile.am 29 Mar 2004 07:07:24 -0000      1.32
+++ Makefile.am 26 Jul 2004 23:20:58 -0000
@@ -1,7 +1,7 @@
 ## Input file for automake to generate the Makefile.in used by configure
 
 # lib first, to compile .class files before native code
-SUBDIRS = lib doc external gnu java javax include native resource vm
+SUBDIRS = lib doc external gnu java javax include native resource vm examples
 
 native: lib
 
Index: configure.ac
===================================================================
RCS file: /cvsroot/classpath/classpath/configure.ac,v
retrieving revision 1.40
diff -u -r1.40 configure.ac
--- configure.ac        25 Jul 2004 11:59:20 -0000      1.40
+++ configure.ac        26 Jul 2004 23:20:58 -0000
@@ -463,6 +463,7 @@
 vm/reference/gnu/java/Makefile
 vm/reference/gnu/java/nio/Makefile
 lib/Makefile
-lib/gen-classlist.sh])
+lib/gen-classlist.sh
+examples/Makefile])
 AC_CONFIG_COMMANDS([gen-classlist],[chmod 755 lib/gen-classlist.sh])
 AC_OUTPUT
Index: lib/standard.omit
===================================================================
RCS file: /cvsroot/classpath/classpath/lib/standard.omit,v
retrieving revision 1.38
diff -u -r1.38 standard.omit
--- lib/standard.omit   30 Apr 2002 10:54:35 -0000      1.38
+++ lib/standard.omit   26 Jul 2004 23:20:58 -0000
@@ -1,4 +1,2 @@
 ../gnu/test/.*$
-../gnu/java/awt/peer/gtk/TestAWT.java$
-../gnu/java/awt/peer/gtk/Test.java$
 ../gnu/javax/swing/plaf/gtk/.*$
## Input file for automake to generate the Makefile.in used by configure

# Setup the compiler to use the GNU Classpath library we just build
GCJ = @GCJ@
JIKES = @JIKES@
if FOUND_GCJ
JCOMPILER = $(GCJ) --bootclasspath '' --classpath $(top_builddir)/lib:. -C
else
if FOUND_JIKES
JCOMPILER = $(JIKES) -bootclasspath '' -extdirs '' -sourcepath '' --classpath 
$(top_builddir)/lib:.
else
error dunno how to setup the JCOMPILER and compile
endif
endif

# All our example java source files
EXAMPLE_JAVA_FILES = $(srcdir)/gnu/classpath/examples/*/*.java

# The zip files with classes we want to produce.
EXAMPLE_ZIP = examples.zip

# Extra objects that will not exist until configure-time
BUILT_SOURCES = $(EXAMPLE_ZIP)

# the png icons we use in some of the examples.
EXAMPLE_ICONS = $(srcdir)/gnu/classpath/examples/icons/*.png

# Some architecture independent data to be installed.
example_DATA = $(EXAMPLE_ZIP) README

# Where we want these data files installed.
exampledir = $(pkgdatadir)/examples

# Make sure all sources and icons are also installed so users can use them.
# (Be careful to strip off the srcdir part of the path when installing.)
install-data-local:
        srcdir_cnt=`echo $(srcdir) | wc -c`; \
        for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
          f=`echo $$file | cut -c$$srcdir_cnt-`; \
          fdir=`dirname $$f`; \
          if test ! -d $(DESTDIR)/$(pkgdatadir)/examples/$$fdir; then \
            echo "$(mkinstalldirs) $(DESTDIR)/$(pkgdatadir)/examples/$$fdir"; \
            $(mkinstalldirs) $(DESTDIR)/$(pkgdatadir)/examples/$$fdir; \
          fi; \
          echo "$(INSTALL_DATA) $$file $(DESTDIR)/$(pkgdatadir)/examples/$$f"; \
          $(INSTALL_DATA) $$file $(DESTDIR)/$(pkgdatadir)/examples/$$f; \
        done

uninstall-local:
        srcdir_cnt=`echo $(srcdir) | wc -c`; \
        for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
          f=`echo $$file | cut -c$$srcdir_cnt-`; \
          echo "rm -f $(DESTDIR)/$(pkgdatadir)/examples/$$f"; \
          rm -f $(DESTDIR)/$(pkgdatadir)/examples/$$f; \
        done

# Make sure everything is included in the distribution.
EXTRA_DIST = README
dist-hook:
        srcdir_cnt=`echo $(srcdir) | wc -c`; \
        for file in $(EXAMPLE_JAVA_FILES) $(EXAMPLE_ICONS); do \
          f=`echo $$file | cut -c$$srcdir_cnt-`; \
          fdir=`dirname $$f`; \
          if test ! -d $(distdir)/$$fdir; then \
            echo "$(makeinstalldirs) $(distdir)/$$fdir"; \
            $(mkinstalldirs) $(distdir)/$$fdir; \
          fi; \
          echo "cp -p $$file $(distdir)/$$f"; \
          cp -p $$file $(distdir)/$$f; \
        done

# To generate the example zip just depend on the sources and ignore the
# class files. Always regenerate all .class files and remove them immediatly.
# And copy the png icons we use to the classes dir so they get also included.
$(EXAMPLE_ZIP): $(EXAMPLE_JAVA_FILES)
        mkdir -p classes/gnu/classpath/examples/icons
        cp $(EXAMPLE_ICONS) classes/gnu/classpath/examples/icons
        $(JCOMPILER) -d classes $(EXAMPLE_JAVA_FILES) 
        cd classes; $(ZIP) -r ../$(EXAMPLE_ZIP) .; cd ..
        rm -rf classes

# Zip file be gone! (and make sure the classes are gone too)
clean-local:
        rm -f $(EXAMPLE_ZIP) classes
These examples show how the GNU Classpath library can be used.

Each example has its own package under gnu.classpath.examples and has a
class Demo which contains a main() method to run that particular example.

The examples can be compiled and run with gcj as follows:

  gcj -o swingdemo --main=gnu.classpath.examples.swing.Demo \
      gnu/classpath/examples/swing/Demo.java
  ./swingdemo

Or with a traditional byte code interpreter like:
  gcj -C gnu/classpath/examples/awt/Demo.java
  gij gnu.classpath.examples.awt.Demo

The installation also comes with an examples.zip archive that contains
all needed resources and compiled byte code class files that can be
run as follows:
  kaffe -classpath examples.zip gnu.classpath.examples.awt.Demo
  kaffe -classpath examples.zip gnu.classpath.examples.swing.Demo

All example code is distributed under the GNU General Public License (GPL).

The example icons used in some of the examples come from gnome-icon-theme
version 1.2.3 and are also distributed under the GPL.  More free icons can
be found in that package
http://ftp.gnome.org/pub/GNOME/sources/gnome-icon-theme/


GNU Classpath examples are free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2, or (at
your option) any later version.

GNU Classpath examples is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath examples; see the file COPYING.  If not,
write to the Free Software Foundation, 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
/* Demo.java -- Shows examples of AWT components
   Copyright (C) 1998, 1999, 2002, 2004 Free Software Foundation, Inc.

This file is part of GNU Classpath examples.

GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.

GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING.  If not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
02111-1307 USA. */

package gnu.classpath.examples.awt;

import java.awt.*;
import java.awt.List;
import java.awt.event.*;
import java.net.URL;
import java.util.*;

class Demo
{
  public static void main(String args[])
  {
    MainWindow f = new MainWindow();
    f.show();
  }
  
  static interface SubWindow
  {
    public void init ();
  }
  
  static class PrettyPanel extends Panel
  {
    Insets myInsets;
    
    public PrettyPanel ()
    {
      myInsets = new Insets (10, 10, 10, 10);
    }
    public Insets getInsets ()
    {
      return myInsets;
    }
  }
  
  static abstract class PrettyFrame extends Frame
  {
    public PrettyFrame ()
    {
      ((BorderLayout) getLayout ()).setHgap (5);
      ((BorderLayout) getLayout ()).setVgap (5);
    }
    
    public Insets getInsets()
    {
      Insets oldInsets = super.getInsets ();
      return new Insets (oldInsets.top+10,
                         oldInsets.left+10,
                         oldInsets.bottom+10,
                         oldInsets.right+10);
    }
  }

  static abstract class SubFrame extends PrettyFrame implements SubWindow
  {
    boolean initted = false;
    
    public void setVisible (boolean visible)
    {
      if (!initted && visible)
        init();
      super.setVisible (visible);
    } 
  }

  static class MainWindow extends PrettyFrame implements ActionListener 
  {
    Button closeButton;
    
    Hashtable windows;
    Vector buttons;
    
    void addSubWindow (String name, SubWindow w)
    {
      Button b = new Button (name);
      b.addActionListener (this);
      
      buttons.addElement (b);
      windows.put (b, w);    
    }
    
    MainWindow () 
    {
      MenuBar mb = new MenuBar ();
      Menu menu = new Menu ("File");
      Menu submenu = new Menu ("Testing", true);
      submenu.add (new CheckboxMenuItem ("FooBar"));
      submenu.add (new CheckboxMenuItem ("BarFoo"));
      menu.add (submenu);
      menu.add (new MenuItem("Orange"));
      MenuItem quit = new MenuItem("Quit", new MenuShortcut('Q'));
      quit.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            System.exit(0);
          }
        });
      menu.add(quit);
      mb.add (menu);
      menu = new Menu("Edit", true);
      menu.add(new MenuItem("Cut"));
      menu.add(new MenuItem("Copy"));
      menu.add(new MenuItem("Paste"));
      mb.add (menu);
      
      setMenuBar (mb);
      
      String version = System.getProperty("gnu.classpath.version");
      add (new Label ("GNU Classpath " + version), "North");
      
      closeButton = new Button ("Close");
      closeButton.addActionListener (this);
      closeButton.setFont (new Font ("Serif", Font.BOLD | Font.ITALIC, 18));
      add (closeButton, "South");
      
      windows = new Hashtable ();
      buttons = new Vector ();
      
      addSubWindow ("Buttons", new ButtonsWindow ());
      addSubWindow ("Cursors", new CursorsWindow ());
      addSubWindow ("Dialog", new DialogWindow (this));
      addSubWindow ("File", new FileWindow (this));
      addSubWindow ("Labels", new LabelWindow ());
      addSubWindow ("List", new ListWindow ());
      addSubWindow ("Radio Buttons", new RadioWindow ());
      addSubWindow ("TextField", new TextFieldWindow ());
      addSubWindow ("Tests", new TestWindow (this));
      
      Panel sp = new Panel();
      PrettyPanel p = new PrettyPanel();
      p.setLayout (new GridLayout (windows.size(), 1));
      
      for (Enumeration e = buttons.elements (); e.hasMoreElements (); )
        {
          p.add ((Button) e.nextElement ());
        }
      
      sp.add (p);
      add (sp, "Center");
      
      setTitle ("AWT Demo");
      pack();
    }
    
    public void actionPerformed (ActionEvent evt)
    {
      Button source = (Button) evt.getSource ();
      
      if (source==closeButton)
        {
          dispose();
          System.exit (0);
        }
      
      Window w = (Window) windows.get (source);
      if (w.isVisible ())
        w.dispose ();
      else 
        {
          if (w instanceof Dialog)
            {
              w.show();
            }
          else
            {
              w.setVisible (true);
            }
        }
    }
  }
  
  static class ButtonsWindow extends SubFrame implements ActionListener
  {
    Button b[] = new Button [9];
    
    public void init ()
    {
      initted = true;
      Panel p = new Panel ();
      p.setLayout (new GridLayout (0, 3, 5, 5));
      
      for (int i=0; i<9; i++) 
        {
          b[i]=new Button ("button" + (i+1));
          b[i].addActionListener (this);
        }
      
      p.add (b[0]);
      p.add (b[6]);
      p.add (b[4]);
      p.add (b[8]);
      p.add (b[1]);
      p.add (b[7]);
      p.add (b[3]);
      p.add (b[5]);
      p.add (b[2]);
      
      add (p, "North");
      
      Button cb = new Button ("close");
      cb.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) {
            dispose();
          }
        });
      add (cb, "South");
      setTitle ("Buttons");
      pack();
    }
    
    public void actionPerformed (ActionEvent evt)
    {
      Button source = (Button) evt.getSource ();
      
      for (int i = 0; i < 9; i++)
        {
          if (source == b[i])
            {
              int i2 = ((i + 1) == 9) ? 0 : (i + 1);
              if (b[i2].isVisible())
                b[i2].setVisible(false);
              else 
                b[i2].setVisible(true);
            }
        }
    }
  }
  
  
  static class DialogWindow extends Dialog implements SubWindow
  {
    Label text;
    Frame parent;
    boolean initted = false;
    
    public DialogWindow (Frame f)
    {
      super (f, true);
      
      this.parent = f;
      
      addWindowListener (new WindowAdapter ()
        {
          public void windowClosing (WindowEvent e)
          {
            text.setVisible (false);
            hide ();
          }
        });
    }
    
    public void setVisible (boolean visible)
    {
      if (!initted && visible)
        init();
      super.setVisible (visible);
    }
    
    public void show ()
    {
      if (!initted)
        init();
      super.show ();
    }
    
    public void init ()
    {
      text = new Label ("Dialog Test");
      text.setAlignment (Label.CENTER);
      
      add (text, "North");
      text.setVisible (false);
      
      Panel p = new PrettyPanel();
      
      Button cb = new Button ("OK");
      cb.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) 
          {
            text.setVisible (false);
            hide();
          }
        });
      
      p.setLayout (new GridLayout (1, 3));
      ((GridLayout) p.getLayout ()).setHgap (5);
      ((GridLayout) p.getLayout ()).setVgap (5);
      p.add (cb);
      
      Button toggle = new Button ("Toggle");
      p.add (toggle);
      
      toggle.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) 
          {
            if (text.isVisible ())
              text.setVisible (false);
            else 
              text.setVisible (true);
            doLayout();
          }
        });
      
      Button subdlg = new Button ("SubDialog");
      p.add (subdlg);
      
      subdlg.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) 
          {
            DialogWindow sw = new DialogWindow (parent);
            sw.show ();
          }
        });
      
      add (p, "South");
      setTitle ("Dialog");
      pack();
    }
  }
  
  static class CursorsWindow extends SubFrame implements ItemListener
  {
    Choice cursorChoice;
    Canvas cursorCanvas;
    
    public void init ()
    {
      cursorChoice = new Choice();
      cursorChoice.add ("Default");
      cursorChoice.add ("Crosshair");
      cursorChoice.add ("Text");
      cursorChoice.add ("Wait");
      cursorChoice.add ("Southwest Resize");
      cursorChoice.add ("Southeast Resize");
      cursorChoice.add ("Northwest Resize");
      cursorChoice.add ("Northeast Resize");
      cursorChoice.add ("North Resize");
      cursorChoice.add ("South Resize");
      cursorChoice.add ("West Resize");
      cursorChoice.add ("East Resize");
      cursorChoice.add ("Hand");
      cursorChoice.add ("Move");
      
      cursorChoice.addItemListener(this);
      
      add (cursorChoice, "North");
      
      cursorCanvas = new Canvas () 
        { 
          public void paint (Graphics g) 
          {
            Dimension d = this.getSize();
            g.setColor(Color.white);
            g.fillRect(0, 0, d.width, d.height/2);
            g.setColor(Color.black);
            g.fillRect(0, d.height/2, d.width, d.height/2);
            g.setColor(this.getBackground());
            g.fillRect(d.width/3, d.height/3, d.width/3,
                        d.height/3);
          }
        };
      
      cursorCanvas.setSize (80,80);
      
      add (cursorCanvas, "Center");
      
      Button cb = new Button ("Close");
      cb.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) {
            dispose();
          }
        });
      
      add (cb, "South");
      setTitle ("Cursors");
      pack();
    }
    
    public void itemStateChanged (ItemEvent e)
    {
      int index = cursorChoice.getSelectedIndex();
      cursorCanvas.setCursor(Cursor.getPredefinedCursor(index));
    }
  }
  
  static class TextFieldWindow extends SubFrame implements ItemListener
  {
    Checkbox editable, visible, sensitive;
    TextField text;
    
    public void init ()
    {
      initted = true;
      text = new TextField ("hello world");
      add (text, "North");
      
      Panel p = new Panel();
      p.setLayout (new GridLayout (3, 1));
      ((GridLayout) p.getLayout ()).setHgap (5);
      ((GridLayout) p.getLayout ()).setVgap (5);
      
      editable = new Checkbox("Editable", true);
      p.add (editable);
      editable.addItemListener (this);
      
      visible = new Checkbox("Visible", true);
      p.add (visible);
      visible.addItemListener (this);
      
      sensitive = new Checkbox("Sensitive", true);
      p.add (sensitive);
      sensitive.addItemListener (this);
      
      add (p, "Center");
      
      Button cb = new Button ("Close");
      cb.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) {
            dispose();
          }
        });
      
      add (cb, "South");
      setTitle ("TextField");
      pack();
    }
    
    public void itemStateChanged (ItemEvent e)
    {
      boolean on=true;
      
      if (e.getStateChange () == ItemEvent.DESELECTED)
        on=false;
      if (e.getSource() == editable)
        text.setEditable (on);
      if (e.getSource() == visible)
        if (on)
          text.setEchoChar ((char) 0);
        else
          text.setEchoChar ('*');
      if (e.getSource() == sensitive)
        text.setEnabled (on);
      
    }
  }
  
  static class FileWindow extends FileDialog implements SubWindow
  {
    boolean initted = false;
    
    public FileWindow (MainWindow mw)
    {
      super (mw);
    }
    
    public void setVisible (boolean visible)
    {
      if (!initted && visible)
        init();
      super.setVisible (visible);
    }
    
    public void init() 
    {
      initted = true;
    }
  }
  
  static class LabelWindow extends SubFrame
  {
    public void init ()
    {
      initted = true;
      
      Panel p = new Panel();
      p.setLayout (new GridLayout (3, 1));
      ((GridLayout) p.getLayout ()).setHgap (5);
      ((GridLayout) p.getLayout ()).setVgap (5);
      
      p.add (new Label ("left justified label", Label.LEFT));
      p.add (new Label ("center justified label", Label.CENTER));
      p.add (new Label ("right justified label", Label.RIGHT));
      
      add (p, "Center");
      
      Button cb = new Button ("Close");
      cb.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) {
            dispose();
          }
        });
      
      add (cb, "South");
      setTitle ("Labels");
      pack();
    }
  }
  
  static class ListWindow extends SubFrame
  {
    public void init ()
    {
      initted = true;
      
      Panel p = new Panel ();
      p.setLayout (new GridLayout (3, 1));
      
      List l = new List (5, true);
      for (int i = 0; i < 10; i++)
        l.add ("List item " + i);

      p.add (l);

      add (p, "Center");
      
      Button cb = new Button ("Close");
      cb.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) {
            dispose();
          }
        });
      
      add (cb, "South");
      setTitle ("List");
      pack();
    }
  }    
  
  
  static class RadioWindow extends SubFrame
  {
    public void init ()
    {
      initted = true;
      
      Panel p = new Panel();
      p.setLayout (new GridLayout (3, 1));
      ((GridLayout) p.getLayout ()).setHgap (5);
      ((GridLayout) p.getLayout ()).setVgap (5);
      
      final CheckboxGroup cg = new CheckboxGroup();
      final Checkbox[] boxes = new Checkbox[3];
      for (int i = 0; i < 3; ++i)
        {
          boxes[i] = new Checkbox("button" + i, cg, i == 0);
          p.add(boxes[i]);
        }
      
      add (p, "North");
      
      p = new Panel();
      p.setLayout (new GridLayout (1, 3));
      ((GridLayout) p.getLayout ()).setHgap (5);
      ((GridLayout) p.getLayout ()).setVgap (5);
      
      for (int i = 0; i < 3; ++i)
        {
          final int val = i;
          Button tweak = new Button ("Set " + i);
          tweak.addActionListener(new ActionListener ()
            {
              public void actionPerformed (ActionEvent e)
              {
                cg.setSelectedCheckbox(boxes[val]);
              }
            });
          p.add(tweak);
        }
      
      add (p, "Center");
      
      Button cb = new Button ("Close");
      cb.addActionListener(new ActionListener () {
          public void actionPerformed (ActionEvent e) {
            dispose();
          }
        });
      
      add (cb, "South");
      setTitle ("Radio Buttons");
      pack();
    }
  }
  
  static class TestWindow extends SubFrame
  {
    static int xs = 5, ys = 5;
    private final Frame parent;
    
    public TestWindow(Frame f)
    {
      parent = f;
    }

    public void init()
    {
      initted = true;
      
      addWindowListener (new WindowAdapter ()
        {
          public void windowClosing (WindowEvent e)
          {
            hide ();
          }
        });

      Panel pan = new Panel();
      
      final Label l = new Label ("Pithy Message:");
      l.setCursor (Cursor.getPredefinedCursor (Cursor.WAIT_CURSOR));
      pan.add (l);
      
      TextField tf = new TextField("Hello world!");
      pan.add(tf);
      add(pan,"North");
      
      final Image img;
      URL imageurl;
      imageurl = this.getClass()
        .getResource("/gnu/classpath/examples/icons/big-warning.png");
      img = Toolkit.getDefaultToolkit().createImage(imageurl);

      final Canvas ch = new Canvas()
        { 
          public void paint (Graphics g)
          {
            g.drawImage(img, xs + 25, ys + 25, this);

            Font font = new Font ("Serif", Font.PLAIN, 18); 
            g.setFont (font);
            g.setXORMode (Color.red);

            g.drawString("Hi Red!", xs + 15, ys + 10);
            g.setColor (Color.blue);
            g.drawLine (xs, ys, xs + 100, ys + 100);
            
          }
        };
      ch.setSize(150, 150);
      add(ch, "Center");

      final ScrollPane sp = new ScrollPane(ScrollPane.SCROLLBARS_ALWAYS);
      final Panel p = new Panel();
      p.add(new Button("Stop"));
      p.add(new Button("evil"));
      p.add(new Button("hoarders"));
      p.add(new Button("use"));
      p.add(new Button("GNU!"));

      sp.add(p);
      add(sp, "South");

      Panel east_panel = new Panel();
      east_panel.setLayout(new GridLayout (0,1));

      CheckboxGroup group = new CheckboxGroup();
      Checkbox cb = new Checkbox("one", group, true);
      east_panel.add(cb);
      cb = new Checkbox("two", group, false);
      east_panel.add(cb);

      add(east_panel,"East");

      final Button wb = new Button();
      wb.setLabel("Hello World!");
      wb.addActionListener(new ActionListener()
        {
          public void actionPerformed (ActionEvent e)
          {
            l.setText ("Hello World!");
            
            final Dialog d = new Dialog(parent);
            d.setLayout(new FlowLayout());
            d.setModal(true);
            Button b = new Button("foobar");
            b.addMouseListener(new MouseAdapter()
              {
                public void mousePressed (MouseEvent me)
                {
                  d.hide ();
                }
              });
            d.add (b);

            List ch = new List();
            ch.add("Ding");
            ch.add("September");
            ch.add("Red");
            ch.add("Quassia");
            ch.add("Pterodactyl");
            d.add(ch);

            d.pack ();
            d.show ();
          }
        });

      wb.addMouseListener(new MouseAdapter()
        {
          public void mousePressed(MouseEvent e) {
            xs++;
            ys++;
            ch.repaint ();
          }
        });
      
      add(wb,"West");
      
      pack();
      show();
      
      sp.setScrollPosition (10,0);
      
      Toolkit t = Toolkit.getDefaultToolkit();
      t.beep();
    }
  }
}

Attachment: Demo.java
Description: Text Data

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]