String Array; need help with methods


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: String Array; need help with methods

  1. #1
    Join Date
    Feb 2003
    Posts
    11

    Question String Array; need help with methods

    Hello,

    This program compiles correctly, but
    i cant seem to get anything to appear on my applet screen except for the textField with the current program down below. Can anyone see a problem, i cant?
    i think im seeing doubles, since ive been looking at
    this program for 30 hours.


    private TextField input;
    private String [] stringArray = new String [10];

    public void init(){
    input = new TextField (20);
    add (input);
    input.addActionListener (this);}

    public void paint(Graphics g){

    getData(stringArray);

    display(stringArray, g);}

    public void actionPerformed (ActionEvent e){

    input.setText(null);
    repaint ();}


    // This section below contains the methods

    public void getData (String [] array)
    {
    for (int z=0; z < array.length; z++){
    array [z] = input.getText();}}

    public void display(String [] array, Graphics g){

    int yValue=100;
    for (int w=0; w < array.length; w++)
    g.drawString("Index "+w+"is "+array[w], 100, yValue*15);}

    }//end of program

    jbowl to the nineth degree

  2. #2
    Join Date
    Mar 2003
    Posts
    84
    i cant seem to get anything to appear on my applet screen except for the textField
    that's all that you add to the GUI.

    i'm not sure what this program is supposed to do, could you explain a little better?
    I'm surprised more of you people don't get hit by cars.

  3. #3
    Join Date
    Feb 2003
    Posts
    11
    no problemo.

    first of all this program uses a Textfield for input on
    10 strings you enter. Than displays them on the screen.
    Sounds easy, but for me its kind of difficult.

    thanks Fantik

    jbowl to the nineth degree

  4. #4
    Join Date
    Mar 2003
    Posts
    84
    ok looking at your code I'm seeing that when paint is called, it calls getdata.. which is where you populate your array... but every time you hit enter in your text field, actionPerformed is called...

    at the end of action performed, paint is called again.. and that calls getData again.. in a loop.

    your array never gets populated.


    you need to call getData from your actionEvent method.. and loop that 10 times in order for your array to be populated.

    do you follow that? or do I need to explain further, let me know where I confused you if so.


    I might be wrong here as well.... my expertise is not in using applets. I'm a low level guy.
    I'm surprised more of you people don't get hit by cars.

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