java - I thought I had the program ready to run but when I run it nothing happens -


so thought had code being able work not working. not know , have tried looking @ has suggested not know appreciated!

import java.awt.*;  import javax.swing.jframe; import javax.swing.jpanel;  import java.awt.borderlayout; import java.awt.gridlayout;  import javax.swing.jbutton; import javax.swing.jlabel;  import java.awt.event.actionevent; import java.awt.event.actionlistener;  public class memory extends jpanel{  /**  *   */ private static final long serialversionuid = 1l; @override public void paintcomponent(graphics g) {     super.paintcomponent(g);            g.setcolor(new color(156, 93, 82));     g.fill3drect(21,3,7,12, true);     g.setcolor(new color(156,23,134));     g.filloval(1,15,15,15);     g.filloval(16,15,15,15);     g.filloval(31,15,15,15);     g.filloval(7,31,15,15);     g.filloval(22,31,15,15);     g.filloval(16,47,15,15);     setvisible(false);}   public memory() {  gridlayout h =new gridlayout(3,3); final jframe frame = new jframe(); final jpanel pan = new jpanel(h); frame.add(pan); pan.setbackground(new color(130,224,190)); pan.setfont(new font("serif", font.bold, 28)); jbutton button1= new jbutton(); pan.add(button1); final jlabel label1= new jlabel("hi"); label1.setvisible(false); pan.add(label1); jbutton button2= new jbutton(); pan.add(button2); final jlabel label2= new jlabel("hi"); label2.setvisible(false); pan.add(label2); jbutton button3= new jbutton(); pan.add(button3); final jlabel label3 = new jlabel("hi"); label3.setvisible(false); pan.add(label3); jbutton button4 = new jbutton(); pan.add(button4); final jlabel label4 = new jlabel("hi"); label4.setvisible(false); pan.add(label4); jbutton button5= new jbutton(); pan.add(button5); final jlabel label5= new jlabel("hi"); label5.setvisible(false); pan.add(label5); jbutton button6= new jbutton(); pan.add(button6); final jlabel label6= new jlabel("hi"); label6.setvisible(false); pan.add(label6); jbutton button7= new jbutton(); pan.add(button7); final jlabel label7= new jlabel("hi"); label7.setvisible(false); pan.add(label7); jbutton button8= new jbutton(); pan.add(button8); final jlabel label8= new jlabel("hi"); label8.setvisible(false); pan.add(label8); jbutton button9= new jbutton(); pan.add(button9); final jbutton button10= new jbutton("exit"); pan.add(button10); frame.setdefaultcloseoperation(jframe.exit_on_close); frame.settitle("memory game"); frame.setsize(500,500); frame.setvisible(true); setlayout(new borderlayout()); add(pan,borderlayout.center); add(button10, borderlayout.south); setsize(600,600); setvisible(true); final jlabel label9= new jlabel("hi"); label9.setvisible(false); pan.add(label9);  button1.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label1.setvisible(true);     } }); button2.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label2.setvisible(true);     } }); button3.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label3.setvisible(true);     } }); button4.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label4.setvisible(true);     } }); button5.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label5.setvisible(true);     } }); button6.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label6.setvisible(true);     } }); button7.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label7.setvisible(true);     } }); button8.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label8.setvisible(true);         frame.getcontentpane().add(new memory());         setvisible(true);      }}); ; button9.addactionlistener(new actionlistener() {     public void actionperformed(actionevent arg0) {         label9.setvisible(true);}}  ); button10.addactionlistener(new actionlistener() { public void actionperformed(actionevent arg0) {          if (button10.getsize() != null) {         system.exit(0);}}           });};          public static void main(string args[])         {             new memory();         };       } 

as said in last question, need add panel instance of jframe...

public static void main(string[] args) {     eventqueue.invokelater(new runnable() {         @override         public void run() {             jframe frame = new jframe("testing");             frame.setdefaultcloseoperation(jframe.exit_on_close);             frame.setlayout(new borderlayout());             frame.add(new memory());             frame.pack();             frame.setlocationrelativeto(null);             frame.setvisible(true);         }     }); } 

take time , have read through creating gui jfc/swing

you'll want remove

final jframe frame = new jframe(); final jpanel pan = new jpanel(h); frame.add(pan); 

from constructor , simple add components directly (memory) panel

you'll need remove setvisible(false); paintcomponent method ... explains why you're having many problems...


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

php - Accessing static methods using newly created $obj or using class Name -