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

📄 voteresults.java

📁 J2ME核心类及MIDlet类 MIDP用户界面对象 图形处理及低级事件处理 多线程编程 I/O及网络编程 数据库RMS编程 浮点数编程 多媒体及GAME API编程 安全、加密及
💻 JAVA
字号:
package com.itpath.examples.voter.ui;

import com.itpath.examples.voter.*;
import com.itpath.examples.voter.intf.*;
import com.itpath.examples.voter.util.*;

import java.util.*;
import javax.microedition.lcdui.*;

public class VoteResults extends Form implements CommandListener
{
	private Command voteCommand = new Command("Vote", Command.SCREEN, 99);
	private Command exitCommand = new Command("Exit", Command.EXIT, 98);

    private ChoiceGroup _voteResults = null;
	private ScreenCallback _screenCallback = null;

    public VoteResults(ScreenCallback sc)
    {
        super("Vote Results");

        Ticker ticker = new Ticker("What do you think of this article?");
        this.setTicker(ticker);

		_screenCallback = sc;

        VoteSummary voteSummary = ResourceUtility.getVoteSummary();

		initialize(voteSummary);

		// add Commands
		this.addCommand( voteCommand);
		this.addCommand( exitCommand);

		// set command listener
		this.setCommandListener( this);
    }

    public void initialize(VoteSummary voteSummary)
    {
		append( getNumVotesString( voteSummary.getNumVotes() )) ;
		append( getAvgVoteString( voteSummary.getAvgVote() ));
		append( showVoteResults( voteSummary.getVotes() ));
    }

	public void update(VoteSummary voteSummary)
	{
		set(0, getNumVotesString( voteSummary.getNumVotes() )) ;
		set(1, getAvgVoteString( voteSummary.getAvgVote() ));
		set(2, showVoteResults( voteSummary.getVotes() ));
	}

	private StringItem getNumVotesString(String num)
	{
		return new StringItem("Num Votes: ", num);
	}

	private StringItem getAvgVoteString(String num)
	{
		return new StringItem("Avg. Vote: ", num);
	}

    private Item showVoteResults(Vector votes)
    {
        _voteResults = new ChoiceGroup("Please Vote", ChoiceGroup.EXCLUSIVE);

        for ( int i = 0; i < votes.size(); i++)
        {
            _voteResults.append( votes.elementAt(i).toString(), null );
        }

        return _voteResults;
    }

    public void commandAction(Command c, Displayable s)
    {
		String command = c.getLabel();

        if ( command.equals("Exit") )
        {
			_screenCallback.exit();
		}
		else if ( command.equals("Vote") )
		{
			// get the selected item
			int selectedIndex = _voteResults.getSelectedIndex();

			Vote newVote = new Vote(""+ selectedIndex, null, null);

			VoteSummary voteSummary = ResourceUtility.addEntry( newVote);

			update( voteSummary );
		}
    }
}

⌨️ 快捷键说明

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