accessing textfield elements in a array


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: accessing textfield elements in a array

  1. #1
    dominic Guest

    accessing textfield elements in a array


    hello

    i have to write an applet whitch has 31 textfield elements. i tried to put
    these elements in an array. when i compile the project, it works without
    an error. when i start the applet, nothing works!! the internet explorer
    doesn`t show me any errors. the applet is just empty!! until now i only access
    the first element of the array --> tDatum[0].setBounds(5,25,60,20);

    heres the code:


    //class erfassenGui

    import java.awt.*;

    public class erfassenGui extends Panel
    {
    public Label lDatum;
    public Label lProjekt;
    public Label lArbeit;
    public Label lVon1;
    public Label lBis1;
    public Label lVon2;
    public Label lBis2;

    public TextField[] tDatum;
    public TextField[] tProjekt;
    public TextField[] tArbeit;
    public TextField[] tVon1;
    public TextField[] tBis1;
    public TextField[] tVon2;
    public TextField[] tBis2;

    public erfassenGui()
    {
    lDatum = new Label("Datum");
    lProjekt = new Label("Projekt");
    lArbeit = new Label("Tätigkeit");
    lVon1 = new Label("von");
    lBis1 = new Label("bis");
    lVon2 = new Label("von");
    lBis2 = new Label("bis");

    tDatum = new TextField[31];
    tProjekt = new TextField[31];
    tArbeit = new TextField[31];
    tVon1 = new TextField[31];
    tBis1 = new TextField[31];
    tVon2 = new TextField[31];
    tBis2 = new TextField[31];
    }
    }

    //class erfasen

    import java.applet.*;
    import java.awt.*;

    public class erfassen extends Applet
    {
    private Font font;

    public void init()
    {
    try
    {
    font = new Font("Arial",1,15);

    setLayout(null);
    setBackground(Color.white);
    erfassenGui gui = new erfassenGui();

    gui.lDatum.setFont(font);
    gui.lProjekt.setFont(font);
    gui.lArbeit.setFont(font);
    gui.lVon1.setFont(font);
    gui.lBis1.setFont(font);
    gui.lVon2.setFont(font);
    gui.lBis2.setFont(font);

    gui.lDatum.setBounds(5,10,60,15);
    gui.lProjekt.setBounds(70,10,100,15);
    gui.lArbeit.setBounds(175,10,380,15);
    gui.lVon1.setBounds(560,10,50,15);
    gui.lBis1.setBounds(615,10,50,15);
    gui.lVon2.setBounds(670,10,50,15);
    gui.lBis2.setBounds(725,10,50,15);

    gui.tDatum[0].setBounds(5,25,60,20);
    gui.tProjekt[0].setBounds(70,25,100,20);
    gui.tArbeit[0].setBounds(175,25,380,20);
    gui.tVon1[0].setBounds(560,25,50,20);
    gui.tBis1[0].setBounds(615,25,50,20);
    gui.tVon2[0].setBounds(670,25,50,20);
    gui.tBis2[0].setBounds(725,25,50,20);

    add(gui.lDatum);
    add(gui.lProjekt);
    add(gui.lArbeit);
    add(gui.lVon1);
    add(gui.lBis1);
    add(gui.lVon2);
    add(gui.lBis2);

    add(gui.tDatum[0]);
    add(gui.tProjekt[0]);
    add(gui.tArbeit[0]);
    add(gui.tVon1[0]);
    add(gui.tBis1[0]);
    add(gui.tVon2[0]);
    add(gui.tBis2[0]);
    }
    catch (Exception e) {}
    }

    public void paint(Graphics g)
    {
    }
    }

  2. #2
    Ruchi Dhar Guest

    Re: accessing textfield elements in a array


    I haven't seen any constructor for TextField in your following code. Is the
    following code is the total code or something is missing. If it is the total
    code there is no place you are creating TextField object. All the erfassenGui
    class you defined the array of 31 elements but you haven't created the actual
    object. If you would have caught the exception and print the exception then
    you would have definetly noticed the NullPointerException. First create
    the TextField object. Declaring tProjekt = new TextField[31]; doesn't actually
    create objects. you need to loop through the array and create objects for
    textfield

    for(int i=0; i<tProjekt.length; i++)
    tProjekt[i] = new TextField();

    I hope this solves your problem.


    "dominic" <dgerber@wib.ch> wrote:
    >
    >hello
    >
    >i have to write an applet whitch has 31 textfield elements. i tried to put
    >these elements in an array. when i compile the project, it works without
    >an error. when i start the applet, nothing works!! the internet explorer
    >doesn`t show me any errors. the applet is just empty!! until now i only

    access
    >the first element of the array --> tDatum[0].setBounds(5,25,60,20);
    >
    >heres the code:
    >
    >
    >//class erfassenGui
    >
    >import java.awt.*;
    >
    >public class erfassenGui extends Panel
    > {
    > public Label lDatum;
    > public Label lProjekt;
    > public Label lArbeit;
    > public Label lVon1;
    > public Label lBis1;
    > public Label lVon2;
    > public Label lBis2;
    >
    > public TextField[] tDatum;
    > public TextField[] tProjekt;
    > public TextField[] tArbeit;
    > public TextField[] tVon1;
    > public TextField[] tBis1;
    > public TextField[] tVon2;
    > public TextField[] tBis2;
    >
    > public erfassenGui()
    > {
    > lDatum = new Label("Datum");
    > lProjekt = new Label("Projekt");
    > lArbeit = new Label("Tätigkeit");
    > lVon1 = new Label("von");
    > lBis1 = new Label("bis");
    > lVon2 = new Label("von");
    > lBis2 = new Label("bis");
    >
    > tDatum = new TextField[31];
    > tProjekt = new TextField[31];
    > tArbeit = new TextField[31];
    > tVon1 = new TextField[31];
    > tBis1 = new TextField[31];
    > tVon2 = new TextField[31];
    > tBis2 = new TextField[31];
    > }
    > }
    >
    >//class erfasen
    >
    >import java.applet.*;
    >import java.awt.*;
    >
    >public class erfassen extends Applet
    > {
    > private Font font;
    >
    > public void init()
    > {
    > try
    > {
    > font = new Font("Arial",1,15);
    >
    > setLayout(null);
    > setBackground(Color.white);
    > erfassenGui gui = new erfassenGui();
    >
    > gui.lDatum.setFont(font);
    > gui.lProjekt.setFont(font);
    > gui.lArbeit.setFont(font);
    > gui.lVon1.setFont(font);
    > gui.lBis1.setFont(font);
    > gui.lVon2.setFont(font);
    > gui.lBis2.setFont(font);
    >
    > gui.lDatum.setBounds(5,10,60,15);
    > gui.lProjekt.setBounds(70,10,100,15);
    > gui.lArbeit.setBounds(175,10,380,15);
    > gui.lVon1.setBounds(560,10,50,15);
    > gui.lBis1.setBounds(615,10,50,15);
    > gui.lVon2.setBounds(670,10,50,15);
    > gui.lBis2.setBounds(725,10,50,15);
    >
    > gui.tDatum[0].setBounds(5,25,60,20);
    > gui.tProjekt[0].setBounds(70,25,100,20);
    > gui.tArbeit[0].setBounds(175,25,380,20);
    > gui.tVon1[0].setBounds(560,25,50,20);
    > gui.tBis1[0].setBounds(615,25,50,20);
    > gui.tVon2[0].setBounds(670,25,50,20);
    > gui.tBis2[0].setBounds(725,25,50,20);
    >
    > add(gui.lDatum);
    > add(gui.lProjekt);
    > add(gui.lArbeit);
    > add(gui.lVon1);
    > add(gui.lBis1);
    > add(gui.lVon2);
    > add(gui.lBis2);
    >
    > add(gui.tDatum[0]);
    > add(gui.tProjekt[0]);
    > add(gui.tArbeit[0]);
    > add(gui.tVon1[0]);
    > add(gui.tBis1[0]);
    > add(gui.tVon2[0]);
    > add(gui.tBis2[0]);
    > }
    > catch (Exception e) {}
    > }
    >
    > public void paint(Graphics g)
    > {
    > }
    > }



  3. #3
    dominic Guest

    Re: accessing textfield elements in a array


    thanks a lot, i forgot that issue. now it works!!

    "Ruchi Dhar" <rdhar@verticalnet.com> wrote:
    >
    >I haven't seen any constructor for TextField in your following code. Is

    the
    >following code is the total code or something is missing. If it is the

    total
    >code there is no place you are creating TextField object. All the erfassenGui
    >class you defined the array of 31 elements but you haven't created the actual
    >object. If you would have caught the exception and print the exception

    then
    >you would have definetly noticed the NullPointerException. First create
    >the TextField object. Declaring tProjekt = new TextField[31]; doesn't actually
    >create objects. you need to loop through the array and create objects for
    >textfield
    >
    >for(int i=0; i<tProjekt.length; i++)
    > tProjekt[i] = new TextField();
    >
    >I hope this solves your problem.
    >
    >
    >"dominic" <dgerber@wib.ch> wrote:
    >>
    >>hello
    >>
    >>i have to write an applet whitch has 31 textfield elements. i tried to

    put
    >>these elements in an array. when i compile the project, it works without
    >>an error. when i start the applet, nothing works!! the internet explorer
    >>doesn`t show me any errors. the applet is just empty!! until now i only

    >access
    >>the first element of the array --> tDatum[0].setBounds(5,25,60,20);
    >>
    >>heres the code:
    >>
    >>
    >>//class erfassenGui
    >>
    >>import java.awt.*;
    >>
    >>public class erfassenGui extends Panel
    >> {
    >> public Label lDatum;
    >> public Label lProjekt;
    >> public Label lArbeit;
    >> public Label lVon1;
    >> public Label lBis1;
    >> public Label lVon2;
    >> public Label lBis2;
    >>
    >> public TextField[] tDatum;
    >> public TextField[] tProjekt;
    >> public TextField[] tArbeit;
    >> public TextField[] tVon1;
    >> public TextField[] tBis1;
    >> public TextField[] tVon2;
    >> public TextField[] tBis2;
    >>
    >> public erfassenGui()
    >> {
    >> lDatum = new Label("Datum");
    >> lProjekt = new Label("Projekt");
    >> lArbeit = new Label("Tätigkeit");
    >> lVon1 = new Label("von");
    >> lBis1 = new Label("bis");
    >> lVon2 = new Label("von");
    >> lBis2 = new Label("bis");
    >>
    >> tDatum = new TextField[31];
    >> tProjekt = new TextField[31];
    >> tArbeit = new TextField[31];
    >> tVon1 = new TextField[31];
    >> tBis1 = new TextField[31];
    >> tVon2 = new TextField[31];
    >> tBis2 = new TextField[31];
    >> }
    >> }
    >>
    >>//class erfasen
    >>
    >>import java.applet.*;
    >>import java.awt.*;
    >>
    >>public class erfassen extends Applet
    >> {
    >> private Font font;
    >>
    >> public void init()
    >> {
    >> try
    >> {
    >> font = new Font("Arial",1,15);
    >>
    >> setLayout(null);
    >> setBackground(Color.white);
    >> erfassenGui gui = new erfassenGui();
    >>
    >> gui.lDatum.setFont(font);
    >> gui.lProjekt.setFont(font);
    >> gui.lArbeit.setFont(font);
    >> gui.lVon1.setFont(font);
    >> gui.lBis1.setFont(font);
    >> gui.lVon2.setFont(font);
    >> gui.lBis2.setFont(font);
    >>
    >> gui.lDatum.setBounds(5,10,60,15);
    >> gui.lProjekt.setBounds(70,10,100,15);
    >> gui.lArbeit.setBounds(175,10,380,15);
    >> gui.lVon1.setBounds(560,10,50,15);
    >> gui.lBis1.setBounds(615,10,50,15);
    >> gui.lVon2.setBounds(670,10,50,15);
    >> gui.lBis2.setBounds(725,10,50,15);
    >>
    >> gui.tDatum[0].setBounds(5,25,60,20);
    >> gui.tProjekt[0].setBounds(70,25,100,20);
    >> gui.tArbeit[0].setBounds(175,25,380,20);
    >> gui.tVon1[0].setBounds(560,25,50,20);
    >> gui.tBis1[0].setBounds(615,25,50,20);
    >> gui.tVon2[0].setBounds(670,25,50,20);
    >> gui.tBis2[0].setBounds(725,25,50,20);
    >>
    >> add(gui.lDatum);
    >> add(gui.lProjekt);
    >> add(gui.lArbeit);
    >> add(gui.lVon1);
    >> add(gui.lBis1);
    >> add(gui.lVon2);
    >> add(gui.lBis2);
    >>
    >> add(gui.tDatum[0]);
    >> add(gui.tProjekt[0]);
    >> add(gui.tArbeit[0]);
    >> add(gui.tVon1[0]);
    >> add(gui.tBis1[0]);
    >> add(gui.tVon2[0]);
    >> add(gui.tBis2[0]);
    >> }
    >> catch (Exception e) {}
    >> }
    >>
    >> public void paint(Graphics g)
    >> {
    >> }
    >> }

    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center