Can somebody help me with this Java AWT error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Can somebody help me with this Java AWT error?

//I am new to java and following a tutorial video. //I am creating a GridBagLayout but gives me a error // It Says "GridBagLayout cannot be converted to LayoutManager" //Code: package pkg12.gridbaglayout; import java.awt.*; //mport java.awt.event.*; class MyFrame extends Frame { Button b1,b2; public MyFrame() { super("GridBag Layout Demo"); GridBagLayout gb = new GridBagLayout(); GridBagConstraints gbc = new GridBagConstraints(); //says error at here, GridBagLayout cannot be converted to LayoutManager, //I use Netbeans and parameter "gb" got highlighted by red setLayout(gb); //shows error at this line b1 = new Button("One"); b2 = new Button("Two"); gbc.gridx = 1; gbc.gridy = 1; add(b1,gbc); gbc.gridx = 2; gbc.gridy = 2; add(b2,gbc); } } public class GridBagLayout { public static void main(String[] args) { MyFrame f = new MyFrame(); f.setSize(500, 500); f.setVisible(true); } } //Please help, I will appreciate

15th Nov 2021, 4:05 AM
Coding San
Coding San - avatar
1 Answer
+ 1
rename your class eg to public class GridBagLayout_test { or use java.awt.GridBagLayout gb = new java.awt.GridBagLayout();
15th Nov 2021, 6:44 AM
zemiak