N
NickName
Hi,
The following is a "complete set of sample code" from a java tutorial.
I understand how the code works. But question, where was the instance
of textArea1defined? I understand textArea is a subclass from the AWT
package. Secondly, when a method of an external class can be
called/used directly vs. via instantiation? Read somewhere, don't
recall exactly how.
Many thanks.
// I guess the following line is missing
import java.awt.*;
// original code block starts
Vector vector1 = new Vector();
for (int i = 0; i < 10;i++) {
vector1.addElement(new Integer(i)); //addElement accepts object or
//composite types
} //but not primitive types
//enumerate vector1 using nextElement()
Enumeration e = vector1.elements();
textArea1.setText("The elements using Enumeration's nextElement():\n");
while (e.hasMoreElements()) {
textArea1.append(e.nextElement()+ " | ");
}
textArea1.append("\n\n");
//enumerate using the elementAt() method
textArea1.append("The elements using Vector's elementAt():\n");
for (int i = 0; i < vector1.size();i++) {
textArea1.append(vector1.elementAt(i) + " | ");
}
textArea1.append("\n\n");
//enumerate using the toString() method
textArea1.append("Here's the vector as a String:\n");
textArea1.append(vector1.toString());
// original code block ends
The following is a "complete set of sample code" from a java tutorial.
I understand how the code works. But question, where was the instance
of textArea1defined? I understand textArea is a subclass from the AWT
package. Secondly, when a method of an external class can be
called/used directly vs. via instantiation? Read somewhere, don't
recall exactly how.
Many thanks.
// I guess the following line is missing
import java.awt.*;
// original code block starts
Vector vector1 = new Vector();
for (int i = 0; i < 10;i++) {
vector1.addElement(new Integer(i)); //addElement accepts object or
//composite types
} //but not primitive types
//enumerate vector1 using nextElement()
Enumeration e = vector1.elements();
textArea1.setText("The elements using Enumeration's nextElement():\n");
while (e.hasMoreElements()) {
textArea1.append(e.nextElement()+ " | ");
}
textArea1.append("\n\n");
//enumerate using the elementAt() method
textArea1.append("The elements using Vector's elementAt():\n");
for (int i = 0; i < vector1.size();i++) {
textArea1.append(vector1.elementAt(i) + " | ");
}
textArea1.append("\n\n");
//enumerate using the toString() method
textArea1.append("Here's the vector as a String:\n");
textArea1.append(vector1.toString());
// original code block ends