Class c = Class.forName("classname"); Object obj = null; obj = c.newInstance(); //不帶引數Object[] arg = new Object[] {3.14159, 125}; //引數 obj = ctor.newInstance(arg);//帶引數
可以用以下代码实现 Component[] com = getContentPane().getComponents(); for (int i = 0; i < com.length; i++) { Component c = com[i]; if(c instanceof JButton){ JButton b = (JButton)c; if(b.getText()=="okbtn"){ System.out.println("b is the reference"); } } }
Object obj = null;
obj = c.newInstance(); //不帶引數Object[] arg = new Object[] {3.14159, 125}; //引數
obj = ctor.newInstance(arg);//帶引數
Component[] com = getContentPane().getComponents();
for (int i = 0; i < com.length; i++) {
Component c = com[i];
if(c instanceof JButton){
JButton b = (JButton)c;
if(b.getText()=="okbtn"){
System.out.println("b is the reference");
}
}
}