📄 helloworldsubclass.java
字号:
package Jt.examples;
import Jt.*;
/**
* Demonstrates the Jt framework API.
*/
public class HelloWorldSubclass extends HelloWorld {
public static final String JtCLASS_NAME = HelloWorldSubclass.class.getName();
public static final String JtHELLO = "JtHELLO";
private static final long serialVersionUID = 1L;
private String greetingMessage;
public HelloWorldSubclass() {
}
// Attributes
public void setGreetingMessage (String greetingMessage) {
this.greetingMessage = greetingMessage;
}
public String getGreetingMessage () {
return (greetingMessage);
}
// Process object messages
public Object processMessage (Object message) {
String msgid = null;
JtMessage msg = (JtMessage) message;
if (msg == null)
return null;
msgid = (String) msg.getMsgId ();
if (msgid == null)
return null;
// Process the JtHELLO Message
if (msgid.equals (HelloWorldSubclass.JtHELLO)) {
if (greetingMessage == null)
greetingMessage = "Hello World ...";
handleTrace ("HelloWorld returning a greeting message: " + greetingMessage);
return (greetingMessage);
}
if (msgid.equals (JtObject.JtREMOVE)) {
return (null);
}
// Let the superclass handle all other messages
return (super.processMessage (message));
}
/**
* HelloWorld program. Demonstrates the use of the
* framework messaging API.
* 1) JtFactory creates an instance of HelloWorld.
* 2) Sends an message to the new instance and prints the reply.
* 3) Removes the new instance.
*/
public static void main(String[] args) {
JtFactory factory = new JtFactory (); // Jt Factory
String reply;
HelloWorldSubclass helloWorld;
//factory.setLogging(true);
// Create helloWorld (HelloWorld class)
helloWorld = (HelloWorldSubclass) factory.createObject (HelloWorldSubclass.JtCLASS_NAME, "helloWorldSubclass");
// Create a Message ("JtHELLO")
JtMessage msg = new JtMessage (HelloWorldSubclass.JtHELLO);
// Send the Message
factory.handleTrace ("main:sending a message (JtHello) to the helloWorld object ...");
reply = (String) factory.sendMessage (helloWorld, msg);
// Print the reply message (Greeting)
System.out.println (reply);
// Remove helloWorld
factory.removeObject (helloWorld);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -