Javaで自分のクラスの中で自分のオブジェクト(?)を知りたいと思っています。
lang
1[ButtonExクラス] 2public class ButtonEx extends Button{ 3 private PropertiesManager propman = new PropertiesManager(); 4 public Object GetProperty(String key){ 5 return propman.GetProperty(getClass(), key); ※1 6 } 7 } 8} 9 10[PropertiesManager] 11public class PropertiesManager { 12 private PropertiesStore propobj; 13 public Object GetProperty(Object obj,String key){ 14 propobj=propstore.get(obj); 15 return propobj.GetProperty(key); 16 } 17} 18※上記propstoreはプロパティファイルを格納するクラス 19 20[メインクラス] 21private HashMap<Object,ButtonEx> buttons = new HashMap<Object,ButtonEx>(); 22for(int i=0 ; i<10 ; i++){ 23 ButtonEx button = new ButtonEx(); 24 button.SetProperty(キー,値); 25 buttons.put(button,button); ※2 26} 27 28button.setOnAction(new EventHandler<ActionEvent>(){ 29 public void handle(ActionEvent act){ 30 System.out.println(button.GetProperty(キー)); ※3 31 } 32} 33
上記のようなつくりをしている意図として、PropManagerは様々な所で使用するため(ButtonExもその一つ)、
オブジェクトを指定して取り出したりしたいため、ButtonExクラス内では、自分のオブジェクトID(?)を※1
で指定したいと考えています。
しかし、※2では、以下のようなオブジェクトIDを格納できるのですが、
ButtonEx@fb9bdcc[styleClass=button]''
※1では(getClass()だから当然かも知れませんが・・・)上のようなIDではなく、自分のクラス名が取れてしまいます。
結果、※3で意図した値が取れていません。
上記のようなIDを自分のクラスから知る方法は何かないでしょうか??
具体的にご教示いただければ助かります。
よろしくお願いします。
※上記はJavaFXのボタンクラスなのですが、Javaの基本的な考え方のような気がしますので、
Javaで質問させて頂きました。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/04/28 14:55
2017/04/28 21:36