my JTextArea won't update! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

my JTextArea won't update!

alftansralftansr Posts: 2Member
i'm trying to update my jtextarea, but it won't show the text i put into it! the strange this is that my system.out.prints show that the jtextarea is getting the information...so if the jtextarea knows what to display, why won't it? ideas? solutions? workarounds? any help would be greatly appreciated

class Test{
Test(){
UserInterface ui = new UserInterface();
}

public static void main( String[] args ){
new Test();
}
}

import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.border.*;

class UserInterface
implements MouseListener
{
private JFrame framer;
private InformationPanel ipanel;

public UserInterface(){
int maxL = 400;
framer = new JFrame( "My Title" );
framer.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
framer.setSize( maxL, 600 );
framer.setLocation( 200, 30 );
JPanel payne = new JPanel();
payne.setOpaque( true );
JPanel enterMe = new JPanel();
enterMe.addMouseListener( this );
enterMe.setBackground( Color.LIGHT_GRAY );
payne.add( enterMe );
ipanel = new InformationPanel();
payne.add( enterMe );
payne.add( new InformationPanel() );
framer.add( payne );
framer.pack();
framer.setVisible( true );
}
public void mouseClicked( MouseEvent e ){
setSquare( "click", "click" );
return;
}

public void mousePressed( MouseEvent e ){
return;
}

public void mouseReleased( MouseEvent e ){
return;
}

public void mouseEntered( MouseEvent e ){
setSquare( "hello", "world" );
return;
}

public void mouseExited( MouseEvent e ){
newGame();
return;
}

public JFrame getFrame(){
return framer;
}

public void newGame(){
ipanel.clearText();
}

public void setSquare( String piece, String place ){
ipanel.addText( "Hello World" );
}
}

import javax.swing.*;
import java.awt.*;
import java.awt.image.*;
import javax.swing.border.*;

class InformationPanel
extends JPanel
{
private JTextArea infoText;

public InformationPanel(){
super();
infoText = new JTextArea( 10, 5 );
infoText.setEditable( true );
infoText.setText( "Egad!" );
add( infoText );
}

public void addText( String text ){
infoText.append( text );
System.out.println( infoText.getText() );
}

public void clearText(){
infoText.setText( "" );
infoText.setBackground( Color.RED );
System.out.println( "clearing text" );
System.out.println( infoText.getText() );
}
}


Comments

  • alftansralftansr Posts: 2Member
    i don't know why my code below doesn't work, but i found a workaround.

    : i'm trying to update my jtextarea, but it won't show the text i put into it! the strange this is that my system.out.prints show that the jtextarea is getting the information...so if the jtextarea knows what to display, why won't it? ideas? solutions? workarounds? any help would be greatly appreciated
    :
    : class Test{
    : Test(){
    : UserInterface ui = new UserInterface();
    : }
    :
    : public static void main( String[] args ){
    : new Test();
    : }
    : }
    :
    : import javax.swing.*;
    : import java.awt.*;
    : import java.awt.image.*;
    : import java.awt.event.*;
    : import javax.swing.border.*;
    :
    : class UserInterface
    : implements MouseListener
    : {
    : private JFrame framer;
    : private InformationPanel ipanel;
    :
    : public UserInterface(){
    : int maxL = 400;
    : framer = new JFrame( "My Title" );
    : framer.setDefaultCloseOperation( WindowConstants.EXIT_ON_CLOSE );
    : framer.setSize( maxL, 600 );
    : framer.setLocation( 200, 30 );
    : JPanel payne = new JPanel();
    : payne.setOpaque( true );
    : JPanel enterMe = new JPanel();
    : enterMe.addMouseListener( this );
    : enterMe.setBackground( Color.LIGHT_GRAY );
    : payne.add( enterMe );
    : ipanel = new InformationPanel();
    : payne.add( enterMe );
    : payne.add( new InformationPanel() );
    : framer.add( payne );
    : framer.pack();
    : framer.setVisible( true );
    : }
    : public void mouseClicked( MouseEvent e ){
    : setSquare( "click", "click" );
    : return;
    : }
    :
    : public void mousePressed( MouseEvent e ){
    : return;
    : }
    :
    : public void mouseReleased( MouseEvent e ){
    : return;
    : }
    :
    : public void mouseEntered( MouseEvent e ){
    : setSquare( "hello", "world" );
    : return;
    : }
    :
    : public void mouseExited( MouseEvent e ){
    : newGame();
    : return;
    : }
    :
    : public JFrame getFrame(){
    : return framer;
    : }
    :
    : public void newGame(){
    : ipanel.clearText();
    : }
    :
    : public void setSquare( String piece, String place ){
    : ipanel.addText( "Hello World" );
    : }
    : }
    :
    : import javax.swing.*;
    : import java.awt.*;
    : import java.awt.image.*;
    : import javax.swing.border.*;
    :
    : class InformationPanel
    : extends JPanel
    : {
    : private JTextArea infoText;
    :
    : public InformationPanel(){
    : super();
    : infoText = new JTextArea( 10, 5 );
    : infoText.setEditable( true );
    : infoText.setText( "Egad!" );
    : add( infoText );
    : }
    :
    : public void addText( String text ){
    : infoText.append( text );
    : System.out.println( infoText.getText() );
    : }
    :
    : public void clearText(){
    : infoText.setText( "" );
    : infoText.setBackground( Color.RED );
    : System.out.println( "clearing text" );
    : System.out.println( infoText.getText() );
    : }
    : }
    :
    :
    :

Sign In or Register to comment.