0

谁能建议如何设置图标按钮?这是我的代码:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tajwed;

import javax.microedition.midlet.*;

    import com.sun.lwuit.*;
    import com.sun.lwuit.animations.*;
    import com.sun.lwuit.events.*;
    import com.sun.lwuit.layouts.BoxLayout;
    import com.sun.lwuit.plaf.*;
    import java.io.IOException;
    import java.util.Hashtable;

/**
 * @author Muhamad BUrhanudin
 */
public class tajwedMidlet extends MIDlet implements ActionListener{

    Form    mHomeForm;
    Form    mAwayForm;
    Form    mMenuTajwid;

    Command mExitCommand;

    Button btMenu;
    Button btNunSukun, btMimSukun, btNunTasjid;
    Button btLamtarif, btIdgham, btMaad, btRaa;
    Button btHelp;
    Button btExit;

    Command mBackCommand;


    public void startApp() {
        Display.init(this);

        installTheme();
        createUI();
        mHomeForm.show();

    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {

    }

    public void actionPerformed(ActionEvent ae)
    {
            mAwayForm.setTransitionInAnimator(
                Transition3D.createCube(400, false));

            mMenuTajwid.setTransitionInAnimator(
                Transition3D.createCube(400, false));


            mMenuTajwid.setTransitionOutAnimator(
                Transition3D.createCube(400, true));

            mAwayForm.setTransitionOutAnimator(
                Transition3D.createCube(400, true));

        if ((ae.getSource()==btMenu)|| (ae.getSource()==btHelp))
        {
            //mAwayForm.show();
            if(ae.getSource()== btMenu)
            {
                mMenuTajwid.show();
            }
        }
        else if (ae.getSource() == mBackCommand) {
            mHomeForm.show();
        }
        else if ((ae.getCommand() == mExitCommand) || (ae.getSource()== btExit))

          notifyDestroyed();
    }

    private void installTheme()
    {
       UIManager uim = UIManager.getInstance();
        Hashtable ht = new Hashtable();
        ht.put("sel#" + Style.BG_COLOR, "ffffff");
        ht.put(Style.BG_COLOR, "d5fff9");
        ht.put(Style.FG_COLOR, "000000");
        uim.setThemeProps(ht);

     }
    private void createUI() {
      // Set up screen for transitions.
      mAwayForm = new Form("Away");
      mAwayForm.addComponent(new Label("Choose Back to return to the home screen."));

      mMenuTajwid = new Form("MENU DASAR TAJWID");
    //  mMenuTajwid
      mMenuTajwid.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

      btNunSukun = new Button("Hukum Nun Sukun & Tanwin");
      btNunSukun.addActionListener(this);
      mMenuTajwid.addComponent(btNunSukun);

      btMimSukun = new Button("Hukum Mim Sukun");
      btMimSukun.addActionListener(this);
      mMenuTajwid.addComponent(btMimSukun);

      btNunTasjid = new Button("Hukum Nun Tasydid & Min Tasydid");
      btNunTasjid.addActionListener(this);
      mMenuTajwid.addComponent(btNunTasjid);

      btLamtarif = new Button("Hukum Laam Ta'rief");
      btLamtarif.addActionListener(this);
      mMenuTajwid.addComponent(btLamtarif);

      btIdgham = new Button("Idgham");
      btIdgham.addActionListener(this);
      mMenuTajwid.addComponent(btIdgham);

      btMaad = new Button("Maad");
      btMaad.addActionListener(this);
      mMenuTajwid.addComponent(btMaad);

      btRaa = new Button("Raa'");
      btRaa.addActionListener(this);
      mMenuTajwid.addComponent(btRaa);

      mBackCommand = new Command("Back");
      mMenuTajwid.addCommand(mBackCommand);
      mMenuTajwid.addCommandListener(this); // Use setCommandListener() with LWUIT 1.3 or earlier.

      // Set up main screen.
      mHomeForm = new Form("Java Mobile Learning");
      mHomeForm.setLayout(new BoxLayout(BoxLayout.Y_AXIS));

      btMenu = new Button("TAJWID LEARNING");
      btMenu.addActionListener(this);
      mHomeForm.addComponent(btMenu);

      try
      {
      btHelp = new Button("HELP",Image.createImage("/help.ico"));
      btHelp.addActionListener(this);
      mHomeForm.addComponent(btHelp);
      }
      catch(IOException e)
      {

      }

      btExit = new Button("EXIT");
      btExit.addActionListener(this);
      mHomeForm.addComponent(btExit);

      mExitCommand = new Command("Keluar");
      mHomeForm.addCommand(mExitCommand);
      mHomeForm.addCommandListener(this); // Use setCommandListener() with LWUIT 1.3 or earlier.
    }
}
4

2 回答 2

0

您将一个额外的Image参数传递给按钮构造函数;您使用 ImageIO 类构建图像。

于 2012-06-16T09:12:44.203 回答
0

我假设您想要一个图像(图标),单击该图像(图标)会执行操作。IE。你不想要一个厚的矩形按钮。

所以如果是这样:

Button myButton = new Button("HELP",Image.createImage("/help.ico"));

    myButton.getStyle().setBgImage(null);
    myButton.getStyle().setPadding(0, 0, 0, 0);
    myButton.getStyle().setBorder(null);

    myButton.getPressedStyle().setBgImage(null);
    myButton.getPressedStyle().setPadding(0, 0, 0, 0);
    myButton.getPressedStyle().setBorder(null);

或者:

一种更简单但占用大量内存的方法是:

myButton.setFlatten(true);

或者:

使用资源编辑器...一个 GUI,您可以在其中为按钮、标签等不同组件指定样式等。

于 2012-06-20T03:29:32.110 回答