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

📄 alert.java

📁 j2me is based on j2mepolish, client & server for mobile application. menu sample
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
	 * of the <code>alertType</code>
	 * parameter and indicates that the <code>Alert</code> is not to
	 * have a specific alert
	 * type.  <code>DISMISS_COMMAND</code> is the only
	 * <code>Command</code> present on the new
	 * <code>Alert</code>.  The <code>CommandListener</code>
	 * associated with the new <code>Alert</code> is the
	 * <em>default listener</em>.  Its behavior is described in more detail in
	 * the section <a href="#commands">Commands and Listeners</a>.
	 * 
	 * @param title the title string, or null if there is no title
	 * @param alertText the string contents, or null if there  is no string
	 * @param alertImage the image contents, or null if there is no image
	 * @param alertType the type of the Alert, or null if the Alert has no specific type
	 */
	public Alert( String title, String alertText, Image alertImage, AlertType alertType)
	{
		//#if !polish.LibraryBuild
			//#style alert, default
			this( title, alertText, alertImage, alertType , de.enough.polish.ui.StyleSheet.alertStyle );
		//#else
			//# this( title, alertText, alertImage, alertType, null );
		//#endif
	}
	
	/**
	 * Constructs a new <code>Alert</code> object with the given title, content string and image, and alert type.
	 * 
	 * The layout of the contents is implementation dependent.
	 * The timeout value of this new alert is the same value that is
	 * returned by <code>getDefaultTimeout()</code>.
	 * The <code>Image</code> provided may either be mutable or immutable.
	 * The handling and behavior of specific <code>AlertTypes</code>
	 * is described in
	 * <A HREF="../../../javax/microedition/lcdui/AlertType.html"><CODE>AlertType</CODE></A>.  <code>null</code> is allowed as the value
	 * of the <code>alertType</code>
	 * parameter and indicates that the <code>Alert</code> is not to
	 * have a specific alert
	 * type.  <code>DISMISS_COMMAND</code> is the only
	 * <code>Command</code> present on the new
	 * <code>Alert</code>.  The <code>CommandListener</code>
	 * associated with the new <code>Alert</code> is the
	 * <em>default listener</em>.  Its behavior is described in more detail in
	 * the section <a href="#commands">Commands and Listeners</a>.
	 * 
	 * @param title the title string, or null if there is no title
	 * @param alertText the string contents, or null if there  is no string
	 * @param alertImage the image contents, or null if there is no image
	 * @param alertType the type of the Alert, or null if the Alert has no specific type
	 * @param style the style of this Alert
	 */
	public Alert( String title, String alertText, Image alertImage, AlertType alertType, Style style )
	{
		super( title, style, true );
		if ( alertText != null || alertImage != null ) {
			createItem( alertText, alertImage, null );
		}
		//#ifdef polish.i18n.useDynamicTranslations
			//# String okLabel = "OK";
			//# if ( okLabel != StyleSheet.OK_CMD.getLabel()) {
				//# StyleSheet.OK_CMD = new Command(okLabel, Command.OK, 2 );
				//# DISMISS_COMMAND = StyleSheet.OK_CMD; 
			//# }
		//#endif
		//this.alertType = alertType;
		addCommand( DISMISS_COMMAND );
		super.setCommandListener( this );
	}
	
	


	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#addCommand(javax.microedition.lcdui.Command)
	 */
	public void addCommand(Command cmd) {
		super.removeCommand( DISMISS_COMMAND );
		super.addCommand(cmd);
		this.numberOfCommands++;
		if (this.numberOfCommands > 1) {
			this.timeout = FOREVER;
		}
	}
	
	

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#removeCommand(javax.microedition.lcdui.Command)
	 */
	public void removeCommand(Command cmd) {
		super.removeCommand(cmd);
		this.numberOfCommands--;
		if (this.numberOfCommands == 0) {
			//#if polish.css.show-dismiss-command
				if (this.showDismissCommand || this.timeout == FOREVER) {
					super.addCommand( DISMISS_COMMAND );
				}
			//#else
				//# super.addCommand( DISMISS_COMMAND );
			//#endif
		}
	}

	/* (non-Javadoc)
	 * @see de.enough.polish.ui.Screen#setCommandListener(javax.microedition.lcdui.CommandListener)
	 */
	public void setCommandListener(CommandListener listener) {
		if (listener == null) {
			super.setCommandListener(this);
		} else {
			super.setCommandListener(listener);
		}
	}

	private void createItem(String alertText, Image alertImage, Style itemStyle) {
		if (itemStyle == null) {
			//#style alertcontent?
			this.iconItem = new IconItem( alertText, alertImage , de.enough.polish.ui.StyleSheet.alertcontentStyle );								
		} else {
			this.iconItem = new IconItem( alertText, alertImage, itemStyle );				
		}
		this.iconItem.appearanceMode = Item.PLAIN;
		this.container.add( this.iconItem );		
		
	}

	/**
	 * Gets the default time for showing an <code>Alert</code>, this is Alert.FOREVER in J2ME Polish.  
	 * This
	 * is either a
	 * positive value, which indicates a time in milliseconds, or the special
	 * value
	 * <A HREF="../../../javax/microedition/lcdui/Alert.html#FOREVER"><CODE>FOREVER</CODE></A>,
	 * which indicates that <code>Alerts</code> are modal by default.  The
	 * value returned will vary across implementations and is presumably
	 * tailored to be suitable for each.
	 * 
	 * @return in J2ME Polish the default timeout is always FOREVER
	 */
	public int getDefaultTimeout()
	{
		return Alert.FOREVER;
	}

	/**
	 * Gets the time this <code>Alert</code> will be shown.  This is
	 * either a positive
	 * value, which indicates a time in milliseconds, or the special value
	 * <code>FOREVER</code>, which indicates that this
	 * <code>Alert</code> is modal.  This value is not
	 * necessarily the same value that might have been set by the
	 * application
	 * in a call to <A HREF="../../../javax/microedition/lcdui/Alert.html#setTimeout(int)"><CODE>setTimeout(int)</CODE></A>.  In particular, if the
	 * <code>Alert</code> is made
	 * modal because its contents is large enough to scroll, the value
	 * returned by <code>getTimeout</code> will be <code>FOREVER</code>.
	 * 
	 * @return timeout in milliseconds, or FOREVER
	 * @see #setTimeout(int)
	 */
	public int getTimeout()
	{
		return this.timeout;
	}

	/**
	 * Set the time for which the <code>Alert</code> is to be shown.
	 * This must either
	 * be a positive time value in milliseconds, or the special value
	 * <code>FOREVER</code>.
	 * 
	 * @param time - timeout in milliseconds, or FOREVER
	 * @throws IllegalArgumentException - if time is not positive and is not FOREVER
	 * @see #getTimeout()
	 */
	public void setTimeout(int time)
	{
		this.timeout = time;
	}

	/**
	 * Gets the type of the <code>Alert</code>.
	 * 
	 * @return a reference to an instance of AlertType, or null if the Alert has no specific type
	 * @see #setType(javax.microedition.lcdui.AlertType)
	 */
	public AlertType getType()
	{
		return this.type;
	}

	/**
	 * Sets the type of the <code>Alert</code>.
	 * The handling and behavior of specific <code>AlertTypes</code>
	 * is described in
	 * <A HREF="../../../javax/microedition/lcdui/AlertType.html"><CODE>AlertType</CODE></A>.
	 * 
	 * @param type - an AlertType, or null if the Alert has no specific type
	 * @see #getType()
	 */
	public void setType( AlertType type)
	{
		this.type = type;
	}

	/**
	 * Gets the text string used in the <code>Alert</code>.
	 * 
	 * @return the Alert's text string, or null  if there is no text
	 * @see #setString(java.lang.String)
	 */
	public String getString()
	{
		if (this.iconItem == null) {
			return null;
		} else {
			return this.iconItem.getText();
		}
	}

	/**
	 * Sets the text string used in the <code>Alert</code>.
	 * 
	 * <p>If the <code>Alert</code> is visible on the display when its
	 * contents are updated
	 * through a call to <code>setString</code>, the display will be
	 * updated with the new
	 * contents as soon as it is feasible for the implementation to do so.
	 * </p>
	 * 
	 * @param str the Alert's text string, or null if there is no text
	 * @see #getString()
	 */
	public void setString( String str )
	{
		setString(str, null);
	}
	
	/**
	 * Sets the text string used in the <code>Alert</code>.
	 * 
	 * <p>If the <code>Alert</code> is visible on the display when its
	 * contents are updated
	 * through a call to <code>setString</code>, the display will be
	 * updated with the new
	 * contents as soon as it is feasible for the implementation to do so.
	 * </p>
	 * 
	 * @param str the Alert's text string, or null if there is no text
	 * @param style the style
	 * @see #getString()
	 */
	public void setString( String str, Style style )
	{
		if (this.iconItem == null) {
			createItem(str, null, style);
		} else if (style != null) {
			this.iconItem.setStyle(style);
		}
		this.iconItem.setText(str);
	}

	/**
	 * Gets the <code>Image</code> used in the <code>Alert</code>.
	 * 
	 * @return the Alert's image, or null  if there is no image
	 * @see #setImage(javax.microedition.lcdui.Image)
	 */
	public Image getImage()
	{
		if (this.iconItem == null) {
			return null;
		} else {
			return this.iconItem.getImage();
		}
	}

	/**
	 * Sets the <code>Image</code> used in the <code>Alert</code>.
	 * The <code>Image</code> may be mutable or
	 * immutable.  If <code>img</code> is <code>null</code>, specifies
	 * that this <code>Alert</code> has no image.
	 * If <code>img</code> is mutable, the effect is as if a snapshot is taken
	 * of <code>img's</code> contents immediately prior to the call to
	 * <code>setImage</code>.  This
	 * snapshot is used whenever the contents of the
	 * <code>Alert</code> are to be
	 * displayed.  If <code>img</code> is already the
	 * <code>Image</code> of this <code>Alert</code>, the effect

⌨️ 快捷键说明

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