Archived

This topic is now archived and is closed to further replies.

[java] Dumbass java

This topic is 4989 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

i have a really easy question - i have a Text Area called TextArea01. and i want to add the contents of an array to it when someone clicks a button on a simple GUI. i have all the action listeners in place but i just cant get the information in there, i dont know the code how to do it, please help by giving me some code that might work. [edited by - Arclight on April 21, 2004 10:29:08 AM]

Share this post


Link to post
Share on other sites


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

public class Texts21 extends Applet implements ActionListener
{

TextArea destination;
Button copy;
String a[] = { "0","1","2","3","4","5","6","7" };

public void init()
{

copy = new Button( "Copy ->" );
copy.addActionListener( this );
add( copy );

destination = new TextArea( 10, 30 );
add( destination );

validate();
}

public void actionPerformed( ActionEvent e )
{

String temp;

if( e.getSource() == copy )
{
for( int i = 0; i < a.size; ++i )
{
temp += a[ i ] + " ";
}

if( destination.getText() == "" )
{
destination.setText( temp );
}
else
{
destination.append( temp );
}

}

}
}


[/CODE]

Dunno if this helps.


[edited by - pkelly83 on April 21, 2004 10:37:39 AM]

Share this post


Link to post
Share on other sites
the piece of code i have works correctly, but i will have more than one array being written to the text area, i have got it to write to it, but they are all on the same line,
do you know what the return command is? so i can display each array on a seperate line.

Thanks.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Do us and yourself a favor, and post your code.

It''s not Java''s fault; title should have been "Dumbass programmer" ...

Share this post


Link to post
Share on other sites
JButton01.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent event) {

// Temporary String Variable, to store the arrays.
String temp;

// initalises temp to an empty string.
temp = "";
Razor [ ] razors = museum.getAllRazors();

if(razors.length == 0) {
JTextArea01.setText("Museum has no Razors");
}

for(int i=0;i
temp += razors;
// HERE IS WHERE I NEED SOMESORT OF RETURN LINE!
JTextArea01.setText("All Razors " + temp);

}

}
});



this is it if you can make head or tails of it.

[edited by - Arclight on April 21, 2004 11:19:18 AM]

[edited by - Arclight on April 21, 2004 11:20:38 AM]

Share this post


Link to post
Share on other sites
Try:

TextArea01.append( new Charecter( 13 ) );

I don''t know if that will work, because for some reason I''ve never had to create a newline in a text box before. I can''t think why not.

Try sun''s website:

http://java.sun.com/j2se/1.4.2/docs/api/

Also the JAVA tutorial:

http://java.sun.com/docs/books/tutorial/index.html

Share this post


Link to post
Share on other sites
JTextArea01.setText("All Razors " + temp + "\n");

To put each array entry on a separate line do something like this:


for(int i=0; i<razors.length; ++i)
{
JTextArea01.append(razors[i] + "\n");
}



[edited by - aldacron on April 21, 2004 11:35:26 AM]

Share this post


Link to post
Share on other sites
Because you eventually posted some code, I''m going to allow this thread to stay open. But be warned: Next time don''t just say "it''s not working," and ask for code, but rather post at least a link to yours since it''s very hard to help without anyone seeing it. Furthermore, you don''t want me to think it''s a homework question and close a legitimate thread

http://chaos.webhop.org

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
quote:
Applet we done in college.


Nice to see that is money well spent...

Share this post


Link to post
Share on other sites
quote:
Original post by pkelly83
The code I posted in original reply to Arclight was just a modified version of an Applet we done in college. I didn''t even write it ''twas straight out of my network drive.


I was referring to the original poster, actually. You''re fine.

Share this post


Link to post
Share on other sites