java - Having trouble with creating a JFrame and adding text to it -
i've been trying setup jframe text i'm having trouble. can create jframe, can't background color or text work it.
import java.awt.color; import javax.swing.jframe; import javax.swing.jlabel; import javax.swing.jpanel; class fundmanager { jframe window; jpanel panel; jlabel text; public void createwindow() { //create window window = new jframe(); window.setvisible(true); window.setsize(960, 540); window.setdefaultcloseoperation(jframe.exit_on_close); window.setlocationrelativeto(null); //create panel panel = new jpanel(); panel.setbackground(color.red); //create label text = new jlabel("test"); } public static void main(string args[]) { fundmanager.createwindow(); } }
my createwindow()
method not running , error:
cannot make static reference to non-static method.
however, when make static whole program breaks.
the issue here need instance of fundmanager before can call method createwindow(). try code below instead.
new fundmanager().createwindow();
Comments
Post a Comment