How can I access a method with several swing components from another class? (Java) -
suppose:
public class window { public void dialog () { jdialog jd = new jdialog(); // add pictures/labels onto jdialog } } and:
public class main { //suppose here gui button if clicked called dialog method } my issue cannot figure out how access method on eclipse. created constructor on window class call method didn't work me.
window instance1 ; // create instance of class public window (window temp){ instance1 = temp; }
///on main class dialog temp1 = new dialog (temp1); temp1.opendialog (); // calls method other class i know syntax issue calling constructor don't know whats wrong.
try that:
public class window { public void dialog()// re forgeting parenttheses { jdialog jd = new jdialog(); // add pictures/labels onto jdialog } } and can access method by:
public class main{ window win; public main(){ win = new window(); win.dialog(); } } and thing convention not use uppercase letter on first letter of method name. first letter in uppercase used class constructor.
a contructor don't return kind of variable , use same name class.
Comments
Post a Comment