The Artima Developer Community
Sponsored Link

Java Answers Forum
Create storage for the list of phrases - arrays HELP?!

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Rob

Posts: 2
Nickname: robm
Registered: Jul, 2003

Create storage for the list of phrases - arrays HELP?! Posted: Jul 26, 2003 1:09 PM
Reply to this message Reply
Advertisement
I am lost with these instructions(at the bottom) - I have the first part where I have instance variables which hold an array named "display" and initiated ao ALabels for output put I can't get any further. Here's what I have so far:




public class ListOfStrings extends A3ButtonHandler
{

private A3ButtonWindow win;
private ATextField input;
private ALabel entries;
private ALabel answer;
private ALabel[] display; // Declares a variable that can hold an array


/**
* Constructs the handler object, the 3-button
* window and populates the window.
*/
public ListOfStrings()
{


// Create the 3-button window
win = new A3ButtonWindow(this);
win.setLeftText("Save");
win.setMidText("Display");
win.setRightText("Discard");

display = new ALabel[10];
display[0] = new ALabel(200, 100, 200, 20); // Populate first element
display[1] = new ALabel(200, 125, 200, 20);
display[2] = new ALabel(200, 150, 200, 20);
display[3] = new ALabel(200, 175, 200, 20);
display[4] = new ALabel(200, 200, 200, 20);
display[5] = new ALabel(200, 225, 200, 20);
display[6] = new ALabel(200, 250, 200, 20);
display[7] = new ALabel(200, 275, 200, 20);
display[8] = new ALabel(200, 300, 200, 20);
display[9] = new ALabel(200, 325, 200, 20);
display[9] = new ALabel(200, 350, 200, 20); // Populate tenth element


input = new ATextField(125, 400, 150, 25);
input.place(win);

// Refresh the window
win.repaint();
}



Create storage for the list of phrases.
The core of this program maintains a list of string values that are input by the user. In this step, you will create the storage for the list. This consists of two parts: an array that can contain up to 10 String objects and an integer that will show how many objects in the array are in the list.

Declare instance variables for the list, that is, the array of Strings and the count of items in the list. Name them something descriptive, like storage and count.
In the constructor, create the array and initialize the count to zero.
There is no reason to fill the array. Since the count is zero, we know not to access values within the array. There is no visible change based on this step.

Topic: Why is it useful in downcast not upcast? Previous Topic   Next Topic Topic: Experiment

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use