Determine a string from main class in an outside class

Hello there,
This might be stupid question but I cant think, I am so very tired. Okay here is the question, is there any way we could see or the get the value of a string(just a string which is set in main class'A', its already set, we cannot make it static r anything like that)in a method outside that main class, probably in a method 'x' in class'C'.
Thanks
potti

Yes, you can, in many ways, or else Java would be moot. Excluding the static way of doing it, which by the way is evil, your class C can make an instance of class A and then access it either as a public field or as the value returned by a public method. You can also use inheritance, but it's pointless in this case, inheritance is meant to abstract, extend functionality, and prevent having to rewrite code. It's not meant for accessing fields. And by the way, inheritance, too, is evil.
This is one way to do it.
class A {
     public String s = "great balls of fire";
public class C {
     public static void main(String[] args) {
          A myInstance = new A();
          String s = myInstance.s;
          System.out.println(s);
}This is the preferred way to do it, as it encapsulates the String. The idea of encapsulation is to access fields by a method instead of directly since interfaces are less likely to change than an object's data and in the case that the object's data does change and the interface does not, the changes will remain local.
class A {
     private String s = "great balls of fire";
     public String getS() { return s; }
public class C {
     public static void main(String[] args) {
          A a = new A();
          String s = a.getS();
          System.out.println(s);
}

Similar Messages

  • Find string from main string

    Hi all
    I have one location
    E:\Testing\Test.xlxs
    now I need only file name from this path.
    what expression should I write to get this filename.
    I need
    Test only.
    Kindly help
    Thanks

    Thanks for help
    .Actually RIGHT( @[User::Path] ,FINDSTRING(REVERSE( @[User::Path] ),"\\",1)-1)
    gives
    test.xlsx
    but i need test only wihtout extension.
    SUBSTRING( RIGHT( @[User::Path] ,FINDSTRING(REVERSE( @[User::Path] ),"\\",1)-1)  , 1 , FINDSTRING( RIGHT( @[User::Path] ,FINDSTRING(REVERSE( @[User::Path] ),"\\",1)-1), "." , 1) -1 )
    Regards, RSingh

  • Class field initialization outside class constructor

    Hi,
    what are the benefits of initializing a class field outside the class constructor? I use this for fields, that i do not need to pass parameter to via the constructor. The code seems more clear/easy to read.

    Hi,
    what are the benefits of initializing a class field
    outside the class constructor? I use this for
    fields, that i do not need to pass parameter to via
    the constructor.
    The code seems more clear/easy to read.That's a pretty big benefit.
    For another, consider when you have multiple constructors: you've factored
    common code out of them (good) and made it impossible to forget to
    initialize that field later when, later on, you write another constructor(also good).

  • Re: Passing a string from Java class to JSP

    How can I pass a string from a function within my bean class to my JSP page?
    I would like to pass something like this with the necessary params filled in:
    String myString ="Successful <b>" + Sales.getActionType() + "</b> was made on <b>" + (new Date()).toString();
    The ActionType will be either a BUY or SELL and the current date need to be added in.
    Thank you in advance!

    SOLVED THE PROBLEM!!!

  • Material exchane ,copy pricing and conditions from main item to sub item.

    Hi All,
    We are using parts exchange/interchangeability in the transaction ME22N,
    While using ME22N we are exchanging  main item with interchangeable part and while doing so we want to copy pricing and conditions from main item to sub item.
    But its not happening.
    As per sap help its possible, details describe below.
    http://help.sap.com/erp2005_ehp_04/helpdata/en/c2/0a5288b77d11d3bcce00105ab03aee/content.htm
    Price Determination by Copying from Main Item
    In the case of price determination by copying from the main item, the net price of the originally ordered part is still used for the superseding part in a part exchange.
    The system copies all conditions from the main item to all sub-items and takes into account the order quantity for the main item when calculating scale prices. It does not take into account the conditions and scale prices that exist for the interchangeable part.
    You cannot change the conditions, which have been copied from the main item, at sub-item level. It is possible, however, to define additional conditions for each sub-item.
    Prerequisites
    A calculation schema, which can be altered on an individual basis in Customizing, has been supplied for the price determination.
    In the vendor master record, you have set the schema group 09 (interchangeable material).
    But in customizing I didnu2019t find value 09 for schema group .
    Can any buddy through some light on missing pieces which need to be set?
    Thanks
    Regards
    Ritesh

    Hi,
    Can you check few more things and tell me?
    - In this exit, does XVBPA and XVBAP contains all the line items. ( main and sub items ).
    - In Sales order creation time, do these table have VBELN populated when this exit triggers.
    - If you modify XVBPA or XVBAP in this exit, do they get overwritten after that.
    Try this code. See if it works.  Let me know if you still have a problem.
    DATA: wa_hvbpa LIKE vbpa,
          wa_xvbpa like vbpa.
    CLEAR: wa_hvbpa, wa_xvbpa.
    * check if HVBAP and VBAP line items are not same
    IF vbap-posnr <> hvbap-posnr.
    * read the ****-to partner from main-item
      READ TABLE xvbpa INTO wa_hvbpa WITH KEY posnr = hvbap-posnr
                                              parvw = 'WE'.
      IF sy-subrc = 0.
    *   read the line item data for sub-item based on main item
        READ TABLE xvbap WITH KEY posnr = vbap-posnr
                                  uepos = hvbap-posnr.
    * See if current line is the child of that BoM parent
        IF sy-subrc = 0.
          MOVE wa_xvbpa-kunnr TO xvbpa-kunnr.
          MOVE xvbap-vbeln TO wa_xvbpa-vbeln.
          MOVE xvbap-posnr TO wa_xvbpa-posnr.
          MOVE 'WE' TO wa_xvbpa-parvw.
          MODIFY vbpa FROM wa_xvbpa.
        ENDIF.
      ENDIF.
    ENDIF.
    Regards,
    RS

  • How can I assign image file name from Main() class

    I am trying to create library class which will be accessed and used by different applications (with different image files to be assigned). So, what image file to call should be determined by and in the Main class.
    Here is the Main class
    import org.me.lib.MyJNIWindowClass;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    MyJNIWindowClass mw = new MyJNIWindowClass();
    mw.s = "clock.gif";
    And here is the library class
    package org.me.lib;
    public class MyJNIWindowClass {
    public String s;
    ImageIcon image = new ImageIcon("C:/Documents and Settings/Administrator/Desktop/" + s);
    public MyJNIWindowClass() {
    JLabel jl = new JLabel(image);
    JFrame jf = new JFrame();
    jf.add(jl);
    jf.setVisible(true);
    jf.pack();
    I do understand that when I am making reference from main() method to MyJNIWindowClass() s first initialized to null and that is why clock could not be seen but how can I assign image file name from Main() class for library class without creating reference to Main() from MyJNIWindowClass()? As I said, I want this library class being accessed from different applications (means different Main() classes).
    Thank you.

    Your problem is one of timing. Consider this simple example.
    public class Example {
        public String s;
        private String message = "Hello, " + s;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example();
            ex.s = "world";
            System.out.println(ex.toString());
    }When this code is executed, the following happens in order:
    1. new Example() is executed, causing an object to constructed. In particular:
    2. field s is given value null (since no value is explicitly assigned.
    3. field message is given value "Hello, null"
    4. Back in method main, field s is now given value "world", but that
    doesn't change message.
    5. Finally, "Hello, null" is output.
    The following fixes the above example:
    public class Example {
        private String message;
        public Example(String name) {
            message = "Hello, " + name;
        public String toString() {
            return message;
        public static void main(String[] args) {
            Example ex = new Example("world");
            System.out.println(ex.toString());
    }

  • Call function, pass value, access variable in movieclip class from main stage

    i am new to flash as.
    I got quite confused on some problems. as the function here
    is quite different from c and asp.net.
    I have a movieClip named MC, and it's enabled with action
    script, with the class name MC_Rectangle
    and a Stage.
    I override the MC_Rectangle class file in a mc_rectangle.as
    external file.
    here is the code:
    package{
    import flash.display.*;
    import flash.events.*;
    public class MC_Rectangle extends MovieClip {
    var sequence:int = new int();
    function setSequence(data:int):void{
    sequence = data;
    function addSequence():void{
    sequence ++;
    I have new a object in the main stage var
    mc_rect:MC_Rectangle = new MC_Rectangle()
    question:
    in main stage:
    1. how can i access the variable "sequence" in "mc_rect"
    2. how can i pass parametre from main stage to mc_rect via
    function setSequence(data:int)?
    3. how can i call the function in addSequence() in mc_rect.
    in asp.net, i usually use mc_rect.sequenct,
    mc_rect.setSequence(data), mc_rect.addSequence() to achieve my
    goals......
    btw, can function in mc_rect return out result to main stage?
    thanks in advance.

    Your as-file must be named MC_Rectangle.as (same upper/lower
    case as in the Class name)
    Ad 1) You have to declare sequence as a public property
    "public var sequence;" or - better - define a getter-function for
    sequence.
    Ad 2) mc_rect.setSequence(8); e. g. (you must write "public"
    in the Class-declaration of setSequence)
    Ad 3) mc_rect.addSequence(); e. g. (you must write "public"
    in the Class-declaration of addSequence)
    ... and yes, your methods can return a value: Replace "void"
    with the proper data type (int, String, ...) and place a "return
    myNumber;" or the like in the method's body.

  • Is it possible to modify private member of a class directly from main?

    This is the code which modifies the private String stk[] indirectly from main method when sorting option is called from main method:
    import java.io.*;
    class Stack
        private String stk[];
        private int tos;
        private int size;
        Stack()
            size=5;
            stk=new String[size];
            tos=-1;
        Stack(int sz)
            size=sz;
            stk=new String[size];
            tos=-1;
        boolean push(String s)
            if(tos==size-1) return false;
            stk[++tos]=s;
            return true;
        String pop()
            if(tos<0) return "Stack Underflow";
            return stk[tos--];
        String[] display()//array type function to return an array called "stk"
            return stk;
        int returnSize()
            return tos;
    class myStack
        public static void main(String args[]) throws IOException
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            Stack S=new Stack();
            int opt=-1;
            while(opt!=6)
                System.out.println("\n\n\n");
                System.out.println("[1] - Create Stack");
                System.out.println("[2] - Push");
                System.out.println("[3] - Pop");
                System.out.println("[4] - Display");
                System.out.println("[5] - Display List In Ascending Order");
                System.out.println("[6] - Exit");
                System.out.print("Option: ");
                opt=Integer.parseInt(br.readLine());
                if(opt==1)
                    System.out.print("\n\nEnter the size of stack: ");
                    int size=Integer.parseInt(br.readLine());
                    S=new Stack(size);
                    System.out.print("\nStack Created...");
                else if(opt==2)
                    System.out.print("\n\nEnter String: ");
                    String s=br.readLine();
                    if(S.push(s))
                        System.out.print("\nSuccessfull...");
                    else
                        System.out.print("\nStack Overflow...");
                else if(opt==3)
                    System.out.print("\nItem Deleted: "+S.pop());
                else if(opt==4)
                    int sz=S.returnSize();
                    System.out.print("\n\n\nStack Contains: "+(sz+1)+" Item(s)\n");
                    String st[]=S.display();
                    while(sz>=0)
                        System.out.println(st[sz]);
                        sz--;
                else if(opt==5)
                    int s=S.returnSize();
                    String stc[]=S.display();
                    for(int i=0;i<=s;i++)
                        for(int j=i+1;j<=s;j++)
                            if(stc[j].compareTo(stc[i])<0)
                                String t=stc[i];
                                stc[i]=stc[j];
                                stc[j]=t;
                    System.out.println(stc[i]);
                else if(opt>6)
                    System.out.print("\nPress 6 To Exit....");

    Actually, since it is returning the reference value of the array, and he is changing the array elements using that reference, then he IS "changing the array".
    @OP:  When you return a reference value to an object (and, in this regard, an array IS an object), then use that reference value to change things in the object (NOT assigning a new value to the variable holding that reference value), then, of course, those items are changed, and everything using that same reference value will "see" those changes, as they ALL point to the SAME object.
    Edit:  My first answer was going under the assumption that you meant DIRECTLY changing (i.e. stk = ...) since all you provided was the "title" and a blurb of code.  Next time you should think about actually providing some information about the actual "problem".
    See http://www.javaranch.com/campfire/StoryCups.jsp (to get associated with the "terms" they use)
    then see http://www.javaranch.com/campfire/StoryPassBy.jsp for some easy to understand explanations of reference values and objects.

  • Is it possible to modify private member of a class directly from main function?

    This is the code which modifies the private String stk[] indirectly from main method when sorting option is called from main method:
    import java.io.*;
    class Stack
        private String stk[];
        private int tos;
        private int size;
        Stack()
            size=5;
            stk=new String[size];
            tos=-1;
        Stack(int sz)
            size=sz;
            stk=new String[size];
            tos=-1;
        boolean push(String s)
            if(tos==size-1) return false;
            stk[++tos]=s;
            return true;
        String pop()
            if(tos<0) return "Stack Underflow";
            return stk[tos--];
        String[] display()//array type function to return an array called "stk"
            return stk;
        int returnSize()
            return tos;
    class myStack
        public static void main(String args[]) throws IOException
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            Stack S=new Stack();
            int opt=-1;
            while(opt!=6)
                System.out.println("\n\n\n");
                System.out.println("[1] - Create Stack");
                System.out.println("[2] - Push");
                System.out.println("[3] - Pop");
                System.out.println("[4] - Display");
                System.out.println("[5] - Display List In Ascending Order");
                System.out.println("[6] - Exit");
                System.out.print("Option: ");
                opt=Integer.parseInt(br.readLine());
                if(opt==1)
                    System.out.print("\n\nEnter the size of stack: ");
                    int size=Integer.parseInt(br.readLine());
                    S=new Stack(size);
                    System.out.print("\nStack Created...");
                else if(opt==2)
                    System.out.print("\n\nEnter String: ");
                    String s=br.readLine();
                    if(S.push(s))
                        System.out.print("\nSuccessfull...");
                    else
                        System.out.print("\nStack Overflow...");
                else if(opt==3)
                    System.out.print("\nItem Deleted: "+S.pop());
                else if(opt==4)
                    int sz=S.returnSize();
                    System.out.print("\n\n\nStack Contains: "+(sz+1)+" Item(s)\n");
                    String st[]=S.display();
                    while(sz>=0)
                        System.out.println(st[sz]);
                        sz--;
                else if(opt==5)
                    int s=S.returnSize();
                    String stc[]=S.display();
                    for(int i=0;i<=s;i++)
                        for(int j=i+1;j<=s;j++)
                            if(stc[j].compareTo(stc[i])<0)
                                String t=stc[i];
                                stc[i]=stc[j];
                                stc[j]=t;
                    System.out.println(stc[i]);
                else if(opt>6)
                    System.out.print("\nPress 6 To Exit....");

    Short answer is: no.
    Long answer is: you should not try to. Information hiding is the fundamental principle of OOP. This means that the code dealing with an object has no knowledge about the objects inner structure. It only knows the methods provided by its interface.
    You should declare all object properties private and prevent any other code outside the owning class to manipulate it. This includes leaking properties via "getter" methods. In your example the display() method is bad in two ways:
    its name does not convey its purpose.
    it a "getter" that returns the private property stk to the caller who may change it. Eg. the caller could add or delete an entry without changing tos accordingly.
    bye
    TPD

  • Running a method in a class from main.mxml

    So... this seems dumb, but I can't seem to run a method on an instance of a class. I should be able to
    arraycollectioninstance[0].methodinclass();    //this doesn't work
    I also tryed arraycollectioninstanace.getItemAt().methodinclass();
    All I want to do in run the function sortByUdn() that resides in the class definition from main.mxml on an instance of an arraycolleection. How do I do this and why doesn't the above attempts work? What am I missing?
    Below is my class:
    package status
    import mx.collections.ArrayCollection;
    import mx.collections.IViewCursor;
    import mx.collections.Sort;
    import mx.collections.SortField;
    import org.osmf.layout.AbsoluteLayoutFacet;
    [Bindable]
    public class Rack
      public var currentSort:String = 'udn';
      public var lowestUdn:int;
      public var highestUdn:int;
      public var circuits:int;
      public var rackModel:String;
      public var rackLevels:ArrayCollection = new ArrayCollection;
      public function Rack(response:XMLList):void
       circuits = response[0].info.length();
       for (var i:int=0; i < circuits; i++)
        rackLevels.addItem(new Level(
         response[0].info[i].@udn,
         response[0].info[i].@circuit,
         response[0].info[i][email protected](),
         response[0].info[i][email protected]()
       findMinMax();
    protected function sortByUdn():void
       var udnSort:Sort = new Sort()
       udnSort.fields = new Array();
       udnSort.fields.push(new SortField('udn',true,false,true));
       this.rackLevels.sort = udnSort;
       this.rackLevels.refresh();

    Thanks for the response!!!
    So my problem is that my class (Rack) has the functions, but I'm using an arraycollection of instances of this class. So in my main Application I have:
    public var current_rack:ArrayCollection = new ArrayCollection;
    then later on I'm using a current_rack.addItem(new Rack(.......)  several times to make the instances.
    I'm trying to call a function in one instance of current_rack[7] to perform a sort on that instance. I'm storing the sort function as part of the class, as it sorts the inards of the class instance.
    I really want to current_rack[0].sortByUdn();
    Though the above doesn't generate a compiler error, I get a runtime error of RangeError: 'Index '0' specified is out of bounds'

  • Reference to string from another class

    I've searched google and this forum a bit, but can't seem to find an answer. I'd say the thing I'm looking for is really simple and essential, so I must be a moron. But anyways; I want to get the output of the "process" thing in another class. How do I reference to that string fomr outside it's class?
    Thanks.
    public class ReadInput {
         private static void printCommands() {
             System.out.println("blabla");
             System.out.println("blabla");
             System.out.println("blabla");
    public static void process(String in) {
              Do something with the String "in" here. Say, eventually rename it to "output".
    public static void doReadFromStdin() {
         try {
             BufferedReader inStream = new BufferedReader (
                                             new InputStreamReader(System.in)
             String inLine = "";
             String in = inLine;
             while ( !(in.equalsIgnoreCase("quit"))
                     !(in.equalsIgnoreCase("exit")) ) {
                 System.out.print("prompt> ");
                 in = inStream.readLine();
                 process(in);
         } catch (IOException e) {
             System.out.println("IOException: " + e);
    public static void main(String[] args) {
          printCommands();
         doReadFromStdin();
    }

    Maybe this might help
    Igor_Pavlove wrote:
    public static void process(String in) {     
    Do something with the String "in" here. Say, eventually rename it to "output".
    public static String process(String in){
      //Do something, e.g.
      String temp = "ifeeltired";
      return temp;  //Returns the String temp when this method is called.
    public static void main(String[] args) {
         printCommands();
    doReadFromStdin();
    public static void main(String[] args){
      String temp = "thisisaroughexamples";
      String result = this.process(temp); //Returns a string and stores it in result
      CreatePlural.print(result);  //This is possible because the method print() in CreatePlural is static and an instance of CreatePlural is not required.
    }Edited by: Melanie_Green on Feb 2, 2009 6:46 AM
    Edited by: Melanie_Green on Feb 2, 2009 6:47 AM

  • Need help with custom event from Main class to an unrelated class.

    Hey guys,
    I'm new to Flash and not great with OOP.  I've made it pretty far with google and lurking, but I've been pulling my hair out on this problem for a day and everything I try throws an error or simply doesn't hit the listener.
    I'm trying to get my Main class to send a custom event to an unrelated class called BigIcon.  The rest of the code works fine, it's just the addEventListener and dispatchEvent that isn't working.
    I've put in the relevant code in below.  Let me know if anything else is needed to troubleshoot.  Thank you!
    Main.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        public class Main extends MovieClip
            var iconLayer_mc:MovieClip = new MovieClip();
            public function Main()
                Spin_btn.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
                addChildAt(iconLayer_mc,0);
                placeIcons();
            function placeIcons():void
                var i:int;
                var j:int;
                for (i = 0; i < 4; i++)
                    for (j = 0; j < 5; j++)
                        //iconString_array has the names of illustrator objects that have been converted to MovieClips and are in the library.
                        var placedIcon_mc:BigIcon = new BigIcon(iconString_array[i][j],i,j);
                        iconLayer_mc.addChild(placedIcon_mc);
            function fl_MouseClickHandler(event:MouseEvent):void
                dispatchEvent(new Event("twitchupEvent",true));
    BigIcon.as
    package
        import flash.display.MovieClip;
        import flash.events.Event;
        import flash.utils.getDefinitionByName;
        public class BigIcon extends MovieClip
            private var iconImage_str:String;
            private var iconRow_int:int;
            private var iconColumn_int:int;
            public function BigIcon(iconImage_arg:String, iconRow_arg:int, iconColumn_arg:int)
                iconImage_str = iconImage_arg;
                iconRow_int = iconRow_arg;
                iconColumn_int = iconColumn_arg;
                this.addEventListener(Event.ADDED_TO_STAGE, Setup);
            function Setup(e:Event)
                this.y = iconRow_int;
                this.x = iconColumn_int;
                var ClassReference:Class = getDefinitionByName(iconImage_str) as Class;
                var thisIcon_mc:MovieClip = new ClassReference;
                this.addChild(thisIcon_mc);
                addEventListener("twitchupEvent", twitchUp);
            function twitchUp(e:Event)
                this.y +=  10;

    Ned Murphy wrote:
    You should be getting an error for the Main.as class due to missing a line to import the Event class...
    import flash.events.Event;
    My apologies, I should attempt to compile my example code before I ask for help...
    Alright, this compiles, gives me no errors, shows my 'book' and 'flowers' icons perfectly when ran, and prints 'addEventListener' to the output window as expected.  I get no errors when I press the button, 'dispatchEvent' is output (good), but the 'twitchUp' function is never called and 'EventTriggered' is never output. 
    How do I get the 'twitchUp' event to trigger?
    Main.as
    package
        import flash.display.MovieClip;
        import flash.events.MouseEvent;
        import flash.events.*;
        public class Main extends MovieClip
            var iconLayer_mc:MovieClip = new MovieClip();
            var iconString_array:Array = new Array(2);
            public function Main()
                Spin_btn.addEventListener(MouseEvent.CLICK,fl_MouseClickHandler);
                addChildAt(iconLayer_mc,0);
                buildStringArray();
                placeIcons();
            function buildStringArray():void
                var i:int;
                var j:int;
                for (i = 0; i < 2; i++)
                    iconString_array[i] = new Array(3);
                    for (j = 0; j < 3; j++)
                        if (Math.random() > .5)
                            //'flowers' is the name of an illustrator object that has been converted to a MovieClip and is in the library
                            iconString_array[i][j] = "flowers";
                        else
                            //'book' is the name of an illustrator object that has been converted to a MovieClip and is in the library
                            iconString_array[i][j] = "book";
            function placeIcons():void
                var i:int;
                var j:int;
                for (i = 0; i < 2; i++)
                    for (j = 0; j < 3; j++)
                        //iconString_array has the names of illustrator objects that have been converted to MovieClips and are in the library.
                        var placedIcon_mc:BigIcon = new BigIcon(iconString_array[i][j],i*50,j*50);
                        iconLayer_mc.addChild(placedIcon_mc);
            function fl_MouseClickHandler(event:MouseEvent):void
                dispatchEvent(new Event("twitchupEvent",true));
                trace("dispatchEvent");
    BigIcon.as
    package
        import flash.display.MovieClip;
        import flash.events.*;
        import flash.utils.getDefinitionByName;
        public class BigIcon extends MovieClip
            private var iconImage_str:String;
            private var iconRow_int:int;
            private var iconColumn_int:int;
            public function BigIcon(iconImage_arg:String, iconRow_arg:int, iconColumn_arg:int)
                iconImage_str = iconImage_arg;
                iconRow_int = iconRow_arg;
                iconColumn_int = iconColumn_arg;
                this.addEventListener(Event.ADDED_TO_STAGE, Setup);
            function Setup(e:Event)
                this.y = iconRow_int;
                this.x = iconColumn_int;
                var ClassReference:Class = getDefinitionByName(iconImage_str) as Class;
                var thisIcon_mc:MovieClip = new ClassReference;
                this.addChild(thisIcon_mc);
                addEventListener("twitchupEvent", twitchUp);
                trace("addEventListener");
            function twitchUp(e:Event)
                this.y +=  10;
                trace("EventTriggered");
    Output:
    [SWF] Untitled-1.swf - 40457 bytes after decompression
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    addEventListener
    dispatchEvent
    [UnloadSWF] Untitled-1.swf
    Test Movie terminated.

  • How to transfer a string from sub sequence to main sequence

    Hi,
    How to transfer a string from sub sequence to main sequence, My main sequence has included a sub sequence, the sub sequence is return a string value after running done, I need to get this string value from sub sequence to main sequence, I check the defined that look like seem the two
    sequence have themself local variable,but I don't know how to defined a globe variable to cover main sequence and sub sequence like VC++'s Main App ,Please kindly help me,thanks in advance...

    Hi,
    I hope this small example will help you.
    Regards
    Ray Farmer
    Regards
    Ray Farmer
    Attachments:
    Sequence File1.seq ‏36 KB

  • Constructing a class extending JDialog when invoked from main application

    In an application that extends JFrame a method, showJDialogGUI, is called to instantiate an object of another class (called enterGUI) that extends JDialog. This object, enterGUIDialog, is modal; user must click on its Submit button in order to dismiss it and be able to continue in MainProgram. I have troubles getting error messages resolved when the constructor of the enterGUIDialog JDialog object is called. Perhaps there are other things wrong with below code. Any help appreciated - snippet of code from both classes is below.
    public class MainProgram extends JFrame {
    enterGUI enterGUIDialog; // declaration for object of class extending JDialog
    public MainProgram() {     // constructor
    myContainer = getContentPane();
    showJDialogGUI(); // calls method to initialize
    public void showJDialogGUI() {
    enterGUIDialog = new enterGUI (this, true);
    enterGUIDialog.setDefaultCloseOperation (DISPOSE_ON_CLOSE );
    enterGUIDialog.setSize(200,200);
    enterGUIDialog.setVisible( true );
    enterGUIDialog.show();
    } // end of class MainProgram
    public class enterGUI extends JDialog{
    Container myContainer;
    JPanel myPanel;
    //// How to call the constructor to create this JDialog????
    public loginGUI( JRootPane theRoot, boolean theModal ) // passed in 'this', and 'true'
    // or maybe??? public About(Frame parent, boolean modal) {
    this.setRootPane( theRoot ); //???????
    // or maybe ??? super(theRoot, flag);
    //super(theRoot, flag); // calls Dialog class constructor
    this.setModal( theModal ); // ?????
    myContainer = getContentPane();
    myContainer.setLayout( new FlowLayout() );
    thePanel = new JPanel();
    // next add components to JPanel, then add to the JDialog container
    fieldsPanel.add( pageLabel ); etc.
    myContainer.add( fieldsPanel );
    // etc.
    myContainer.setDefaultCloseOperation( DISPOSE_ON_CLOSE );
    myContainer.setVisible(true);
    } // end of constructor
    // more methods etc
    }

    Error received is:
    E:\Ghost>
    MainProgram.java:670: cannot resolve symbol
    symbol : constructor enterGUI (MainProgram,boolean)
    location: class MyPackage.enterGUI
    enterGUIDialog = new enterGUI(this, true);
    'new enterGUI(this, true); ' seems to be at start of
    error
    TIAThe error message could not be any more clear. To wit: the compiler is telling you it cannot find a constructor for class enterGUI that takes as parameters a reference to a javax.swing.JFrame, and a boolean value. Supply the constructor and the error will not be raised.

  • 2 Threads issues. How to return data from a thread located in other class

    I have 2 questions.
    This is the context. From main I start one thread that does a little job then starts another thread and waits for it to end to continue.
    1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
    synchronized methods outside different classes (and the threads belongs to different classes).
    2) From the main thread I start the Second Thread located in another class like this ClassName obj = new ClassName(arg); obj.start(); obj.join()
    Is that correct for waiting for the created thread to finish ?

    1) The last started thread needs to return a string to the Thread started from main. How can I accomplish that, because I read that I cannot use
    synchronized methods outside different classes (and the threads belongs to different classes).Threads do not "belong" to classes. Class code executes in a particular thread. The class instances exist as long as something, somewhere, holds a strong reference to them.
    So when you start a new thread, hold a strong reference to the object being executed by that thread. When the thread is done, retrieve your data from that object.
    Even better, don't subclass Thread to create your objects. Instead, implement Callable, and use a ThreadPoolExecutor to execute it.

Maybe you are looking for