Reusing a variable from a new object instance

I'm developing a stock list array for an assignment I'm currently working on. I've got most of it done, and it seems to be working for the most part, but I'm having trouble getting an array to accept individual variable entries created by new object instances in TestQ3.java.
I think problem is because the variable itemCode in CraftItem.java is being overwritten by the creation of a new object instance in the TestQ3.java file. I've tested it and believe this to be true.
I can add a String of my own choosing by using testArray.addCraftItemToStock(itemCode); line but I want to get the program to reuse the itemCode values that have already been created by the four new object instances in TestQ3.java. For example, I want to be able to add more instances of them to the testArray.
As I'm still relatively new to Java programming, I'm wondering how to do this. I've tried several solutions but I'm not getting anywhere. I'd appreciate it if anyone has any ideas?
Here's my code:
TestQ3.java
public class TestQ3 {
  public static void main(String args[]) {
    // creating a new StockItem array
    CraftStock testArray = new CraftStock(CraftStock.initialStockCapacity);
    // creating new object instance for Glue
    Glue gluePVA = new Glue("PVA Glue",250,"789012",2.50);
    // adds gluePVA item code to the testArray list
    // testArray.addCraftItemToStock(gluePVA.getItemCode());
    // creating new object instance for Card
    Card colouredCard = new Card ("Coloured Card","A3","654321",1.25);
    // adds coloured card item code to the testArray list
    // testArray.addCraftItemToStock(colouredCard.getItemCode());
    // creating new object instance for Glue
    Glue superGlue = new Glue ("Super Glue",25,"210987",1.50);
    // adds superGlue item code to the testArray list
    // testArray.addCraftItemToStock(superGlue.getItemCode());
    // creating new object instance for Card
    Card whiteCard = new Card ("White Card","A4","123456",0.50);
    // adds superGlue item code to the testArray list
    // testArray.addCraftItemToStock(whiteCard.getItemCode());
    // display complete stocklist
    testArray.displayCraftStockList();
    // this adds the itemCode from gluePVA to the array but
    // it comes out as the last itemCode entry 123456 rather than 789012
    // when I run the code. The problem may lie with variable itemCode
    testArray.addCraftItemToStock(gluePVA.getItemCode());
    // display complete stocklist
    testArray.displayCraftStockList();
CraftItem.java
public class CraftItem {
  // instance variables
  public static String itemCode;
  private double price;
  //private int stockCount;
  // constructor
  public CraftItem(String itemCodeValue, double itemPriceValue){
    itemCode = itemCodeValue;
    price = itemPriceValue;
    //CraftStock.addCraftItemToStock(itemCode);
    //stockCount++;
  // getter for itemCode
  public String getItemCode() {
    return itemCode;
  // getter for price
  public double getPrice() {
    return price;
  // setter for itemCode
  public void setItemCode(String itemCodeValue) {
    itemCode = itemCodeValue;
  // setter for price
  public void setPrice(double itemPriceValue) {
    price = itemPriceValue;
  // toString() value
  public String toString() {
    return "Item code is " + itemCode + " and costs " + price + " pounds.";
Glue.java
public class Glue extends CraftItem{
  // Instance variables
  private String glueType;
  private double glueVolume;
  // Constructor
  public Glue(String glueType, double glueVolume,
   String itemCodeValue, double itemPriceValue) {
        super(itemCodeValue, itemPriceValue);
        glueType = glueType;
        glueVolume = glueVolume;
  // getter
  public String getGlueType() {
    return glueType;
  // getter
  public double getGlueVolume() {
    return glueVolume;
  // setter
  public void setGlueType(String glueTypeValue) {
    glueType = glueTypeValue;
  public void setGlueVolume(double glueVolumeValue) {
    glueVolume = glueVolumeValue;
  // toString
  public String toString() {
    return glueType + ", " + glueVolume + "ml, item code is "
     + super.getItemCode() + " and costs " + super.getPrice() + " pounds.";
Card.java
public class Card extends CraftItem{
  // instance variables
  private String cardType;
  private String cardSize;
  // Constructor
  // added super(itemCodeValue, itemPriceValue) to call on CraftItem
  public Card(String cardTypeValue, String cardSizeValue,
   String itemCodeValue, double itemPriceValue) {
        super(itemCodeValue, itemPriceValue);
        cardType = cardTypeValue;
        cardSize = cardSizeValue;
  // getter
  public String getCardType() {
    return cardType;
  // getter
  public String getCardSize() {
    return cardSize;
  // setter
  public void setCardType(String cardTypeValue) {
    cardType = cardTypeValue;
  // setter
  public void setCardSize(String cardSizeValue) {
    cardSize = cardSizeValue;
  // toString
  // using super. to call on methods from superclass CraftItem
  public String toString() {
    return cardType + ", size " + cardSize + ", item code is "
     + super.getItemCode() + " and costs " + super.getPrice() + " pounds.";
CraftStock.java
public class CraftStock {
    public static int currentStockLevel;
    public static String[] craftStock;
    public static int initialStockCapacity = 10;
    public CraftStock(int initialStockCapacity) {
        currentStockLevel = 0;
        craftStock = new String[initialStockCapacity];
    public int currentStockLevel() {
        return currentStockLevel;
    public static void addCraftItemToStock(String itemCodeValue) {
        if(currentStockLevel == 10){
          System.out.println("Stock list full: cannot add new item code." +
            "\nPlease remove an item if you want to add a new one.");
        else{
        craftStock[currentStockLevel] = itemCodeValue;
        currentStockLevel++;
        System.out.println("Item added");
    public void removeCraftItemFromStock(String itemCode){
      findStockItem(itemCode);
      int i = -1;
        do {
            i++;
        } while (!craftStock.equals(itemCode));
for (int j = i; j < currentStockLevel - 1; j++) {
craftStock[j] = craftStock[j + 1];
currentStockLevel--;
System.out.println("Item removed");
private int findStockItem(String itemCode){
int index = 0;
for(int i = 0; i < currentStockLevel; i++){
if(craftStock[i].equals(itemCode)){
index = i;
break;
else{
index = -1;
return index;
public void displayCraftStockList() {
if(currentStockLevel == 0){
System.out.println("There are no items in the stock list");
else{
for(int i = 0; i < currentStockLevel; i++){
System.out.println("Item at " + (i + 1) + " is " + craftStock[i]);
Message was edited by:
Nikarius

An instance variable relates to an object. If you require a variable to be available across multiple objects of the same class then I suggest you declare a class variable using the static keyword in your declaration.
HTH

Similar Messages

  • New Object instance

    I have a method call dumpEnvelope,
    if everytime i call the dumpPart , i will call the dumpEnvelope,....
    if i call dumpEnvelope , i want to create a new object of inMailBean
    how do i do that....
    previously, what i do is like this...
    InMailBean inMailBean=new InMailBean();
    only create 1 instance of object...
    i want everytime i call dumpEnvelope((Message)p,out,New OBJECT ->inMailBean(),invalidMailAck)
    dumpPart(){
    dumpEnvelope((Message)p, out, inMailBean,invalidMailAck);
    dumpEnvelope(Message m, PrintWriter out, InMailBean inMailBean,InvalidMailAck invalidMailAck){

    hi,
    so create new instance of InMailBean in dumpEnvelop() and return if from that,
    cerate new instance with
    InMailBean newObj = new InMailBean(); ///just like how you did earlier
    return newObj;
    so return type of dumpEnvelop() , dumpPart() will be InMailBean, since dumpEnvelop() return this type object to dumpPart() and which in turn return that new obj to calling place. e.g,
    InMailBean dumpPart(){}
    same for dumpEnvelop()
    is that what you were looking for
    let me know if it was smthing else
    regards

  • Updating a variable from a new window

    I have a frame which displays various labels and lists. I want to open a new frame, put in some input, then update the original frame. So far I have done this my making the original variable "static" and modifying it from the new frame but this is a pain. Is there an easier way?

    Can I do that if I am instantiating the second frame
    from the first? How do I pass myself to the new
    frame's constructor?
    // called from inside FirstFrame
    SecondFrame secondFrame = new SecondFrame(this);

  • WebUtil doesn't work when called from WHEN-NEW-FORM-INSTANCE trigger

    I need WEBUTIL_CLIENTINFO functions to know some information from the client, like IP, JavaVersion, Hostname, OS user, etc. This functions I call through WHEN-NEW-FORM-INSTANCE TRIGGER and this doesn't nor work. I obtain the next message and error:
    oracle/forms/webutil/clientinfo/GetClientInfo.class not found. WEBUTIL_CLIENTINFO.GET_IP_ADDRESS.
    But when I call this WebUtil functions through WHEN-WINDOW-ACTIVATED trigger or through a button it works. Why?. I need call WebUtils in the WHEN-NEW-FORM-INSTANCE trigger!
    Any help will be of great value.

    Basically make a timer...
    Do you have the wu_test_106.fmb file that comes with the webutil install?
    If you look in the wnfi trigger you will see this...
    declare
         fake_timer TIMER;
    begin
         -- Purpose of the fake timer is the we cannot call webutil in this trigger since the
         -- beans have not yet been instantiated.  If we put the code in a when-timer-expired-trigger
         -- it means that this timer will not start running until Forms has focus (and so the webutil
         -- beans will be instantiated and so call canbe made.
         fake_timer:= CREATE_TIMER('webutil',100,NO_REPEAT);
         --create_blob_table;
         null;
    end;And in the form level when-timer-expired you will see this...
         :global.user_home := webutil_clientinfo.get_system_property('user.home');
         :OLE.FILENAME := :global.user_home||'\temp.doc';
         SET_ITEM_PROPERTY('builtins.text_io_item',PROMPT_TEXT,'Write to '||:global.user_home||'\helloworld.txt');
         SET_ITEM_PROPERTY('files.userdothome',PROMPT_TEXT,:global.user_home);

  • A way to create new object instances in a loop?

    I have an square matrix of String values.
    Is there a way to take each row, make it into an object, and put the object in a new square matrix of objects?
    Any ideas?

    Do you mean something like this:Integer[][] foo = new Integer[5][5];
    for (int i = 0; i < foo.length; i++) {
        for (int j = 0; j < foo.length; j++) {
    foo[i][j] = new Integer(i + j);
    }It's hard to guess what you want, why not post some code (use the code tags: Formatting tips)

  • Use String Variable in New Object Creation

    Thanks to those who review and respond. I am new to Java, so please be patient with my terminoloy mistakes and fumblings. I am reading in a file and I want to create a new object based on specific field (car for example). As you will notice I grab field 8 here label sIID.
    String sIID = dts.group(8);
    BTW this regex grouping works fine. The problem is seen when I try to use the sIID variable in my new object creation process.
    DateParse sIID = new DateParse();
    My IDE is reporting "Variable sIID is already defined in the scope"
    Is this possible? The assumption is that the sIID will have different value during the processing of the file. For example, car could mean truck, sedan, etc with operators like color, number of doors, mileage, top speed, etc.

    Thanks for the reply. I have include similar and much shorter code for the sake of brevity.
    My problems are centered around the x variable/object below. Ideally this would translate to three objects PersonA, PersonB, etc that I could reference later in the code as PersonA.newname if I wanted to. Hopefully this makes sense.
    public class TestingObjects {
      public static void main(String[] argv) {
           String [] names;
           names = new String[3];
           names[0] = "PersonA";
           names[1] = "PersonB";
           names[2] = "PersonC";
           for (String x:names) {
             PN x = new PN();  // <- Problem
             x.name = x;
             x.SayName();
            System.out.println(x.newname);
    public class PN {
           String name;
           String newname;
      public String SayName() {
           newname = "Name = " + name;
           System.out.println(name);
          return newname;
    }

  • Creating dynamic object instance names

    If I have a class such as ...
    class NewDevice
    I would create a new instance of that object by calling 'NewDevice' as ....
    NewDevice nd = new NewDevice();
    Suppose I don't actually know how many device I need before I read a file in and then subsequently create a new object instance. I could have a long list of variable name i.e. nd1, nd2, nd3 etc but that would be messy and I would be sure to run out.
    My Question..........
    How do I create object instances with unique names 'on-the-fly' so to speak
    Thanks

    Here's an example that allows you to build up a list of NewDevice instances, see how many there are and get them back by their index in the list:
    public class MyClass
      List newDeviceList;
      public MyClass()
        newDeviceList = new ArrayList();
      public void addNewDevice(NewDevice newDevice)
        newDeviceList.add(newDevice);
      public int getNewDeviceCount()
        return newDeviceList.size();
      public NewDevice getNewDevice(int idx)
        return (NewDevice)newDeviceList.get(idx);
    }Hope this helps.

  • How to invoke BPM object instance variable from interactive activity?

    I have a screenflow with an automatic activity "A" followed by an interactive activity "B". "B" calls a BPM object "X" and uses a JSP presentation to show its attributes. Is there a way to use another BPM object, say type "Y", create an instance variable of that type inside "A", and get its attributes values from the JSP page associated to "B"?
    Edited by: user6473912 on 20/07/2010 03:37 PM

    Try this. It assumes you have:
    <li> a user named "auto"
    <li> a project variable named "customerType"
    <li> an instance variable named "orderAmount" that is a decimal
    <li> an instance variable named "order" that is a BPM Object that has attributes named "customerName" and "amount"
    ps as ProcessService
    xmlObject as Fuego.Xml.XMLObject
    do 
      connectTo ps
          using url = Fuego.Server.directoryURL,
          user = "auto",
          password = "auto"
      instF as InstanceFilter
      create(instF, processService : ps)
      addAttributeTo(instF, variable : "customerType", comparator : IS, value : "Gold")
      instF.searchScope = SearchScope(participantScope : ParticipantScope.ALL, statusScope : StatusScope.ONLY_INPROCESS)
      for each inst in getInstancesByFilter(ps, filter : instF) do
        // here's how to get the value inside a primitive instance variable
        orderAmtObj as Object = getVar(inst, var : "orderAmount")
        // here's how to get the value of attributes inside a complex BPM Object instance variable
        //    - in this case this is an "order" object with two attributes (customerName and amount)
        orderObj as Object = (getVar(inst, var : "order"))
        xmlObject = Fuego.Xml.XMLObject(createXmlTextFor(DynamicXml, object : orderObj, topLevelTag : "xsi"))
        logMessage "The value of the order object's customer name is: " +
               selectString(xmlObject, xpath : "customerName")
        logMessage "The value of the order object's order amount is: " +
               selectNumber(xmlObject, xpath : "amount")
        // here's a rather uninspired way to retrieve who the participant is that was assigned the instance
        logMessage "The participant assigned to this instance is: " + inst.participantId
      end
    on exit
      disconnectFrom ps
    endDan

  • Setting the name of a new object from a string

    Is there anyway I can set the object name of a newly created
    object from a string?
    eg.
    (the code below generates a compile time error on the
    variable declaration)
    public function addText(newTxt:String, txt:String,
    format:TextFormat):void {
    var
    this[newTxt]:TextField = new TextField();
    this[newTxt].autoSize = TextFieldAutoSize.LEFT;
    this[newTxt].background = true;
    this[newTxt].border = true;
    this[newTxt].defaultTextFormat = format;
    this[newTxt].text = txt;
    addChild(this[newTxt]);
    called using>
    addText("mytxt", "test text", format);
    I could then reference the object later on without using
    array notation using mytxt.border = false; for example
    There are many a time when I want to set the name of a new
    object from a string.
    In this example I have a function that adds a new text object
    to a sprite.
    The problem is, if I call the function more than once then
    two textfield objects will exist, both with the same name. (either
    that or the old one will be overwritten).
    I need a way of setting the name of the textfield object from
    a string.
    using
    var this[newTxt]:TextField = new TextField()
    does not work, If I take the "var" keyword away it thinks it
    a property of the class not an object.
    resulting in >
    ReferenceError: Error #1056: Cannot create property newTxt on
    Box.
    There must be a way somehow to declare a variable that has
    the name that it will take represented in a string.
    Any help would be most welcome
    Thanks

    Using:
    var this[newTxt]:TextField = new TextField()
    is the right approach.
    You can either incrment an instance variable so that the name
    is unique:
    newTxt = "MyName" + _globalCounter;
    var this[newTxt]:TextField = new TextField();
    globalCounter ++;
    Or store the references in an array:
    _globalArray.push(new TextField());
    Tracy

  • How can you get  the public variables from object that extends JLabel?

    I'm using the mouseClickedListener method e.getComponent(); to get the component that is clicked on the sceen. The component i clicked is type "object" and extends a jlabel, and i really need to acces a variable from it. Heres the code i'm using-
    MouseListener listenerDown=new java.awt.event.MouseListener() {
            public void mousePressed(MouseEvent e){
                paintAll();
                mX=e.getX();
                mY=e.getY();
            public void mouseClicked(MouseEvent e) {
                Component c = e.getComponent();
                drawResizeBox(c);
                selected=c;
            public void mouseReleased(MouseEvent e) {
            public void mouseEntered(MouseEvent e) {
            public void mouseExited(MouseEvent e) {
    package javapoint;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.Image;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.geom.Line2D;
    import java.awt.image.BufferedImage;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    public class object extends JLabel{
        public object(Rectangle rect,int id){
            idNum=id;
            Rect=rect;
            BufferedImage image = new BufferedImage((int)rect.getWidth()+1, (int)rect.getHeight()+1, BufferedImage.TYPE_INT_ARGB);
            Graphics2D g = (Graphics2D) image.getGraphics();       
            g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            g.drawRect((int)rect.getX(), (int)rect.getY(), (int)rect.getWidth(), (int)rect.getHeight());
            Icon icon = new ImageIcon((Image)image);
            setIcon(icon);
            setBounds((int)rect.getX()-1, (int)rect.getY()-1, (int)rect.getWidth()+1, (int)rect.getHeight()+1);
            mainFrame.slideArr[mainFrame.sIndx].add(this);
            setVisible(true);
            r=true;       
        object(Oval oval,int id){
            idNum=id;       
            setBounds(oval.getX(), oval.getY(), oval.getWidth(), oval.getHeight());
            getGraphics().drawOval(oval.getX(), oval.getY(), oval.getWidth(), oval.getHeight());
            o=true;
            setVisible(true);
        object(Line2D line,int id){
            idNum=id;       
            setBounds((int)line.getX1(), (int)line.getY1(), (int)line.getX2(), (int)line.getY2()); //Not gunna work
            getGraphics().drawLine((int)line.getX1(), (int)line.getY1(), (int)line.getX2(), (int)line.getY2());
            l=true;
            setVisible(true);
        object(Icon icon,int id){
            idNum=id;
            setIcon(icon);
            setBounds(50,50,icon.getIconWidth(),icon.getIconHeight());
            i=true;
            setVisible(true);
        void drawObject(object obj){
            if(r){
                Rectangle rect=obj.Rect;
                setBounds((int)rect.getX()-1, (int)rect.getY()-1, (int)rect.getWidth()+1, (int)rect.getHeight()+1);          
                Rect=rect;
                BufferedImage image = new BufferedImage((int)rect.getWidth()+1, (int)rect.getHeight()+1, BufferedImage.TYPE_INT_ARGB);
                Graphics2D g = (Graphics2D) image.getGraphics();           
                g.setColor(Color.red);
                g.drawRect(0, 0, (int)rect.getWidth(), (int)rect.getHeight());           
                Icon icon = new ImageIcon((Image)image);
                setIcon(icon);
            }else if(l){
            }else if(o){
            }else if(i){
        public boolean r=false;
        public Rectangle Rect;
        public boolean o=false;
        public Oval Oval;
        public boolean l=false;
        public Line2D Line;
        public boolean i=false;
        public Icon Icon;
        public JLabel label;
        public int idNum;
    }Edited by: ghostbust555 on Feb 12, 2010 2:14 PM

    ghostbust555 wrote:
    Well see the problem is i have an array of 200 objects.What does that have to do with anything? And if it does, why isn't it in the code you posted?
    I dont understand what you mean in your "Edit..." part. could you show some code/ explain farther? sorry if its a dumb question I'm still a bit of a novice at java.Yeah.
    object yuck = (object) e.getComponent(); // That's a cast.
    boolean yucksR = yuck.r; // Get the "r" variable from the object.

  • Dynamic Variables and New-Object - in a GUI

    so, i have not found anything that i can parlay into a solution for what i am attempting to do.  
    Basically i am using powershell to build a GUI to manage websites on various servers.  
    in a nutshell:
    - i have an array with the servers i want to query
    - a foreach loop gets me the site names for each server (number of sites can vary on a server).
    - need put checkboxes on a GUI for every site to do something (25-30 sites across 8 servers).
    currently i am passing the $dir.name variable to a function that will create the new variable using this command:
    $pName = $dir.name New-variable -name $pName -value (New-Object System.Windows.Forms.CheckBox)
    $pName.Location -value (New-Object System.Drawing.Size(10,$i))
    $pName.Size -value (New-Object System.Drawing.Size(100,20))
    $Pname.Text -value $dir.name
    $groupBox.Controls.Add($pName) 
    Problem is i am not able to do anything with my newly created variable.  I am trying to use the following code to position the new checkbox but i get nothing (same for text, size, etc.)  I am not seeing any errors, so i don't know what i have going
    wrong.  
    is this even possible?
    I am able to create static checkboxes, and i can create dynamic variables.  But i can't mix the two...

    Here is how we normally use listboxes to handle form situations like this one.  The listboxes can automatically select subgroups.
    The hash of arrays can be loaded very easily with a script or the results of the first list can be used to lookup and set the contents of the second.
    Notice how little code is actually used.  This is all of the setup code needed aside from the from definition:
    $FormEvent_Load={
    $global:serversToSites=@{
    Server1=@('S1_SITE1','S1_SITE2','S1_SITE3')
    Server2=@('S2_SITE1','S2_SITE2','S2_SITE3')
    Server3=@('S3_SITE1','S3_SITE2','S3_SITE3')
    $listbox1.Items.AddRange($serversToSites.Keys)
    $listbox1_SelectedIndexChanged={
    $listbox2.Items.Clear()
    $listbox2.Items.AddRange($global:serversToSites[$listbox1.SelectedItem])
    $listbox2_SelectedIndexChanged={
    [void][System.Windows.Forms.MessageBox]::Show($listbox2.SelectedItem,'You Selected Site')
    Here is the complete demo form:
    [void][reflection.assembly]::Load("System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089")
    [void][reflection.assembly]::Load("System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a")
    [System.Windows.Forms.Application]::EnableVisualStyles()
    $form1 = New-Object 'System.Windows.Forms.Form'
    $listbox2 = New-Object 'System.Windows.Forms.ListBox'
    $listbox1 = New-Object 'System.Windows.Forms.ListBox'
    $buttonOK = New-Object 'System.Windows.Forms.Button'
    $InitialFormWindowState = New-Object 'System.Windows.Forms.FormWindowState'
    $FormEvent_Load={
    $global:serversToSites=@{
    Server1=@('S1_SITE1','S1_SITE2','S1_SITE3')
    Server2=@('S2_SITE1','S2_SITE2','S2_SITE3')
    Server3=@('S3_SITE1','S3_SITE2','S3_SITE3')
    $listbox1.Items.AddRange($serversToSites.Keys)
    $listbox1_SelectedIndexChanged={
    $listbox2.Items.Clear()
    $listbox2.Items.AddRange($global:serversToSites[$listbox1.SelectedItem])
    $listbox2_SelectedIndexChanged={
    [void][System.Windows.Forms.MessageBox]::Show($listbox2.SelectedItem,'You Selected Site')
    $Form_StateCorrection_Load=
    #Correct the initial state of the form to prevent the .Net maximized form issue
    $form1.WindowState = $InitialFormWindowState
    $form1.Controls.Add($listbox2)
    $form1.Controls.Add($listbox1)
    $form1.Controls.Add($buttonOK)
    $form1.AcceptButton = $buttonOK
    $form1.ClientSize = '439, 262'
    $form1.FormBorderStyle = 'FixedDialog'
    $form1.MaximizeBox = $False
    $form1.MinimizeBox = $False
    $form1.Name = "form1"
    $form1.StartPosition = 'CenterScreen'
    $form1.Text = "Form"
    $form1.add_Load($FormEvent_Load)
    # listbox2
    $listbox2.FormattingEnabled = $True
    $listbox2.Location = '237, 26'
    $listbox2.Name = "listbox2"
    $listbox2.Size = '120, 134'
    $listbox2.TabIndex = 2
    $listbox2.add_SelectedIndexChanged($listbox2_SelectedIndexChanged)
    # listbox1
    $listbox1.FormattingEnabled = $True
    $listbox1.Location = '13, 26'
    $listbox1.Name = "listbox1"
    $listbox1.Size = '120, 134'
    $listbox1.TabIndex = 1
    $listbox1.Sorted = $true
    $listbox1.add_SelectedIndexChanged($listbox1_SelectedIndexChanged)
    # buttonOK
    $buttonOK.Anchor = 'Bottom, Right'
    $buttonOK.DialogResult = 'OK'
    $buttonOK.Location = '352, 227'
    $buttonOK.Name = "buttonOK"
    $buttonOK.Size = '75, 23'
    $buttonOK.TabIndex = 0
    $buttonOK.Text = "OK"
    $buttonOK.UseVisualStyleBackColor = $True
    #Save the initial state of the form
    $InitialFormWindowState = $form1.WindowState
    #Init the OnLoad event to correct the initial state of the form
    $form1.add_Load($Form_StateCorrection_Load)
    #Clean up the control events
    $form1.add_FormClosed($Form_Cleanup_FormClosed)
    #Show the Form
    $form1.ShowDialog()
    You can easily substitute  CheckedListbox if you like checkboxes.
    ¯\_(ツ)_/¯

  • Accessing instance variables from container

    I am new to Flash. I am a programmer, not a designer so this
    is my first foray into Actionscript.
    I am creating a slide show player in Flash. It retrieves an
    XML file containing other .swf files that should be played, the
    order in which they should be played, the length of time each one
    should show, and the text that should be displayed.
    For example:
    <presentation>
    <globals>
    <setting name="use_transitions" value="false"/>
    <setting name="use_delays" value="false"/>
    </globals>
    <slide src="slide5.swf" text="Slide 1" delay="10"/>
    <slide src="slide3.swf" text="Slide 2" delay="10"/>
    </presentation>
    I have everything working except for the loaded .swf file
    picking up on the text to display.
    I can set the Var: property on the dynamic text field to
    _root.dynamic_text and it will load what is in the variable
    dynamic_text just fine.
    However, the slide3.swf and slide5.swf file have default text
    in them that should who if there is no text specified.
    It seems that variables inside a loaded movie are not in
    scope.
    I load the movie using:
    loadMovie(slides[nIndex][0], "slideMovie");
    However if my instance name on my dynamic text field is
    "theText" this code does not work:
    this.slideMovie.theText.text = dynamic_text;
    How do I dereference the dynamic text field?
    Thanks for any help.

    quote:
    Originally posted by:
    abeall
    I didn't really follow your set up.
    > this.slideMovie.theText.text = dynamic_text;
    Where is that code placed? Where is theText? Where is
    dynamic_text defined, or what is it? _txt usually signifies a
    TextField instance, but if that was the case then the statement
    would not do anything. Are you trying to access objects in the
    external slide SWF before it has been loaded and initialized?
    I'm sorry that I wasn't clear enough.
    Maybe this will help.
    ============== Begin Code ==============
    slide3.swf
    ========
    _root
    layer |------> Instance of Graphic Symbol
    -----------------------> Dynamic Text Object named
    'theText'
    layer |------> Instance of Graphic Symbol
    -----------------------> JPEG Graphic Background
    layer |------> Actionscript Layer
    slide_show engine.swf
    ==================
    _root
    layer |------> Movie Clip Object named 'slideMovie'
    layer |------> Actionscript Layer
    Actionscript code snippet:
    /* This becomes a two dimentional array of slides.
    * slides[index][0] is the .swf file to load.
    * slides[index][1] is the transistion to load. (Not
    currently used.)
    * slides[index][2] is the delay to wait (in seconds) until
    the next slide shows.
    * slides[index][3] is the customized text to show the loaded
    slide. If blank show the default text.
    var slides = new Array();
    var dynamic_text;
    var nIndex = 0;
    var main:Object = new Object();
    main.switch_slides = function()
    if (nInterval != -1)
    clearInterval(nInterval);
    if (nIndex >= slides.length)
    return;
    _root.dynamic_text = slides[nIndex][3];
    loadMovie(slides[nIndex][0], "slideMovie");
    this.slideMovie.theText.text = _root.dynamic_text;
    nInterval = setInterval(main, "switch_slides",
    (slides[nIndex++][2] * 1000));
    // Code to load and parse the configuration file deleted for
    brevity.
    ============== End Code ==============
    The slides are made by our designer. Most of which animate
    the background image and then fade in the text.
    The text object usually does not exist in the first key
    frame. So my workaround is probably the only way this can be done.
    The workaround needs to go in every slide's actionscript
    layer on the first key frame.
    The only real problem I have with it is that I need to put
    the default text in the actionscript. Putting a Var reference in
    the dynamic text will remove the text there if the variable is
    empty.
    However trying to dynamically create the var reference does
    not seem to work. For example:
    In the slide3.swf file if I have the following code on the
    actionscript layer, the var reference in the dynamic text does not
    get pulled in properly:
    if (_root.dynamic_text)
    this.dynamic_text = _root.dynamic_text;
    I need to put the var reference at the top with the default
    text. For example:
    var dynamic_text = "default text";
    if (_root.dynamic_text)
    this.dynamic_text = _root.dynamic_text;

  • How new objects are instantiated when reading from object stream?

    Hi,
    How the serializable API instantiates new objects when reading from stream?
    First it needs to create a new instance of a class and then fill its' fields with a serialized data. But not all serializable classes have empty constructor (as it have java beans) to make simple call of Class.newInstance(). Is there any way to create a virgin instance of any class?
    Ant�n

    I found the way, but it is not a solution:
    Constructor serializableConstructor = sun.reflect.ReflectionFactory.getReflectionFactory().newConstructorForSerialization( Class instanceClass, Constructor superClassEmptyConstructor );
    Object obj = serializableConstructor.newInstance();This "magic" method creates an empty constructor for a serializable class from empty constructor of any superclass. The limitation is that a first non-serializable superclass must have an empty constructor.
    As this magic method locates in a package sun.** I think this will not work with other JREs.

  • Refering to object instances from a jsp

    How can i call object instances within class instances in my application -- from a jsp?
    In other words, i want to reference to an pre-existing application instance of a class.
    I do not want "use:bean" -- which will use a class (not the specific instance i am looking for in the application).
    I also do not want a binding to a variable only ( #{class.variable} ).
    Thank You!
    eric

    That's a good reminder of how to positively access class2, stevejluke. Thanks.
    However, i have found by trying to access a simple String in Class1 that the class1 instantiated by the jsf page (this comes up first in the application and has components which require Class1) is not the same instantiation that being accessed by the jsp page (which is navigated to by a button from the jsf page).
    I put:
    <jsp:useBean id="myBean" class="com.mycompany.expense.EntryHandler" scope="session"/>
    at the top of both the jsf and the jsp page.
    faces-config.xml has:
    <managed-bean>
    <description>
    Glue bean for entry related events and the current entry data
    </description>
    <managed-bean-name>entryHandler</managed-bean-name>
    <managed-bean-class>
    com.mycompany.expense.EntryHandler
    </managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    <managed-property> ((about 4)) <managed-property>
    <managed-bean>
    I tried setting <managed-bean-name> equal to the id in the jsp:useBean tag but drew the an error indicating the the <jsp:useBean ...> tag had instantiated the class before the faces-config.xml file had -- hence the managed property could not be found.
    I also tried putting name="entryHandler" in the <jsp:useBean > tag, but this is not allowed.
    Hmm, how to get the <managed-bean> and <jsp:useBean> to match?
    Maybe i have to put in code to the effect "get context " "get instantiation" etc,
    I'll have to try looking it up . . .

  • Clearing variable from Request object

    Hi everyone,
    After getting value from request.getParameter("var"), I want to clear this "var" variable from request scope. So that in the next coming statements if i again call the same request.getParameter("var") statement than it must return null
    So how to handle this issue of clearing certain variable from request scope or flushing the whole request object

    I don't know what you are trying to do but it sounds confused. I would suggest you read the parameter once, at the beginning of the code. Store it in a variable and use that variable as necessary. If you still need help then would you explain what you are trying to achieve here.

Maybe you are looking for

  • Is there a way to identify manual log switches?

    Hi! A while ago I upgraded a 10g database to 11.2.0.2 64 Bit Windows. During the Upgrade we realized that redo logs were configured really small (~10MB) what resulted in a lot of log switches (a few hundred per day). So we adjusted redo log size to 1

  • AD SSO with entry point for SAP users....

    A client would like to use Active Directory (AD) Single Sign On rather than SAP for authentication purposes.  There are two potential scenarios we would need to support: Scenario 1, access to SAP BW (General Ledger, Profit Centre Accounting) and rela

  • PO item condition amount change in ME28

    Hi, The question is whether ME28 will update the PO item condition amount automatically when release PO ? If so, how ME28 determine the PO item condition amount to change. Please teach me if you have any idea. Thanks a lot ! Regards,

  • My phone says connect to iTunes when it dies, my phone was never jail broken either

    When my phone dies, I plug it in and the apple comes up than it goes to the USB and iTunes logo. I connect it to iTunes hold in power and home and all and it eventually turns on I did it 3 times so far, now this time I can't get it to go back on

  • Lightroom 2 and Capture NX 2

    Is there any chance that Lightroom 2 might be able to read the proprietary changes that Capture NX2 writes into the Nikon NEF files? These two programs greatly substitute each other.