home *** CD-ROM | disk | FTP | other *** search
/ The Net: Ultimate Internet Guide / WWLCD1.ISO / pc / java / ingzp26a / gridpanel.java < prev    next >
Encoding:
Java Source  |  1996-08-14  |  4.0 KB  |  190 lines

  1. /* $Id: gridPanel.java,v 1.4 1996/03/28 08:48:44 djun Exp $
  2.  
  3.    File: gridPanel.java
  4.  
  5.    This is an extension of Panel, with a GridbagLayout and
  6.    constructor methods for common Widgets such as labels,
  7.    buttons, textfields, etc, defined.
  8.    
  9.    Author: Djun M. Kim
  10.    Copyright (c) 1996 Djun M. Kim.  All rights reserved.
  11.  
  12. */
  13.  
  14. import java.awt.*;
  15. import java.net.*;
  16. import java.util.*;
  17.  
  18. public class gridPanel extends Panel{
  19.  
  20.     // display panel with gridbag layout methods
  21.  
  22.     int RELA = GridBagConstraints.RELATIVE;
  23.     int REMN = GridBagConstraints.REMAINDER;
  24.  
  25.     GridBagLayout gridbag = new GridBagLayout();
  26.     GridBagConstraints c = new GridBagConstraints();
  27.  
  28.     gridPanel() {
  29.     setLayout(gridbag);
  30.     c.fill = GridBagConstraints.BOTH;
  31.     c.ipadx = 0; c.ipady = 0;
  32.     c.insets.top = 0; c.insets.bottom = 0;
  33.     }
  34.  
  35.     gridPanel(Container target) {
  36.     setLayout(gridbag);
  37.     target.add(this);
  38.     c.fill = GridBagConstraints.BOTH;
  39.     c.ipadx = 0; c.ipady = 0;
  40.     c.insets.top = 0; c.insets.bottom = 0;
  41.     }
  42.  
  43.     gridPanel(String s, Container target) {
  44.     setLayout(gridbag);
  45.     target.add(s, this);
  46.     c.fill = GridBagConstraints.BOTH;
  47.     c.ipadx = 0; c.ipady = 0;
  48.     c.insets.top = 0; c.insets.bottom = 0;
  49.     }
  50.  
  51.     public Button make_button(
  52.             String name, 
  53.             double weightx, double weighty, 
  54.             int gridweight, int gridheight) {
  55.  
  56.     c.weightx = weightx; 
  57.     c.weighty = weighty; 
  58.     c.gridwidth = gridweight;
  59.     c.gridheight = gridheight;
  60.  
  61.     Button button = new Button(name);
  62.     gridbag.setConstraints(button, c);
  63.     add(button);
  64.     return button;
  65.     }
  66.  
  67.     public Button make_button(
  68.             String name, 
  69.             int gridx, int gridy,
  70.             double weightx, double weighty, 
  71.             int gridweight, int gridheight) {
  72.  
  73.     c.gridx = gridx;
  74.     c.gridy = gridy;
  75.     c.weightx = weightx; 
  76.     c.weighty = weighty; 
  77.     c.gridwidth = gridweight;
  78.     c.gridheight = gridheight;
  79.  
  80.     Button button = new Button(name);
  81.     gridbag.setConstraints(button, c);
  82.     add(button);
  83.     return button;
  84.     }
  85.  
  86.     public Label make_label(
  87.             String name, 
  88.             double weightx, double weighty, 
  89.             int gridwidth, int gridheight) {
  90.  
  91.     c.weightx = weightx; 
  92.     c.weighty = weighty; 
  93.     c.gridwidth = gridwidth;
  94.     c.gridheight = gridheight;
  95.  
  96.     Label label = new Label(name);
  97.     gridbag.setConstraints(label, c);
  98.     add(label);
  99.     return label;
  100.     }
  101.  
  102.     // Create a text field.
  103.     public TextField make_textf(
  104.             String name, 
  105.             boolean editable, 
  106.             double weightx, double weighty, 
  107.             int gridweight, int gridheight) {
  108.  
  109.     c.weightx = weightx; 
  110.     c.weighty = weighty; 
  111.     c.gridwidth = gridweight;
  112.     c.gridheight = gridheight;
  113.  
  114.     TextField textf = new TextField(name);
  115.     textf.setEditable(editable);
  116.     gridbag.setConstraints(textf, c);
  117.     add(textf);
  118.     return(textf);
  119.     }
  120.  
  121.     public TextArea make_texta(
  122.             String name, 
  123.             int textlines, 
  124.             int textwidth, 
  125.             double weightx, double weighty, 
  126.             int gridweight, int gridheight) {
  127.  
  128.     c.weightx = weightx; 
  129.     c.weighty = weighty; 
  130.     c.gridwidth = gridweight;
  131.     c.gridheight = gridheight;
  132.  
  133.     TextArea texta = new TextArea(textlines, textwidth);
  134.     texta.setEditable(false);
  135.     gridbag.setConstraints(texta, c);
  136.     add(texta);
  137.     return(texta);
  138.     }
  139.  
  140.     public List make_list(
  141.             String name, 
  142.             int numitems,
  143.             boolean multipicks, 
  144.             double weightx, double weighty, 
  145.             int gridweight, int gridheight) {
  146.  
  147.     c.weightx = weightx; 
  148.     c.weighty = weighty; 
  149.     c.gridwidth = gridweight;
  150.     c.gridheight = gridheight;
  151.  
  152.     List list = new List(numitems, multipicks);
  153.     gridbag.setConstraints(list, c);
  154.     add(list);
  155.     return(list);
  156.     }
  157.  
  158.     public void make_panel(
  159.             Object arg, 
  160.             int gridx, int gridy,
  161.             double weightx, double weighty, 
  162.             int gridwidth, int gridheight){
  163.     Panel panel = (Panel) arg;
  164.     c.gridx = gridx;
  165.     c.gridy = gridy;
  166.     c.weightx = weightx;
  167.     c.weighty = weighty;
  168.     c.gridwidth = gridwidth;
  169.     c.gridheight = gridheight;
  170.     gridbag.setConstraints(panel, c);
  171.     add(panel);
  172.     }
  173.  
  174.     public void make_canvas(
  175.             Canvas canvas, 
  176.             int gridx, int gridy,
  177.             double weightx, double weighty, 
  178.             int gridwidth, int gridheight){
  179.     c.gridx = gridx;
  180.     c.gridy = gridy;
  181.     c.weightx = weightx;
  182.     c.weighty = weighty;
  183.     c.gridwidth = gridwidth;
  184.     c.gridheight = gridheight;
  185.     gridbag.setConstraints(canvas, c);
  186.     add(canvas);
  187.     }
  188. }
  189.  
  190.