1

谁能告诉我什么是 xlets 和一个简单的程序(带有 xlets 和 java)以及运行所需的所有软件。

4

1 回答 1

2

Xlet 适用于嵌入式设备的Java ME 平台。此链接可能会有所帮助

Netbeans 允许您从 PC 运行应用程序

从链接复制并粘贴:

package helloxlet;
import javax.microedition.xlet.*;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Font;

// Create the Main class.
public class Main extends Component implements Xlet {
    private Container rootContainer;
    private Font font;

    // Initialize the xlet.
    public void initXlet(XletContext context) {
        log("initXlet called");
        // Setup the default container
        // This is similar to standard JDK programming,
        // except you need to get the container first.
        // XletContext.getContainer gets the parent 
        // container for the Xlet to put its AWT components in. 
        // and location is arbitrary, so needs to be set. 
        // Calling setVisible(true) make the container visible.
        try {
            rootContainer = context.getContainer();
            rootContainer.setSize(400, 300);
            rootContainer.setLayout(new BorderLayout());
            rootContainer.setLocation(0, 0);
            rootContainer.add("North", this);
            rootContainer.validate();
            font = new Font("SansSerif", Font.BOLD, 20);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // Start the xlet.
    public void startXlet() {
        log("startXlet called");
        //make the container visible
        rootContainer.setVisible(true);
    }

    // Pause the xlet
    public void pauseXlet() {
        log("pauseXlet called");
        //make the container invisible
        rootContainer.setVisible(false);
    }

    // Destroy the xlet
    public void destroyXlet(boolean unconditional) {
        log("destroyXlet called");
        //some cleanup for the xlet..
        rootContainer.remove(this);
    }

    void log(String s) {
        System.out.println("SimpleXlet: " + s);
    }

    public void paint(Graphics g) {
        int w = getSize().width;
        int h = getSize().height;
        g.setColor(Color.blue);
        g.fill3DRect(0, 0, w - 1, h - 1, true);
        g.setColor(Color.white);
        g.setFont(font);
        g.drawString("Hello Java World", 20, 150);
    }

    public Dimension getMinimumSize() {
        return new Dimension(400, 300);
    }

    public Dimension getPreferredSize() {
        return getMinimumSize();
    }
}
于 2016-01-21T06:36:41.110 回答