processMessage, can't use other objects

Hi everyone,

I have been trying to solve this problem for 2 days now. I am geting crazy :

I have this function :

public void processMessage(Chat chat, Message message )

{

if(message.getType() == Message.Type.chat){

System.out.println(chat.getParticipant() + " says: " + message.getBody());

}

}

in the same class I have this attribute :

ChatBox chatBoxLinked = null;

(instancied by the constructor)

In all the other methods I can do this :

chatBoxLinked.MessageDisplay(message);

like for example :

public void sendMessage(String message, String to) throws XMPPException

{

chat = connection.getChatManager().createChat(to, this);

chat.sendMessage(message);

chatBoxLinked.MessageDisplay(message);

}

But into the processMessage function I can’t, it doesn’t work and I don’t have any error output.

Could anyone help me please ?

Best Regards

You are going to have to give more information. What is actually happening? Saying that it doesn’t work is not much to go on.

How exactly does it not work and what have you tried.

The problem is in my “appendReceivedMessage” method, the line :

this.MessageDisplay(messagereceived); doesn’t do anything and stop the execution of the method.

However the same line :

this.MessageDisplay(“Welcome”);

Works and do what I want.

Here is my code :

/*

  • To change this template, choose Tools | Templates and open the template in

  • the editor.

*/

package olamessenger;

import java.util.logging.Level;

import java.util.logging.Logger;

import javafx.event.ActionEvent;

import javafx.event.EventHandler;

import javafx.scene.Group;

import javafx.scene.Scene;

import javafx.scene.control.Button;

import javafx.scene.control.ScrollPane;

import javafx.scene.control.TextField;

import javafx.scene.layout.HBox;

import javafx.scene.layout.VBox;

import javafx.stage.Stage;

import olamessenger.smack.ServerConnection;

import olamessenger.smack.UserMessaging;

import org.jivesoftware.smack.*;

/**

  • @author Vincent

*/

public class MainApp {

public Group root = null;

public Scene scene = null;

public ScrollPane sp = null;

public HBox hbDisplayMessage = null;

public HBox hbSendMessage = null;

public HBox hbTest = null;

public VBox vbMessageContainer = null;

public VBox vbDialog = null;

public TextField typedMessage = null;

public TextField txForPic = null;

public TextField txMessageContent = null;

public TextField receivedMessage = null;

public VBox vbReceivedMessage = null;

public Button sendMessage = null;

public UserMessaging usermessaging = null;

private int id;

private static int numberOfChatBox = 0;

public MainApp(Stage mainStage) {

id = ++numberOfChatBox;

//Initializing the scene

mainStage.setTitle(“Messenger Welcome”);

root = new Group();

scene = new Scene(root, 800, 650);

scene.getStylesheets().add(“olamessenger/theme/dialogBoxStyle.css”);

//Chat Box initialization

vbDialog = new VBox();

vbDialog.setLayoutX(150);

//Joining the scrollpanel and the message container

vbMessageContainer = new VBox();

sp = new ScrollPane();

sp.setMinHeight(500);

sp.setMinWidth(600);

sp.setContent(vbMessageContainer);

// Creating the send message area

sendMessage = new Button();

sendMessage.setText(“Send Message”);

sendMessage.setMinHeight(40);

typedMessage = new TextField();

typedMessage.setMinWidth(500);

typedMessage.setMinHeight(40);

hbSendMessage = new HBox();

hbSendMessage.getChildren().addAll(typedMessage,sendMessage);

//Handling the send actions

usermessaging = new UserMessaging(this);

sendMessage.setOnAction(new EventHandler() {

public void handle(ActionEvent event) {

try {

System.out.println(“trying to send a message”);

//usermessaging.getChatBox().MessageDisplay(typedMessage.getText());

usermessaging.sendMessage(typedMessage.getText(),“admin”+"@"+ServerConnection.g etServerIp());

usermessaging.sendMessage(typedMessage.getText(),“sambasub”+"@"+ServerConnectio n.getServerIp());

} catch (XMPPException ex) {

Logger.getLogger(MainApp.class.getName()).log(Level.SEVERE, null, ex);

}

}

});

//This is for testing

receivedMessage = new TextField();

HBox hbRm = new HBox();

hbRm.getChildren().addAll(receivedMessage);

//Join the scrollbar and send message and received messages for test (hbRm)

vbDialog.getChildren().addAll(sp,hbSendMessage,hbRm);

this.MessageDisplay(“Welcome”);

root.getChildren().add(vbDialog);

mainStage.setScene(scene);

mainStage.show();

}

public void appendReceivedMessage (String messagereceived) {

this.MessageDisplay(messagereceived);

receivedMessage.setText(receivedMessage.getText() + messagereceived);

}

public void MessageDisplay(String messageContent) {

hbDisplayMessage = new HBox();

hbDisplayMessage.setMinHeight(50);

//System.out.println(sp.getMinWidth());

//hbMessage.setMinWidth(800);

txForPic = new TextField();

txForPic.setText(“picture here”);

txForPic.setEditable(false);

txForPic.setId(“txForPic”);

txMessageContent = new TextField();

txMessageContent.setText(messageContent);

txMessageContent.setEditable(false);

// txMessageContent.setMinWidth(sp.getMinWidth()-txForPic.getWidth());

txMessageContent.setMinWidth(450);

//txMessageContent.setStyle("-fx-background: #ed1c24;");

hbDisplayMessage.getChildren().addAll(txForPic,txMessageContent);

vbMessageContainer.getChildren().addAll(hbDisplayMessage);

}

}

I am not familiar with javafx, but is it possible that you have a threading issue. Many UI libraries, like swt, for example, only allow a specific UI thread to call any method that writes to the display.

If this is the case for javafx, then you will have to wrap the call to MessageDisplay inside of a UI thread, since it is currently being called on Smack’s reader thread.

BTW, Java conventions dictate that method names start with a lower case. Hungarion notation is not very popular either