I have two class. One class is for JAVA text area another class has a object. I want to print in the textarea from another class. The class with the text area.

        public class LabelStatus extends JPanel {
            /**
             * 
             */
            private static final long serialVersionUID = 1L;

            final static JTextArea test =new JTextArea(40, 60);



        public LabelStatus() {
                JLabel title = new JLabel ("INCOMING MESSAGES  ",JLabel.CENTER);
                title.setFont(new Font ("Serif", Font.BOLD,30));
                this.add(title); 
                GridBagConstraints k = new GridBagConstraints();       
                k.gridx = 10;
                k.gridy = 10; 

                test.setLineWrap(true);   
                test.setWrapStyleWord(true);
                test.setEditable(false);  


                JScrollPane spane = new JScrollPane(test);
                spane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
                GridBagLayout gbl = new GridBagLayout(); 
                gbl.setConstraints(spane,k);     
                JPanel panel = new JPanel(gbl);
                panel.add(spane);  
                add(panel);          
                }

                public final id  WriteOnPanel(final dataclass mrcc)
                {

                    test.setText("\n THE STATUS " + mrcc.getMainState().value());

                }   

                }   

In this class I want to use the WriteOnPanel function to write my object.

In the other class I have the function which call WriteOnPanel to write some thing.Like this

LabelStatus.WriteOnPanel(mradarcontrolcommand);

Looks like I cannot write the object in the JTEXTAREA.

Please let me know how to deal with it.

WriteOnPanel is (correctly) an instance netrhod, so in your "other" class you need a reference to the instance of LabelStatus that you want to use when you call that method. Somewhere in your code you will create a new LabelStatus object, and you need to pass that into your "other" class, eg as a parameter in its constructor. Exactly how/where you do that depends on how your code is structured overall - so I can't be any more specific.

The other class is as follows

public class CommandSubscriber implements MessageListener {
IMaritimeRadarControlCommand mradarcontrolcommand;

/**
 * Logger
 */
private static final Logger logger = Logger.getLogger(CommandSubscriber.class);

private PluginTester plugin;


public CommandSubscriber() {
}
public CommandSubscriber(final PluginTester plugin) {
    this.plugin = plugin;




}


/**
 * Overwritten method.
 * Called from JMS to handle control command.
 * @param message Received message
 */
@Override
public final void onMessage(final Message message) {



    logger.info("entering onMessage()");
        if (message instanceof TextMessage) {
            TextMessage textMsg = (TextMessage) message;

            String type = null;
            try {
              type = textMsg.getStringProperty("TYPE");
            } catch (JMSException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            String xml = null;
            try {
                xml = textMsg.getText();
            } catch (JMSException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            logger.info("received message: '" + xml);

            if (type.equals("MaritimeRadarControlCommand")) {
                mradarcontrolcommand=ControlCommandFactory.unMarshalling(xml,this.getPlugin());
                System.out.println("\n SENDING THE MESSAGE TO LABEL STATUS");

            *   LabelStatus.WriteOnPanel(mradarcontrolcommand); *               
            }

            else {
                logger.warn("Unknown TextMessage received. type: " + type);
            }
        }
 }
/**
 * 
 * @return PluginTester for xml schema for jaxb unmarshalling
 */
public final PluginTester getPlugin() {
    return plugin;
}
//  logger.info("leaving onMessage()");

}

In this class I use LabelStatus.WriteOnPanel functionality to write the object information.

This question has already been answered. Start a new discussion instead.