2012-06-16 6 views
0

아이콘 버튼 설정 방법에 대해 조언 해 줄 사람이 있습니까? 여기에 내 코드입니다 : 당신은 버튼 생성자에 추가 Image 매개 변수를 전달버튼 LWUIT 자바 ME 아이콘 설정

/* 
* 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. 
    } 
} 
+0

에 오신 것을 환영합니다. '{} '아이콘을 사용하여 코드의 형식을 지정하십시오. – Leigh

답변

0

는; ImageIO 클래스를 사용하여 이미지를 생성합니다.

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); 

OR :

간단하지만 메모리를 많이 방법은 다음과 같습니다

그래서 경우에 그입니다

myButton.setFlatten(true); 

OR :

사용 resourc 편집기를 .. . GUI를 어디에 버튼, 라벨 등 다양한 구성 요소에 대한 스타일 등을 지정할 수 있습니다.