⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jxmemidlet.java

📁 This Source.zip has three application code folders containing .java and .class files and two .jar fi
💻 JAVA
字号:

import java.io.IOException;

import javax.microedition.rms.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;


public class JXMEMIDlet extends MIDlet implements ItemCommandListener
{
    private Display display;
    
    private final Command CMD_SEND = new Command ( "Send", Command.ITEM, 1 );

    private TextField tfRecipientName = null;
    private TextField tfMessageForRecipient = null;
    private TextField tfMessageFromSender = null;

    private StringItem sendButton = null;
    private JXTA4JMSMessagingClient jxmeMessagingClient = null;
    
    private String relayURL = "http://localhost:9700";
    private String sender = "Sender: ";    

    public JXMEMIDlet()
    {
        try {
            tfMessageFromSender = new TextField ( "", "", 40, TextField.UNEDITABLE);            
            jxmeMessagingClient = new JXTA4JMSMessagingClient(
                                                    relayURL, 
                                                    "Alice", 
                                                    15000, 
                                                    tfMessageFromSender);

            System.out.println ("Got connection with relay...");
            showMessagingForm();
        }//try
        catch ( Exception e ){
            e.printStackTrace();
        }//catch
        
    }//JXMEMIDlet


    public void startApp(){
        Thread thread = new Thread (jxmeMessagingClient );
        thread.start();
    }//startApp()


    public void pauseApp(){
    }//pauseApp()


    public void destroyApp (boolean b){
    }//destroyApp()


    private void showMessagingForm() {
        Form msgForm = new Form ("JXTA4JMS Messaging");

        tfRecipientName = new TextField ( "Message To:", "", 10, TextField.ANY );
        tfMessageForRecipient = new TextField ( "Message", "", 40, TextField.ANY );
        
        sendButton = new StringItem ( "Send", "", Item.BUTTON );
        sendButton.setDefaultCommand ( CMD_SEND );
        sendButton.setItemCommandListener ( this );
        sendButton.setLayout( Item.LAYOUT_2 );

        msgForm.append ( tfMessageFromSender );

        msgForm.append ( tfRecipientName );
        msgForm.append ( tfMessageForRecipient );
        msgForm.append ( sendButton );

        display = Display.getDisplay (this);
        display.setCurrent ( msgForm );

    }//showMessagingForm()
    
    
    public void commandAction (Command c, Item item)
    {
        if ( c == CMD_SEND )
        {
            try
            {
                if ( tfRecipientName.getString().equals( "" ) )
                {
                    Alert alert = new Alert(
                          "Error", 
                          "Please enter recipient name for sending message", 
                          null, 
                          AlertType.ERROR
                          );
                    alert.setTimeout( 1000 );
                    display.setCurrent ((Screen) alert);
                
                }//if (tfRecipientName.getString().equals( "" ))
                else
                {
                   JXTA4JMSMessage message = new JXTA4JMSMessage( (tfRecipientName.getString()), 
                                                          tfMessageForRecipient.getString() 
                                                           );
                   jxmeMessagingClient.sendMessage (message);
                }
            }//try
            
            catch ( Exception e )
            {
                e.printStackTrace();
            }
        }//if (c == CMD_SEND)
        
    }//commandAction()
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -