473,396 Members | 1,963 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

help with passing class interface in getContructor() and newInstance()

Can I passing class interface in getContructor and newInstance()....

Expand|Select|Wrap|Line Numbers
  1. public interface face{
  2.   public void message(String m) ;
  3. }
  4. public class Test {
  5.   private Face iFace = null ;
  6.   private JPanel theBody = null ;
  7.   private JFrame jFrame = null;
  8.   public static void main(String[] args) {
  9.     SwingUtilities.invokeLater(new Runnable() {
  10.       public void run() {
  11.         Test application = new Test ();
  12.         application.getJFrame().setVisible(true);
  13.       }
  14.     });
  15.   }
  16.   private JFrame getJFrame() {
  17.     if (jFrame == null) {
  18.       iFace = new faceData() ;
  19.       jFrame = new JFrame() ;
  20.       body = jFrame.getContentPane() ;
  21.       body.setLayout(new BorderLayout()) ;
  22.       body.add(getBody(), BorderLayout.CENTER) ;
  23.       body.add(getButton(), BorderLayout.SOUTH) ;
  24.     }
  25.     return jFrame;
  26.   }
  27.   private JPanel getBody(){
  28.     if (theBody == null){
  29.       theBody = new emptyBody(screen) ;
  30.     }
  31.     return theBody  ;
  32.   }
  33.   private JButton getButton(){
  34.     JButton b = new JButton() ;
  35.     b.setName(nama) ;
  36.     b.addMouseListener(new MouseAdapter(){
  37.       public void mousePressed(MouseEvent e){
  38.         iFace.message("Home") ;
  39.       }
  40.     });
  41.   }
  42.   private class faceData implements Face{
  43.     public void message(String m) {
  44.       body.remove(theBody) ;
  45.       theBody = runObj(m, iFace);
  46.       body.add(theBody , BorderLayout.CENTER);
  47.       body.validate();
  48.     }
  49.   }
  50.   private runObj(String m, Face f){
  51.     ClassLoader cld = null ;
  52.     Class       cls = null ;
  53.     Constructor con = null;
  54.     Object      obj = null;
  55.     File file = new File(System.getProperty("user.dir"));
  56.     try {
  57.     URL url = file.toURL();
  58.     URL[] urls = new URL[]{url};
  59.     cld = new URLClassLoader(urls)
  60.         cls = cld.loadClass(m);
  61.     con = cls.getConstructor(new Class[]{Face.class});
  62.     obj = con.newInstance(new Object[] {f});
  63.     }
  64.     catch(.....}
  65.     return (JPanel) obj ;
  66.    }
  67. }
  68. public class Home Extend JPanel{
  69.   private Face iFace = null ;
  70.   public Home(Face f){
  71.     iFace = f;
  72.     initialize() ;
  73.   }
  74.   private void initialize{...}
  75. }
is my code right or there's any good advice?
Please help!!! thanks
Aug 23 '11 #1
0 1053

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: ChrisB | last post by:
Hello: I am writing an application using C# that needs to support several queries that limit the number of returned records through the use of filtering and was hoping to get some opinions on...
2
by: Robert V. Hanson | last post by:
I have a user control built using the Microsoft IE Control. I declared a public variable as int32 (DefaultTab) in the user control. I can't seem to provide the correct syntax to the tabstrip...
5
by: Darious Snell | last post by:
I am using windows forms and vb.net. My problem is a little complex so please bear with me. I have written an application that references a .com based API linked to an external client...
5
by: owais | last post by:
Hi, I have a problem, I want to implements Parent class interface methods in child class. for e.g -------------- Test1.vb ---------------- Imports System Imports System.Web.UI Imports...
2
by: fujiyama | last post by:
Hi, I have a problem with reuse of the same class interface. I have two user controls which uses the same IAppElement interface. When I use both controls I recieve warning message warning CS0436 -...
2
by: Kevin Frey | last post by:
In a derived class I am trying to redefine the implementation of a interface method defined in a base class - the base class interface method was not declared virtual. I have yet to actually...
2
by: audiokarate | last post by:
I have like atleast 15 errors that say class, interface, or enum expected and I have no idea what that means. Can someone tell me what it is and how I might be able to fix it? Thank you. - Manny...
1
jenkinsloveschicken
by: jenkinsloveschicken | last post by:
I am needing help passing a GET variable to a receiving php page. This html page does not contain an forms for submission(POST/GET methods). First I need to parse the URL string using...
0
by: kirthi kumari | last post by:
i donot find any errors,but for almost 18lines of the code am getting an error saying "class,interface or enum expected error".please look at the code below package NQ; import...
0
by: Shobhit parashe | last post by:
Hi All, I m passing Class as a input values in Webmethod of Webservice and how to call these Webmethod? pls help me solve this problem. Thanks
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.