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

クリックするとアクションを実行する画像(アイコン)が必要だと仮定しています。すなわち。厚い長方形のボタンは必要ありません。

したがって、次の場合に備えて:

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 に答える
0

Imageボタン コンストラクターに追加のパラメーターを渡します。ImageIO クラスを使用してイメージを作成します。

于 2012-06-16T09:12:44.203 に答える