i'm working on java homework , having difficulty understanding doing wrong. in step, required determine class inherited jframe class declares setvisible method, import class , modify code in main method frame variable declared type rather jframe type.
import javax.swing.jframe; public class productframe extends jframe { public productframe() { // of these methods available because // inherited jframe class // , superclasses this.settitle("product") this.setsize(200, 200); this.setlocation(10, 10); this.setresizable(false); // method uses field that's available // because it's inherited this.setdefaultcloseoperation(exit_on_close); } public static void main(string[] args) { // creates instance of productframe jframe frame = new productframe(); // displays frame frame.setvisible(true); } }
i post have been trying, doesn't make sense , isn't worth copying. findings setvisible window.java, ,
public void setvisible(boolean bln) { // compiled code }
is find, after try import setvisible class window.java code, , try doesn't work.
i required determine class inherited jframe class declares setvisible method, import class , modify code in main method frame variable declared type rather jframe type.
the java api tell this. jframe api entry, , on page, search the setvisible
method , shows method belongs window class: java.awt.window
(window api entry). can use window variable in place of jframe variable if need call setvisible(true)
on it. note if need more jframe specific functionality variable, such getting contentpane, window type won't work.
e.g.
// sure import java.awt.window; window window = new productframe(); window.setvisible(true);
the bottom line learn use api answer most of java questions.