Using variable of one  class in another class

what are the different ways in which we can access a variable defined in one class in some other class ,i am aware of making object of that class and using variable ,inheritance polymorphisms,is there any other way

learnerpuneet wrote:
i don't want to use objects of the respective class to access methods and variablesSo you've given up on OO already?
Well okay, then declare everything static and you can use class names to access methods and variables.

Similar Messages

  • Accessing a variable defined in one class from another class..

    Greetings,
    I've only been programming in as3 for a couple months, and so far I've written several compositional classes that take MovieClips as inputs to handle behaviors and interactions in a simple game I'm creating. One problem I keep coming upon is that I'd love to access the custom variables I define within one class from another class. In the game I'm creating, Main.as is my document class, from which I invoke a class called 'Level1.as' which invokes all the other classes I've written.
    Below I've pasted my class 'DieLikeThePhishes'. For example, I would love to know the syntax for accessing the boolean variable 'phish1BeenHit' (line 31) from another class. I've tried the dot syntax you would use to access a MovieClip inside another MovieClip and it doesn't seem  to be working for me. Any ideas would be appreciated.  Thanks,
    - Jeremy
    package  jab.enemy
    import flash.display.MovieClip;
    import flash.events.Event;
    import jab.enemy.MissleDisappear;
    public class DieLikeThePhishes
    private var _clip2:MovieClip; // player
    private var _clip3:MovieClip; //phish1
    private var _clip4:MovieClip; //phish2
    private var _clip5:MovieClip; //phish3
    private var _clip6:MovieClip; //phish4
    private var _clip10:MovieClip; // background
    private var _clip11:MovieClip // missle1
    private var _clip12:MovieClip // missle2
    private var _clip13:MovieClip // missle3
    private var _clip14:MovieClip // missle4
    private var _clip15:MovieClip // missle5
    private var _clip16:MovieClip // missle6
    private var _clip17:MovieClip // missle7
    private var _clip18:MovieClip // missle8
    private var _clip19:MovieClip // missle9
    private var _clip20:MovieClip // missle10
    private var _clip21:MovieClip // missle11
    private var _clip22:MovieClip // missle12
    var ay1 = 0;var ay2 = 0;var ay3 = 0;var ay4 = 0;
    var vy1 = 0;var vy2 = 0;var vy3 = 0;var vy4 = 0;
    var phish1BeenHit:Boolean = false;var phish2BeenHit:Boolean = false;
    var phish3BeenHit:Boolean = false;var phish4BeenHit:Boolean = false;
    public function DieLikeThePhishes(clip2:MovieClip,clip3:MovieClip,clip4:MovieClip,clip5:MovieClip,clip6:M ovieClip,clip10:MovieClip,clip11:MovieClip,clip12:MovieClip,clip13:MovieClip,clip14:MovieC lip,clip15:MovieClip,clip16:MovieClip,clip17:MovieClip,clip18:MovieClip,clip19:MovieClip,c lip20:MovieClip,clip21:MovieClip,clip22:MovieClip)
    _clip2 = clip2;_clip3 = clip3;_clip4 = clip4;_clip5 = clip5;_clip6 = clip6;
    _clip10 = clip10;_clip11 = clip11;_clip12 = clip12;_clip13 = clip13;_clip14 = clip14;
    _clip15 = clip15;_clip16 = clip16;_clip17 = clip17;_clip18 = clip18;_clip19 = clip19;
    _clip20 = clip20;_clip21 = clip21;_clip22= clip22;
    _clip3.stage.addEventListener(Event.ENTER_FRAME, onEnterFrame)
    function onEnterFrame(event:Event):void
    vy1+= ay1;_clip3.y += vy1; vy2+= ay2;_clip4.y += vy2;
    vy3+= ay3;_clip5.y += vy3; vy4+= ay4;_clip6.y += vy4;
    if (phish1BeenHit ==false)
    if(_clip3.y >620)
    {_clip3.y = 620;}
    if (phish2BeenHit ==false)
    if(_clip4.y >620)
    {_clip4.y = 620;}
    if (phish3BeenHit ==false)
    if(_clip5.y >620)
    {_clip5.y = 620;}
    if (phish4BeenHit ==false)
    if(_clip6.y >620)
    {_clip6.y = 620;}
    if (_clip11.hitTestObject(_clip3) ||_clip12.hitTestObject(_clip3)||_clip13.hitTestObject(_clip3)||_clip14.hitTestObject(_cl ip3)||_clip15.hitTestObject(_clip3)||_clip16.hitTestObject(_clip3)||_clip17.hitTestObject( _clip3)||_clip18.hitTestObject(_clip3)||_clip19.hitTestObject(_clip3)||_clip20.hitTestObje ct(_clip3)||_clip21.hitTestObject(_clip3)||_clip22.hitTestObject(_clip3))
    _clip3.scaleY = -Math.abs(_clip3.scaleY);
    _clip3.alpha = 0.4;
    ay1 = 3
    vy1= -2;
    phish1BeenHit = true;
    if (_clip11.hitTestObject(_clip4) ||_clip12.hitTestObject(_clip4)||_clip13.hitTestObject(_clip4)||_clip14.hitTestObject(_cl ip4)||_clip15.hitTestObject(_clip4)||_clip16.hitTestObject(_clip4)||_clip17.hitTestObject( _clip4)||_clip18.hitTestObject(_clip4)||_clip19.hitTestObject(_clip4)||_clip20.hitTestObje ct(_clip4)||_clip21.hitTestObject(_clip4)||_clip22.hitTestObject(_clip4))
    _clip4.scaleY = -Math.abs(_clip4.scaleY);
    _clip4.alpha = 0.4;
    ay2 = 3
    vy2= -2;
    phish2BeenHit = true;
    if (_clip11.hitTestObject(_clip5) ||_clip12.hitTestObject(_clip5)||_clip13.hitTestObject(_clip5)||_clip14.hitTestObject(_cl ip5)||_clip15.hitTestObject(_clip5)||_clip16.hitTestObject(_clip5)||_clip17.hitTestObject( _clip5)||_clip18.hitTestObject(_clip5)||_clip19.hitTestObject(_clip5)||_clip20.hitTestObje ct(_clip5)||_clip21.hitTestObject(_clip5)||_clip22.hitTestObject(_clip5))
    _clip5.scaleY = -Math.abs(_clip5.scaleY);
    _clip5.alpha = 0.4;
    ay3 = 3
    vy3= -2;
    phish3BeenHit = true;
    if (_clip11.hitTestObject(_clip6) ||_clip12.hitTestObject(_clip6)||_clip13.hitTestObject(_clip6)||_clip14.hitTestObject(_cl ip6)||_clip15.hitTestObject(_clip6)||_clip16.hitTestObject(_clip6)||_clip17.hitTestObject( _clip6)||_clip18.hitTestObject(_clip6)||_clip19.hitTestObject(_clip6)||_clip20.hitTestObje ct(_clip6)||_clip21.hitTestObject(_clip6)||_clip22.hitTestObject(_clip6))
    _clip6.scaleY = -Math.abs(_clip6.scaleY);
    _clip6.alpha = 0.4;
    ay4 = 3
    vy4= -2;
    phish4BeenHit = true;
    if (_clip3.y > 10000)
    _clip3.x = 1000 +3000*Math.random()-_clip10.x;
    _clip3.y = 300;
    _clip3.alpha = 1;
    _clip3.scaleY = Math.abs(_clip3.scaleY);
    ay1 = vy1 = 0;
    phish1BeenHit = false;
    if (_clip4.y > 10000)
    _clip4.x = 1000 +3000*Math.random()-_clip10.x;
    _clip4.y = 300;
    _clip4.alpha = 1;
    _clip4.scaleY = Math.abs(_clip4.scaleY);
    ay2 = vy2 = 0;
    phish2BeenHit = false;
    if (_clip5.y > 10000)
    _clip5.x = 1000 +3000*Math.random()-_clip10.x;
    _clip5.y = 300;
    _clip5.alpha = 1;
    _clip5.scaleY = Math.abs(_clip5.scaleY);
    ay3 = vy3 = 0;
    phish3BeenHit = false;
    if (_clip6.y > 10000)
    _clip6.x = 1000 +3000*Math.random()-_clip10.x;
    _clip6.y = 300;
    _clip6.alpha = 1;
    _clip6.scaleY = Math.abs(_clip6.scaleY);
    ay4 = vy4 = 0;
    phish4BeenHit = false;
    var missleDisappear1 = new MissleDisappear(_clip11,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear2 = new MissleDisappear(_clip12,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear3 = new MissleDisappear(_clip13,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear4 = new MissleDisappear(_clip14,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear5 = new MissleDisappear(_clip15,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear6 = new MissleDisappear(_clip16,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear7 = new MissleDisappear(_clip17,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear8 = new MissleDisappear(_clip18,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear9 = new MissleDisappear(_clip19,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear10 = new MissleDisappear(_clip20,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear11 = new MissleDisappear(_clip21,_clip3,_clip4,_clip5,_clip6,_clip10);
    var missleDisappear12 = new MissleDisappear(_clip22,_clip3,_clip4,_clip5,_clip6,_clip10);

    I would approach it in much the same way as you would in java, by making getters and setters for all of your class variables.
    Getters being for returning the values, Setters being for setting them.
    So you would make a get function for the variable you want to access ala:
    function get1PhishBeenHit():boolean {
         return this.phish1BeenHit;
    Then to access the value of that variable from outwith the class:
    var result:boolean = ClassInstanceName.get1PhishBeenHit();

  • Passing a parameter from one class to another class in the same package

    Hi.
    I am trying to pass a parameter from one class to another class with in a package.And i am Getting the variable as null every time.In the code there is two classes.
    i. BugWatcherAction.java
    ii.BugWatcherRefreshAction.Java.
    We have implemented caching in the front-end level.But according to the business logic we need to clear the cache and again have to access the database after some actions are happened.There are another class file called BugwatcherPortletContent.java.
    So, we are dealing with three java files.The database interaction is taken care by the portletContent.java file.Below I am giving the code for the perticular function in the bugwatcherPortletContent.java:
    ==============================================================
    public Object loadContent() throws Exception {
    Hashtable htStore = new Hashtable();
    JetspeedRunData rundata = this.getInputData();
    String pId = this.getPorletId();
    PortalLogger.logDebug(" in the portlet content: "+pId);
    pId1=pId;//done by sraha
    htStore.put("PortletId", pId);
    htStore.put("BW_HOME_URL",CommonUtil.getMessage("BW.Home.Url"));
    htStore.put("BW_BUGVIEW_URL",CommonUtil.getMessage("BW.BugView.Url"));
    HttpServletRequest request = rundata.getRequest();
    PortalLogger.logDebug(
    "BugWatcherPortletContent:: build normal context");
    HttpSession session = null;
    int bugProfileId = 0;
    Hashtable bugProfiles = null;
    Hashtable bugData = null;
    boolean fetchProfiles = false;
    try {
    session = request.getSession(true);
    // Attempting to get the profiles from the session.
    //If the profiles are not present in the session, then they would have to be
    // obtained from the database.
    bugProfiles = (Hashtable) session.getAttribute("Profiles");
    //Getting the selected bug profile id.
    String bugProfileIdObj = request.getParameter("bugProfile" + pId);
    // Getting the logged in user
    String userId = request.getRemoteUser();
    if (bugProfiles == null) {
    fetchProfiles = true;
    if (bugProfileIdObj == null) {
    // setting the bugprofile id as -1 indicates "all profiles" is selected
    bugProfileIdObj =(String) session.getAttribute("bugProfileId" + pId);
    if (bugProfileIdObj == null) {
    bugProfileId = -1;
    else {
    bugProfileId = Integer.parseInt(bugProfileIdObj);
    else {
    bugProfileId = Integer.parseInt(bugProfileIdObj);
    session.setAttribute(
    ("bugProfileId" + pId),
    Integer.toString(bugProfileId));
    //fetching the bug list
    bugData =BugWatcherAPI.getbugList(userId, bugProfileId, fetchProfiles);
    PortalLogger.logDebug("BugWatcherPortletContent:: got bug data");
    if (bugData != null) {
    Hashtable htProfiles = (Hashtable) bugData.get("Profiles");
    } else {
    htStore.put("NoProfiles", "Y");
    } catch (CodedPortalException e) {
    htStore.put("Error", CommonUtil.getErrMessage(e.getMessage()));
    PortalLogger.logException
    ("BugWatcherPortletContent:: CodedPortalException!!",e);
    } catch (Exception e) {
    PortalLogger.logException(
    "BugWatcherPortletContent::Generic Exception!!",e);
    htStore.put(     "Error",CommonUtil.getErrMessage(ErrorConstantsI.GET_BUGLIST_FAILED));
    if (fetchProfiles) {
    bugProfiles = (Hashtable) bugData.get("Profiles");
    session.setAttribute("Profiles", bugProfiles);
    // putting the stuff in the context
    htStore.put("Profiles", bugProfiles);
    htStore.put("SelectedProfile", new Integer(bugProfileId));
    htStore.put("bugs", (ArrayList) bugData.get("Bugs"));
    return htStore;
    =============================================================
    And I am trying to call this function as it can capable of fetching the data from the database by "getbugProfiles".
    In the new class bugWatcherRefreshAction.java I have coded a part of code which actually clears the caching.Below I am giving the required part of the code:
    =============================================================
    public void doPerform(RunData rundata, Context context,String str) throws Exception {
    JetspeedRunData data = (JetspeedRunData) rundata;
    HttpServletRequest request = null;
    //PortletConfig pc = portlet.getPortletConfig();
    //String userId = request.getRemoteUser();
    /*String userId = ((JetspeedUser)rundata.getUser()).getUserName();//sraha on 1/4/05
    String pId = request.getParameter("PortletId");
    PortalLogger.logDebug("just after pId " +pId);  */
    //Calling the variable holding the value of portlet id from BugWatcherAction.java
    //We are getting the portlet id here , through a variable from BugWatcherAction.java
    /*BugWatcherPortletContent bgAct = new BugWatcherPortletContent();
    String portletID = bgAct.pId1;
    PortalLogger.logDebug("got the portlet ID in bugwatcherRefreshAction:---sraha"+portletID);*/
    // updating the bug groups
    Hashtable result = new Hashtable();
    try {
    request = data.getRequest();
    String userId = ((JetspeedUser)data.getUser()).getUserName();//sraha on 1/4/05
    //String pId = (String)request.getParameter("portletId");
    //String pId = pc.getPorletId();
    PortalLogger.logDebug("just after pId " +pId);
    PortalLogger.logDebug("after getting the pId-----sraha");
    result =BugWatcherAPI.getbugList(profileId, userId);
    PortalLogger.logDebug("select the new bug groups:: select is done ");
    context.put("SelectedbugGroups", profileId);
    //start clearing the cache
    ContentCacheContext cacheContext = getCacheContext(rundata);
    PortalLogger.logDebug("listBugWatcher Caching - removing markup content - before removecontent");
    // remove the markup content from cache.
    PortletContentCache.removeContent(cacheContext);
    PortalLogger.logDebug("listBugWatcher Caching-removing markup content - after removecontent");
    //remove the backend content from cache
    CacheablePortletData pdata =(CacheablePortletData) PortletCache.getCacheable(PortletCacheHelper.getUserHandle(((JetspeedUser)data.getUser()).getUserName()));
    PortalLogger.logDebug("listBugWatcher Caching User: " +((JetspeedUser)data.getUser()).getUserName());
    PortalLogger.logDebug("listBugWatcher Caching pId: " +pId);
    if (pdata != null)
    // User's data found in cache!
    PortalLogger.logDebug("listBugWatcher Caching -inside pdata!=null");
    pdata.removeObject(PortletCacheHelper.getUserPortletHandle(((JetspeedUser)data.getUser()).getUserName(),pId));
    PortalLogger.logDebug("listBugWatcher Caching -inside pdata!=null- after removeObject");
    PortalLogger.logDebug("listBugWatcher Caching -finish calling the remove content code");
    //end clearing the cache
    // after clearing the caching calling the data from the database taking a fn from the portletContent.java
    PortalLogger.logDebug("after clearing cache---sraha");
    BugWatcherPortletContent bugwatchportcont = new BugWatcherPortletContent();
    Hashtable httable= new Hashtable();
    httable=(Hashtable)bugwatchportcont.loadContent();
    PortalLogger.logDebug("after making the type casting-----sraha");
    Set storeKeySet = httable.keySet();
    Iterator itr = storeKeySet.iterator();
    while (itr.hasNext()) {
    String paramName = (String) itr.next();
    context.put(paramName, httable.get(paramName));
    PortalLogger.logDebug("after calling the databs data from hashtable---sraha");
    } catch (CodedPortalException e) {
    PortalLogger.logException("bugwatcherRefreshAction:: Exception- ",e);
    context.put("Error", CommonUtil.getErrMessage(e.getMessage()));
    catch (Exception e) {
    PortalLogger.logException("bugwatcherRefreshAction:: Exception- ",e);
    context.put(     "Error",CommonUtil.getErrMessage(ErrorConstantsI.EXCEPTION_CODE));
    try {
    ((JetspeedRunData) data).setCustomized(null);
    if (((JetspeedRunData) data).getCustomized() == null)
    ActionLoader.getInstance().exec(data,"controls.EndCustomize");
    catch (Exception e)
    PortalLogger.logException("bugwatcherRefreshAction", e);
    ===============================================================
    In the bugwatcher Action there is another function called PostLoadContent.java
    here though i have found the portlet Id but unable to fetch that in the bugWatcherRefreshAction.java . I am also giving the code of that function under the bugWatcherAction.Java
    ================================================
    // Get the PortletData object from intermediate store.
    CacheablePortletData pdata =(CacheablePortletData) PortletCache.getCacheable(PortletCacheHelper.getUserHandle(
    //rundata.getRequest().getRemoteUser()));
    ((JetspeedUser)rundata.getUser()).getUserName()));
    pId1 = (String)portlet.getID();
    PortalLogger.logDebug("in the bugwatcher action:"+pId1);
    try {
    Hashtable htStore = null;
    // if PortletData is available in store, get current portlet's data from it.
    if (pdata != null) {
    htStore =(Hashtable) pdata.getObject(     PortletCacheHelper.getUserPortletHandle(
    ((JetspeedUser)rundata.getUser()).getUserName(),portlet.getID()));
    //Loop through the hashtable and put its elements in context
    Set storeKeySet = htStore.keySet();
    Iterator itr = storeKeySet.iterator();
    while (itr.hasNext()) {
    String paramName = (String) itr.next();
    context.put(paramName, htStore.get(paramName));
    bugwatcherRefreshAction bRefAc = new bugwatcherRefreshAction();
    bRefAc.doPerform(pdata,context,pId1);
    =============================================================
    So this is the total scenario for the fetching the data , after clearing the cache and display that in the portal.I am unable to do that.Presently it is still fetching the data from the cache and it is not going to the database.Even the portlet Id is returning as null.
    I am unable to implement that thing.
    If you have any insight about this thing, that would be great .As it is very urgent a promt response will highly appreciated.Please send me any pointers or any issues for this I am unable to do that.
    Please let me know as early as possible.
    Thanks and regards,
    Santanu Raha.

    Have you run it in a debugger? That will show you exactly what is happening and why.

  • How to kill one class from another class

    I need to dipose one class from another class.
    So that first i have to find what are all threads running in that class and then to kill them
    Assist me.

    Subbu_Srinivasan wrote:
    I am explaining you in clear way
    No you haven't been.
    >
    In my application i am handling many JInternalFrame.Simultaneously i am running working on more than one frame.
    Due to some poor performance of some thread in one JInternalFrame,the thread is keeps on running .
    i could not able to proceed further on that screen.
    So i have to kill that JInternalFrame.Yoinks.
    To be begin with your problem sounds like you are doing everything in one thread. So stop doing that. Second when you get it split up and if a task is taking too much time then interrupt it. No kill. Interrupt. This means the worker thread needs to check sometimes if it has been interrupted.

  • Reading a variable from one method to another method

    I am pretty new to Java and object code, so please understand if you think I should know the answer to this.
    I wish to pass a variable from one method to another within one servet. I have a doPost method:
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
              HttpSession session = request.getSession();
             String userID = (String)session.getAttribute("userID");
             String title = request.getParameter("title");
            PrintWriter out = response.getWriter();
            out.println("userID is ..."+userID);
    } and wish to pass the variable userID to:
      public static void writeToDB(String title) {
             try{
                  String connectionURL = "jdbc:mysql://localhost/cms_college";
                  Connection connection=null;     
                 Class.forName("com.mysql.jdbc.Driver");
                 connection = DriverManager.getConnection(connectionURL, "root", "");
                 Statement st = connection.createStatement();         
                   st.executeUpdate ("INSERT INTO cmsarticles (title, userID) VALUES('"+title+"','"+userID+"')");
             catch(Exception e){
                   System.out.println("Exception is ;"+e);
        }because, at the moment the userID cannot be resolved in the writeToDB method. Thanking you in anticipation.

    Thanks for responding.
    If I replace
    public static void writeToDB(String title)with
    public static void writeToDB(String title, String userID)It throws up an error in the following method
    public void processFileItem(FileItem item) {
              // Can access all sorts of useful info. using FileItem methods
              if (item.isFormField()) {
                   //Map<String, String> formParameters = new LinkedHashMap<String, String>();
                   //String filename = item.getFieldName();
                   //String title = item.getString();
                   //System.out.println("received filename is ... " + filename );
                   //formParameters.put(title, filename);
                   } else {
                      // Is an uploaded file, so get name & store on local filesystem
                      String uploadedFileName = new File(item.getName()).getName();            
                      File savedFile = new File("c:/uploads/"+uploadedFileName);
                      long sizeInBytes = item.getSize();
                      System.out.println("uploadedFileName is " + uploadedFileName);
                      String title = uploadedFileName;
                      System.out.println("size in bytes is " + sizeInBytes);
                      writeToDB(title);
                      try {
                        item.write(savedFile);// write uploaded file to local storage
                      } catch (Exception e) {
                        // Problem while writing the file to local storage
              }      saying there are not enough arguments in writeToDB(title);
    and if I put in an extra argumenet writeToDB(title,String userID);
    again it does not recognise userID

  • OBIEE 11g How to pass variable from one prompt to another prompt in dashboard page.

      How to pass variable from one prompt to another prompt in dashboard page.
    I have two prompt in dashboard page as below.
    Reporttype
    prompt: values(Accounting, Operational) Note: values stored as
    presentation variable and they are not coming from table.
    Date prompt values (Account_date, Operation_date)
    Note:values are coming from dim_date table.  
    Now the task is When user select First
    Prompt value  “Accounting” Then in the
    second prompt should display only Accounting_dates , if user select “operational”
    and it should display only operation_dates in second prompt.
    In order to solve this issue I made the
    first prompt “Reporttype” values(Accounting, Operational) as presentation
    values (custom specific values) and default presentation value is accounting.
    In second prompt Date are coming from
    dim_date table and I selected Sql results as shown below.
    SELECT case when '@{Reporttype}'='Accounting'
    then "Dates (Receipts)"."Acct Year"
    else "Dates (Receipts)"."Ops
    Year"  End  FROM "Receipts"
    Issue: Presentation variable value is not
    changing in sql when user select “operation” and second prompt always shows
    acct year in second prompt.
    For testing pupose I kept this presentation
    variable in text object of dashboard and values are changing there, but not in
    second prompt sql.
    Please suggest the solution.

    You will want to use the MoveClipLoader class (using its loadClip() and addListener() methods) rather than loadMovie so that you can wait for the file to load before you try to access anything in it.  You can create an empty movieclip to load the swf into, and in that way the loaded file can be targeted using the empty movieclip instance name.

  • Copy variable from one thread to another

    My program requires user to input a java file which contains the run() method.
    In the input file, user can declare variables and use those variables inside the run method. User also need to enter the number of threads to be spawned.
    The problem is how can I construct some method like "copy" which can copy the variable from one thread to another in my program? I can't do that since I don't know the name of the variables that the user inputted.
    I've tried this:
    class helloworld extends thread{
    void run(){
    String a="hello";
    String b="world";
    copy(0,1,a,b)
    class myProgram {
    Class c = Class.forName(fileName);         // file name of user's file     
    Thread t[] = new Thread[p];             // p is number of threads
         for (int i=0; i<p; i++){             // create threads      
                   t[i] = (Thread) c.newInstance();  
                   t.start();
    public void copy(int sourThread, int destThread, String s1, String s2){
    t[sourThread].s1=t[destThread].s2
    But it doesn't work. It said "cannot resolve symbol s1 and s2".
    please help. urgent. Thanks a lot in advance.

    You need to seriously reconsider what you're allowing the user to do. The short answer to your problem is to use a shared, synchronized associative array.
    However, since the user can specify any number of threads, you will have to resolve deadlocks, and the fact that you're asking this question suggests you will have problems doing so until you have read up on threads and shared variables in more detail. (I don't mean to be dismissive. Deadlocks and shared variables have to be customized to the application, i.e., you have to figure out just when each thread will need access to the variable, what kind of access, and when.)
    In the meantime, take a step back and take a look at the big picture.
    From what you've said, I would guess a common example of your application is that I want to be able to read file "foo.dat", uppercase each letter in the file, and write it out to "fooXXX.dat" where XXX reflects the thread number. And specify any number of threads I want.
    Threads would not be the best way to accomplish this. Do this serially.
    Alternatively, I could interpret your problem as in you need to create a main() function that's capable of reading someone else's dot-class file, clone the object and start it. In which case, why do you want to share variables? If the user did his job correctly, then his file will already contain shared variables (or copy them as appropriate). All you have to do is clone the object via the new keyword, then call start() in it.
    You cannot share something when you don't know what you're sharing.
    The third option is that you're doing this as an academic exercise (i.e., homework). Granted, yes, your professor may ask you to do things illogically just to prove they can be done. Unfortunately, we're not supposed to help you in that case. People who read this forum generally try to find logical and efficient ways of doing things.

  • Passing variables from one swf to another

    I am facing problem to pass variable from one swf to another.
    I am using loadMovie to load another swf. how can I pass a variable
    value to another swf. Can anyone help me plz? It is somewhat
    urgent.
    thanx in advance.

    first of all:
    this is the Flash Media Server and your problem is not
    related to FMS....
    second thing related to the "somewhat urgent" :
    we, users on this forum, are not there to do your job... so
    calm down otherwise no people will answer your question. This forum
    is a free support forum that community of Flash developer use to
    learn tricks and to solve problems.
    Possibles solutions:
    If the two swf are seperate you can use LocalConnection to
    establish a connection between different swf.
    If you load a second swf into the first one you can interact
    like a standard movieClip(only if there from the same domain or if
    you a policy file on the other server)
    You can use SetVariable(via Javascript) to modify a root
    variable on the other swf and check with an _root.onEnterFrame to
    see if the variable had changed in the second swf.
    * MovieClipLoader will do a better job, in your specify case,
    than the loadMovie. Use the onLoadInit event to see when the swf is
    really totaly loaded into the first one otherwise you will have
    timing issues.
    My final answer(lol) is the solution 2 with the
    notice(*)

  • Passing variables from one jsp to another

    Hi All,
    I've searched thru the forum and can't find an answer to a prob I'm having, trying to pass a variable from one jsp to another.
    in file searchBar.jsp i have
    <%
    String archiveSearch = "off";
    %>
    and
    <%
    if (userUtils != null && userUtils.getSearch().equals("on"))
    %>
    <a href="/webLayout/webSideBar.jsp?searchState=<%=archiveSearch%>onclick="archiveSearch = "on""></a>
    and in file webSideBar.jsp
    <%
    String searchState = "off";
    String archiveSearch = (String)request.getParameter("searchState");
    %>
    basically it will give me a variable archiveSearch set to on in webSideBar when the user clicks on the search button, but as it is it's not passing the variable from the searchBar.jsp to the webSideBar.jsp and I think it looks ok !!!! but it's not
    Help

    Looks good to me as well.
    Couple of suggestions
    1 - view source on searchbar.jsp - see what the generated source code for that link is
    2 - Look at the url used to generate webSideBar.jsp. If its not in the address bar, right click the webSideBar page and choose properties.
    Check to see what parameter was passed.
    Are these pages in a frameset? Do you have to specify a target frame for your link?

  • How can I using tpcall from one service to another service in the same server

    When I using tpforward between two services in one server, it's working ok. However,
    when I using tpcall from one service to another service, it's failed?
    anybody can tell me why?
    thanks
    george

    "george" <[email protected]> wrote:
    >
    When I using tpforward between two services in one server, it's working
    ok. However,
    when I using tpcall from one service to another service, it's failed?
    anybody can tell me why?Basically, tpcall:ing another service in the same server is a no-no, unless you
    a) are running a multi-threaded server (requires TUXEDO 7 or newer + compilation
    options) or
    b) use tpacall() instead of tpcall() and specify the flag TPNOREPLY. This is probably
    not what you want to accomplish, though.
    The reason is that TUXEDO servers by default (and always in versions before 7)
    are single-threaded. If service A and B both reside in server X, server X will
    be busy taking care of the call to A. If A makes a call to B, the call will be
    put on the queue to X, but X will not look at the queue until it is done with
    A, which won't happen until B returns... deadlock!
    You can play tricks with starting multiple instances of X, but in the end you
    will always face a risk (something lika a race-condition) for a dead-lock.
    Solution: Move service B to another server (usually quite easy) OR switch to multi-threading,
    if that's possible. Just make sure all code your service calls is MT-safe as well...
    thanks
    georgeHope this helps you,
    /Per

  • Is it possible to pass a variable from one animation to another?

    I have multiple animations on the same page. I need to pass a variable from one to the other.
    Animation One has this:
    sym.setVariable("myVarOne", 1);
    Animation Two has this:
    var myVarOneInTwo=Edge.getComposition("EDGE-12345678").getVariable("myVarOne");
    Seems like it should work, but kinda hard to tell. I put in:
    console.log("myVarOneInTwo = " + myVarOneInTwo);
    But I get: Javascript error in event handler! Event Type = timeline
    So it seems that it doesn't like getting a variable from another animation.
    Is there a way to pull a variable from one animation into another?

    Sorry also had to fix this:
    var myVarOneInTwo=Edge.getComposition("EDGE-12345678").getVariable("myVar One");
    To this:
    var myVarOneInTwo=Edge.getComposition("EDGE-12345678").getStage().getVariable("myVar One");

  • How Do I Run A Class From Another Class?

    Hiya everyone, id like to know how to run a class from another class.
    Ive got a Login class which extends a JFrame and a Personnel class which also extends a JFrame. When i press the login button (in Login class), ive got it to decide if password/login are acceptable and if they are, I want the Login class to close then run the Personnel class.
    Im just after the code which says to close this class and run the Personnel class. How do i do that?
    Ive researched this but couldnt get an understandable answer!
    Help would be much appreciated, Ant...

    This is the Login Class:
    public class MainMenu extends javax.swing.JFrame {
        Statement statement = null;
        int currentRecord;
        ResultSet rs = null;
        String name = null, job = null, mission = null, login = null, password = null;
        String loginVal;
        String passwordVal;
        /** Creates new form MainMenu */
        public MainMenu() {
            initComponents();
            try{
                Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                String filename = System.getProperty("user.dir") + "/src/Personnel.mdb";
                String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=" + filename;
                Connection conn = DriverManager.getConnection( database , "","");
                statement = conn.createStatement();
                System.out.println("Connected...ok");
            } catch (Exception e) {
                System.err.println("Got a connection Problem!");
                System.err.println(e.getMessage());
        private void btnLoginActionPerformed(java.awt.event.ActionEvent evt) {                                        
            loginVal = txtLogin.getText();
            passwordVal = txtPassword.getText();
            String name = null, job = null, mission = null, login = null, password = null;
            try{
                rs = statement.executeQuery("SELECT Login,Password FROM Personnel WHERE Login = '" + loginVal + "' ");
                System.out.println("TRYING SELECT CLAUSE");
                if(rs.next()){
                    System.out.println("THERE IS A NEXT RECORD");
                    login = rs.getString(1);
                    password = rs.getString(2);
                    System.out.println("GOT THE NEXT RECORD");
                    System.out.println(login + password);
                System.out.println("Query Complete");
            }catch(Exception s){
                //s.printStackTrace();
                System.out.println("NO RECORDS EXIST FOR THIS LOGIN ID");
            if(passwordVal.equals(password)){
                System.out.println("Access Granted"); //CLOSE MAIN AND RUN CONTROL CLASS
            } else{
                System.out.println("Access Denied"); //RE-RUN CLASS
        }                 

  • What is the utility called to be able to use MSOffice from one mac to another?

    what is the utility called to be able to use MSOffice from one mac to another?
    thanks

    Remote Desktop Connection?
    Screen Sharing?

  • How to pass a variable from one class to another class?

    Hi,
    Is it possible to pass a variable from one class to another? For e.g., I need the value of int a for calculation purpose in method doB() but I get an error <identifier> expected. What does the error mean? I know, it's a very, very simple question but once I learn this, I promise to remember it forever. Thank you.
    class A {
      int a;
      int doA() {
          a = a + 1;
          return a;
    class B {
      int b;
      A r = new A();
      r.a;  // error: <identifier> expected. What does that mean ?
      int doB() {
         int c = b/a;  // error: operator / cannot be applied to a
    }Thank you!

    elaine_g wrote:
    I am wondering why does (r.a) give an error outside the method? What's the reason it only works when used inside the (b/r.a) maths function? This is illegal syntax:
    class B {
      int b;
      A r = new A();
      r.a;  //syntax error
    }Why? Class definition restricts what you can define within a class to a few things:
    class X {
        Y y = new Y(); //defining a field -- okay
        public X() { //defining a constructor -- okay
        void f() { //defining a method -- okay
    }... and a few other things, but you can't just write "r.a" there. It also makes no sense -- that expression by itself just accesses a field and does nothing with it -- why bother?
    This is also illegal syntax:
    int doB() {
          A r = new A();
          r.a;  // error: not a statement
    }Again, all "r.a" does on its own is access a field and do nothing with it -- a "noop". Since it has no effect, writing this indicates confusion on the part of the coder, so it classified as a syntax error. There is no reason to write that.

  • Use a counter from one class to another class of the same project

    Hello!
    In my class Book I have a variable, which is in fact a counter, counts the number of books. I need to use this same variable in another class Library, and I want to know if this is possible by any means!
    Thank You very much for Your support!

    Read this carefully.
    Regards,

Maybe you are looking for

  • Transfer Intra-Company

    Dear all , We are thinking in use the importation process from our company in the USA to Brazil. So , could I use the same concept of STO to have the stock in transit and here Post invoice from complementary costs directly to this PO or STO on MIRO ?

  • Is JDK need to install prior to 11g Binary installation

    Hi All, I am planning to install 11.2.0 on Suse Linux 10. Prior to the install i checked Preinstall validation using RDA, it says :- Rule A00200: JDK Version Description This rule checks that the installed JDK version is JDK 5.0 update 6 or later. Th

  • Code for reading the and placing the file using java webservice

    Hi All, Can anybody can guide me on how to read a file and place the file using java. Let  me know if any code is available which has been completed using java. Regards, Rahul

  • Comments have disappeared and iweb replublishes more then it should

    Today I wanted to upload a new blog. First of all, iweb started republishing all my picture books, which were unchanged.. so that took a lot of extra time. When this all finished, I got a mobile me publishing error. When I checked my site online, I n

  • Error in MSS Personal Change Request (PCR)

    The PCR Team Viewer gives an error saying that "An error occurred: com.sap.pct.hcm.objectanddataprovider.proxyclasses.Hrwpc_Rfc_Get_Objects_FaultException: " Can anyone suggest me what can be the reason of this error? Thanking you Mukesh Adwani SAP N