Jump to content
  • Advertisement

Archived

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

Arclight

[java] Dumbass java

This topic is 5204 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
Advertisement


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!