java - How do I construct a JFrame child class? -
i'm trying make child class jframe
. think im doing correctly when run opens blank window without name or background color (my jpanel
class background. however, know error not there because commented out add(jpanel
) , window still didn't have name) eclipse doesn't show syntax errors. why doesn't code work?:
main class:
package ashwin.engine; import javax.swing.*; import java.awt.*; public class execute { public static void main(string[] args) { swingutilities.invokelater(new runnable(){ @override public void run() { int[] bcolor = new int[3]; bcolor[0] = 254; bcolor[1] = 0; bcolor[2] = 0; window wndw = new window("test", 1000, 1000, bcolor, true); } }); } }
jframe child class:
package ashwin.engine; import javax.swing.*; import java.awt.*; public class window extends jframe { window(string name, int width, int length, int[] backgroundcolor, boolean visible) { system.out.println("made frame class"); setname(name); setvisible(visible); setsize(width, length); setdefaultcloseoperation(jframe.exit_on_close); display display = new display(backgroundcolor); } }
edit: forgot mention, print out debug statement "made frame class", dont know if helps thought should point out.
you shouldn't use setname
settitle
. display name on screen. background, should use getcontentpane().setbackgroundcolor(color color)
the chode should this:
public class execute { public static void main(final string[] args) { swingutilities.invokelater(new runnable() { @override public void run() { final color bcolor = new color(254, 0, 0); final window wndw = new window("test", 1000, 1000, bcolor, true); } }); } } public class window extends jframe { window(final string name, final int width, final int length, final color backgroundcolor, final boolean visible) { system.out.println("made frame class"); this.settitle(name); this.setsize(width, length); this.getcontentpane().setbackground(backgroundcolor); this.setdefaultcloseoperation(jframe.exit_on_close); this.setvisible(visible); } }
Comments
Post a Comment