java - JLabel is not showing -


i'm trying give jlabel in next line, nothing happening output shows nothing blank line when run code:

main class:

import javax.swing.jframe;  public class main {      public static void main(string[] args){         test piyu=new test();         piyu.setdefaultcloseoperation(jframe.exit_on_close);         piyu.setsize(300,200);          piyu.setvisible(true);     } } 

test class:

import java.awt.*; import javax.swing.*;  public class test extends jframe {      private jlabel item1,item2;      public test() {         super("first java app");         jpanel panel=new jpanel();         panel.setlayout(new gridlayout());         item1=new jlabel("my name xyz");         item2=new jlabel("yo");         item1.settooltiptext("game on");         panel.add(item1);         panel.add(item2);     } } 

you missing 1 line. never add jpanel jframe.

class test extends jframe {      private jlabel item1,item2;      public test(){          super("first java app");         jpanel panel=new jpanel();         panel.setlayout(new gridlayout());         item1=new jlabel("my name xyz");         item2=new jlabel("yo");         item1.settooltiptext("game on");         panel.add(item1);         panel.add(item2);         this.add(panel);      } } 

also, note there no need extend jframe in case. have written this:

import java.awt.*; import javax.swing.*; import javax.swing.jframe;  public class main {      public static void main(string[] args){          jframe piyu=new jframe("first java app");          jpanel panel=new jpanel();         jlabel item1,item2;         panel.setlayout(new gridlayout());         item1=new jlabel("my name xyz");         item2=new jlabel("yo");         item1.settooltiptext("game on");         panel.add(item1);         panel.add(item2);         piyu.add(panel);          piyu.setdefaultcloseoperation(jframe.exit_on_close);         piyu.setsize(300,200);         piyu.setvisible(true);      } } 

Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -