java - incompatible type GridLayout cannot be converted to layout manager -


here demo code, please check out why code given me problem.

package gridlayout;  import java.awt.*; import javax.swing.*;  public class gridlayout {     public static void main(string[] args) {     eventqueue.invokelater(()->{          myframe frame = new myframe();         //frame.setdefaultcloseoperation(0);         //frame.settitle("grid layout");        // frame.setdefault     });   } }  class myframe extends jframe{  public myframe(){      settitle("my programm");     setdefaultcloseoperation(jframe.exit_on_close);      add(new mypanel());     pack();     setvisible(true);     }  }  class mypanel extends jpanel{   private jbutton display;   private  double result;   private string lastcommand;   private boolean start;   private jpanel panel;  // private static final int n = 4;    public mypanel(){       setlayout(new borderlayout());      //setlayout(new gridlayout(4,4));      result = 0;     lastcommand = "=";     start = false;     display = new jbutton("0");      setenabled(false);     add(display, borderlayout.north);  //        panel = new jpanel(); //        panel.setlayout(new gridlayout());           gridlayout explayout = new gridlayout(0,4); }  public void addbuttons(string name){     jbutton button = new jbutton(name);    } } 

the issue seems in have code:

 public class gridlayout {      /**      * @param args command line arguments      */        public static void main(string[] args) {         // todo code application logic here         eventqueue.invokelater(()->{              myframe frame = new myframe();             //frame.setdefaultcloseoperation(0);             //frame.settitle("grid layout");            // frame.setdefault         });         }      } 

since have defined custom class in package other classes reside , class called gridlayout, 2 names conflict when panel.setlayout(new gridlayout()) avoid either rename custom gridlayout has different name or try panel.setlayout(new java.awt.gridlayout()) instead of panel.setlayout(new gridlayout())

p.s. - @xtremebaumer correctly noticed should avoid using well-known class names either jdk distribution package or other well-known libraries (at least should understand risks if still required classes have such names)


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -