user interface - Using prototype (Design Pattern) to do a simple Frame with Buttons on JAVA -
im trying implement construction design patterns of gof, 1 of them "prototype". idea create user interface (a frame buttons , labels) in wich can use prototype clone button, because program memory game (about mario bros :d) of on java. want implement own clone method.
what think need make button, , when clone change name of button (and maybe image button shows).
first of have class named prototype
clone:
import javax.swing.jbutton; public interface prototype { //method make clone public prototype makeclone(); public jbutton getbuttonname(); public void setbuttonname(string eldato); }//end interface prototype
then, have concreteprototypebutton
implement interface prototype
, use cloning method.
import javax.swing.jbutton; public class concreteprototypebutton implements prototype{ private string adata; static jbutton abutton; //-------- public prototype makeclone(){ prototype aclone; //--------------- aclone = new concreteprototypebutton(); aclone.setnombreboton(this.adata); return aclone; }//end makeclone public string getbuttonname() { return adata; }//end getnombreboton public void setbuttonname(string adata) { object thename =new string(adata); thename=thename.tostring(); //------------ this.adata=(jbutton)thename; }//end setbuttonname method }//end class concreteprototypebutton
but java shows me problem in method getbuttonname
on line:
return adata;
finally have third class named userinterface
client, can not have main
'cause main
in class complete program.
import javax.swing.*; public class interfaz { prototype abutton; prototype buttonone; prototype buttontwo; //------------------- abutton = new concreteprototypebutton(); abutton.setbuttonname("buttonone"); //we make clone buttonone = abutton.makeclone(); abutton.setbuttonname("buttontwo"); //we make clone buttontwo = abutton.makeclone(); //and continue creating buttons reach 16 buttons. }//end clase interfaz
but i'm doing wrong , idk it, on class show me errors on line:
prototype buttontwo;
and on this:
}//end clase interfaz
the idea have this: http://imageshack.us/photo/my-images/855/te7q.png/ (tell me if can not see image).
i apreciate lot if can me. in advance.
additional notes: when change method returns jbutton string java sends me error: - implements prototype.getnombreboton - return type incompatible with: prototype.getnombreboton
and if change too. how can declarate target of classes make objects "buttons"?
first of all
prototype buttontwo;
and buttontwo = abutton.makeclone();
both different should buttontwo
and return adata;
you returning string in place of jbutton , in method
public void setbuttonname(string adata) {
string thename; //------------ thename = (string) adata; adata = thename; }
the adata here refering local variable of method of setbuttonname(string adata) in place of adata = thename; should have used this.adata = thename; give error assigning string jbutton. may want write method work
public void setbuttonname(string adata) {
object thename=new string(adata); thename=thename.tostring(); //------------ this.adata=(jbutton)thename; }
this per code provided here dont know requirement wanted make. try might works.
Comments
Post a Comment