🔒 Locked
[java] Dumbass java
Advertisement
Original Post
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]
Whats in the array text or numbers?
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]
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]
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]
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
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
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
http://chaos.webhop.org
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement