swing - Call Method from load class from classForName java -
Firstly I am using IBM Java 2 SDK, Standard Edition, v 1.2
. Two clayes,
My main goal is to dynamically add panel class to a JetBad panel and execute the method from the loaded class.
Let's start:
> The current menu will catch the bunts that will set fire to connect the classes.
The main category.
extended to public class WMenu javax.swing.JFrame {JTabbedPane1 = new javax. Swing.JTabbedPane (); JBTnexec = new javax.swing.JButton (); Jebtonundo = new javax.swing.JButton (); ... public static zero major (java.lang.String [] args) {...} / * When user press BTN should execute this method. * / Public Zero exec (java.awt.event.MouseEvent e) {JpnL content = new zpn (); / * The name of my class is unknown on the name of this class, for this case, manually added by variable, * / class qc = Class.forName ("Wcontrol"); Content = (JPN) qc.new Instance (); JTabbedPane1.addTab ("Control", Content); } / * When the Undo Press BTN * /
Undo Public Zune (java.util.EventObject newEvent) {class wMenu = Class.forName ("Wcontrol"); Method m = wMenu.getDeclaredMethod ("undo", new class [] {String.class}); Object c = wMenu.newInstance (); M.invoke (c, new object [] {new string (this.getClass (). GetName (). ToString ())}); } }
Class # 2 / * My panel which is the control screen. There are some label fields * /
Public class Wcontrol expanded Jpnell {txt_cve = new javax.swing.JTextField (); Public Zero Undo (String In) {/*txt_cve.setText("TTT "); First test comment ... * / System.out.println ("data" + txt_cveind.getText ()); Employmentpan Show message dialog (this, "data:" + txt_cveind.getText (), "info", 1); } }
}
Now, when I run the frame, when I executed the new class panel to load, even then came prefix, displayed in the JetBad panel There is no problem.
This thing happens when I type in TCT, form class Wcontrol type = "TTT" and by pressing the undo BTN (Main Class), the method is executed in wControl because it came Was with the show's message, but the text data is not there ... is empty ??
If I add comment statement, and I run it again, then data displays: TTT will Anne know what I am doing wrong here? Or any suggestion
I think the program is code for you. It's empty because you really are in Wcontrol Are making a new example of, which in turn begin the variable txt_cve with empty text. Check out my comments below:
Undo public zeros (java.util.EventObject newEvent) {class wMenu = Class.forName ("Wcontrol"); Method m = wMenu.getDeclaredMethod ("undo", new class [] {String.class}); // Note # 1: Make a new example of this class object c = wMenu.newInstance (); M.invoke (c, new object [] {new string (this.getClass (). GetName (). ToString ())}); } Public class Wcontrol has expanded JPanel {// Note # 2: txt_cve txt_cve = new javax.swing.JTextField () restart; Public Zero Undo (String In) {// Note # 3: This is an interesting part, you change txt_cve and // txt_cveind has been affected, so you should see txt_cfe in your code as a reference // txt_cveind Will be handed in /*txt_cve.setText("TTT "); First test comment ... * / System.out.println ("data" + txt_cveind.getText ()); Employmentpan Show Messagidoug (this, "data:" + txt_cveind.getText (), "info", 1); }}
Comments
Post a Comment