[java] Dumbass java

Started by
12 comments, last by Arclight 19 years, 12 months ago
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]
-----------------------------Like A Midget At A Urinal, Im Always On My Toes.Beer helping ugly people get laid since 4000BC.
Advertisement
Whats in the array text or numbers?
Strings.
-----------------------------Like A Midget At A Urinal, Im Always On My Toes.Beer helping ugly people get laid since 4000BC.
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 + " ";<br>      }<br><br>      if( destination.getText() == "" )<br>      {<br>        destination.setText( temp );<br>      }<br>      else<br>      {<br>        destination.append( temp );<br>      }<br><br>    }<br><br>  }<br>}<br><br><br></pre><br><br>Dunno if this helps.     </pre>    <br><br><SPAN CLASS=editedby>[edited by - pkelly83 on April 21, 2004 10:37:39 AM]</SPAN>
it helps alot, thanks.
if i still cant get it to work i''ll post again soon, lol.
-----------------------------Like A Midget At A Urinal, Im Always On My Toes.Beer helping ugly people get laid since 4000BC.
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.
-----------------------------Like A Midget At A Urinal, Im Always On My Toes.Beer helping ugly people get laid since 4000BC.
Do us and yourself a favor, and post your code.

It''s not Java''s fault; title should have been "Dumbass programmer" ...
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]
-----------------------------Like A Midget At A Urinal, Im Always On My Toes.Beer helping ugly people get laid since 4000BC.
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
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]

This topic is closed to new replies.

Advertisement