-
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
-
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.
-
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
-
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
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks