[3234] in java-interest

home help back first fref pref prev next nref lref last post

Class GridBagLayout Example

daemon@ATHENA.MIT.EDU (Martin Freeman)
Fri Nov 3 22:47:55 1995

Date: Fri, 3 Nov 95 17:17:23 PST
From: martin@PRPA.Philips.COM (Martin Freeman)
To: java-interest@java.sun.com
Cc: martin@savant.PRPA.Philips.COM


I am working with the new NT version of the JDK beta 1.0. I
just tried to compile the following code that is included as an example
in the Java class GridBagLayout.java:

import java.awt.*;
import java.util.*;
import java.applet.Applet;

public class GridBagEx1 extends Applet {

    protected void makebutton(String name,
                              GridBagLayout gridbag,
                              GridBagConstraints c) {
        Button button = new Button(name);
        gridbag.setConstraints(button, c);
        add(button);
    }

    public void init() {
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints c = new GridBagConstraints();
 
        setFont(new Font("Helvetica", Font.PLAIN, 14));
        setLayout(gridbag);
   
        c.fill = GridBagConstraints.BOTH;
        c.weightx = 1.0;
        makebutton("Button1", gridbag, c);
        makebutton("Button2", gridbag, c);
        makebutton("Button3", gridbag, c);
    
	c.gridwidth = GridBagConstraints.REMAINDER; //end row
        makebutton("Button4", gridbag, c);
    
        c.weightx = 0.0;		   //reset to the default
        makebutton("Button5", gridbag, c); //another row
    
	c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
        makebutton("Button6", gridbag, c);
    
	c.gridwidth = GridBagConstraints.REMAINDER; //end row
        makebutton("Button7", gridbag, c);
    
	c.gridwidth = 1;	   	   //reset to the default
	c.gridheight = 2;
        c.weighty = 1.0;
        makebutton("Button8", gridbag, c);
    
        c.weighty = 0.0;		   //reset to the default
	c.gridwidth = GridBagConstraints.REMAINDER; //end row
	c.gridheight = 1;		   //reset to the default
        makebutton("Button9", gridbag, c);
        makebutton("Button10", gridbag, c);
    
        resize(300, 100);
    }
    
    public static void main(String args[]) {
	Frame f = new Frame("GridBag Layout Example");
	GridBagEx1 ex1 = new GridBagEx1();
    
	ex1.init();
    
	f.add("Center", ex1);
	f.pack();
	f.resize(f.preferredSize());
	f.show();
    }
}

-------------------------------------------------------------------------------

I get the following error message. Before I submit a bug report, is this
error the result of something that I may be doing?

-------------------------------------------------------------------------------

java.lang.NullPointerException
        at sun.tools.tree.FieldExpression.checkLHS(FieldExpression.java:166)
        at sun.tools.tree.AssignExpression.checkValue(AssignExpression.java:40)
        at sun.tools.tree.BinaryAssignExpression.check(BinaryAssignExpression.java:52)
        at sun.tools.tree.ExpressionStatement.check(ExpressionStatement.java:43)
        at sun.tools.tree.CompoundStatement.check(CompoundStatement.java:48)
        at sun.tools.tree.Statement.checkMethod(Statement.java:55)
        at sun.tools.javac.SourceField.check(SourceField.java:181)
        at sun.tools.javac.SourceClass.check(SourceClass.java:398)
        at sun.tools.javac.SourceClass.compileClass(SourceClass.java:513)
        at sun.tools.javac.SourceClass.compile(SourceClass.java:500)
        at sun.tools.javac.Main.compile(Main.java:195)
        at sun.tools.javac.Main.main(Main.java:286)
GridBagEx1.java:7: Class GridBagConstraints not found in type declaration.
    protected void makebutton(String name,
                   ^
GridBagEx1.java:7: Class GridBagLayout not found in type declaration.
    protected void makebutton(String name,
                   ^
GridBagEx1.java:11: Class GridBagLayout not found in void makebutton(java.lang.String, GridBagLayout, GridBagConstraints).
        gridbag.setConstraints(button, c);
                              ^
GridBagEx1.java:16: Class GridBagLayout not found in type declaration.
        GridBagLayout gridbag = new GridBagLayout();
        ^
GridBagEx1.java:16: Class GridBagLayout not found in new.
        GridBagLayout gridbag = new GridBagLayout();
                                ^
GridBagEx1.java:17: Class GridBagConstraints not found in type declaration.
        GridBagConstraints c = new GridBagConstraints();
        ^
GridBagEx1.java:17: Class GridBagConstraints not found in new.
        GridBagConstraints c = new GridBagConstraints();
                               ^
GridBagEx1.java:20: Class GridBagLayout not found in void init().
        setLayout(gridbag);
                 ^
GridBagEx1.java:22: Class GridBagConstraints not found in void init().
        c.fill = GridBagConstraints.BOTH;
         ^
error: An exception has occurred in the compiler; please file a bug report (java-bugs@java.sun.com).
10 errors
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post