• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

GridbagConstraints

 
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.awt.* ;

public class Gridconst extends Frame {
GridBagLayout gridbag=new GridBagLayout();
setLayout(gridbag); //ERROR:Identifier expected.
GridBagConstraints constraints=new GridBagConstraints();
Component b = new Button("Button") ;
add(c) ;
constraints.gridx=5;
constraints.gridy=10;
gridbag.setConstraints(c,constraints);

setSize(300,400) ;

setVisible(true) ;
pack();
}
}
public static void main(String[] args) {
FrameTest frame = new FrameTest() ;

}
}//ERROR:Identifier expected.

Why is this program giving teh error specified?
 
Ranch Hand
Posts: 325
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Where is the class FrameTest defined in the code..
what is c in add(c) ???
 
Deepali Pate
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for those errors but even after corrections it gives me error.

import java.awt.* ;

public class Gridconst extends Frame {
GridBagLayout gridbag=new GridBagLayout();
setLayout(gridbag); //ERROR:Identifier expected.

GridBagConstraints constraints=new GridBagConstraints();
Component b = new Button("Button") ;
add(b) ;
constraints.gridx=5;
constraints.gridy=10;
gridbag.setConstraints(c,constraints);

setSize(300,400) ;

setVisible(true) ;
pack();
}
}
public static void main(String[] args) {
Gridconst frame = new Gridconst() ;

}
}
 
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check out the curly brackets!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...and there should be b and not c in the line
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
your problem is that you can�t call a method in the body of the class, you can only declare members. You can call methods inside constructors or other methods like this:

You should try reading some good books on Java like "Thinking in Java" from Bruce Eckel, to avoid this problems in the future.
Francisco
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strange!I've seen code similar to this in JQplus:

And it works.
 
Deepali Pate
Ranch Hand
Posts: 114
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Francisco,
Yes it worked. May be that was teh problem. But it is not displying the size i am specifying.
Also if i add other constraints like
constraints.gridwidth=15;
constraints.gridheight=10;
constraints.weightx=35;
constraints.weighty=30;
i see no change Why??? Can u pls explain.
Thnx a lot
 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class a
{ int x = method(); ....
public int method()
{
return 10;
}
..... .....
}
I think a smart compiler will make the above code look like ..
public class a
{ int x ;
public a()
{
x = method();
super();
}
public int method()
{
return 10;
}
..... .....
}
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic