Made In China Talk  

Go Back   Made In China Talk > International Business Talk > Import
Directory Register FAQ Members List Calendar Mark Forums Read 中文




How Do I Access Another Class In A Higher Level Package In Java?


Reply
 
Thread Tools Display Modes
  #1  
Old 07-23-2009, 12:55 PM
Canada Canada is offline
Senior Member
 
Join Date: Dec 2008
Posts: 2,783
Feedback: (0)
Default How Do I Access Another Class In A Higher Level Package In Java?

My Problem is i created a custom package called modules which contains the logic and event handlers.They both are able to be imported by the main class, but the event handlers needs information from the main program. So i tried Class_Name.GetMethod(); to get the information, however it says it cant find the file. It is not in a package because it is the main program, is the only way i can accomplish this to remove them from the event package and place it with the actual main class file?I tried adding it to a new package, then importing the file but that didnt work either, and i can not make it an interface becuase it is an event handler, which means its implementing actionlistener, with actions to perform listed inside of itIt did not work becuase the main package would be in the same location as the base package of Modules so it could not import the modules, which it can do already without a package holding it, its just the actionlistener classes that i have seperated that i am trying to get information from the main program..the layout> program_main.java> modules>> Events>>>Event_Handler1.java>>>Event_Handler2.java
Reply With Quote




  #2  
Old 07-23-2009, 01:24 PM
gonorth gonorth is offline
Senior Member
 
Join Date: May 2008
Posts: 1,853
Feedback: (0)
Default How Do I Access Another Class In A Higher Level Package In Java?

Some suggestions:1. There is no reason for the main program to be in the base directory.So create a package called mainProg and then put the main program inside that package. When executing, execute the mainProg.MyMain class.2. The design forces the module package to know every program to know about the main class, making the module not portable.Create a MyModuleInterface interface class and then put the methods you need inside that interface, and then make the main program implement the MyModuleInterface.eg: package module;public interface MyModuleInterface{public int GetMethod();}public class MyMainProgram implements MyModuleInterface{// other methods...public int GetMethod(){return 2;}}
Reply With Quote
Reply



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


| Business Forum | Toronto Chinese

All times are GMT +9. The time now is 08:29 PM.


All rights reserved. Copyright 2007 Made In China Talk