Results 1 to 4 of 4

Thread: Mutable Image in Java

  1. #1
    Join Date
    Nov 2009
    Posts
    678

    Mutable Image in Java

    Hello, I want details about the Mutable images. If anyone is having information about it, then please reply those details to me. If you give me any source code, then it will help me alot. So, give me program related to the Mutable Image. I am waiting for your reply. Please, help me in this problem. Thank in advance.

  2. #2
    Join Date
    May 2008
    Posts
    2,389

    Re: Mutable Image in Java

    Most of the time for Mutable images created with the help of canvas class. The user class extends the Canvas class to create the image. For this the method such as below are used as follows:

    Code:
    image = Image.createImage(100, 20);       
    Graphics graphics = image.getGraphics();       
    Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,  Font.SIZE_MEDIUM);       
    graphics.setFont(font);       
    graphics.setColor(255, 0, 0);       
    graphics.fillRoundRect(0,0, image.getWidth()-1,  image.getHeight()-1, 20, 20);        
    graphics.setColor(0, 0, 255);                  
    graphics.drawString(message,(image.getWidth()/2) -  (font.stringWidth(message)/2), 0, Graphics.TOP | Graphics.LEFT);

  3. #3
    Join Date
    Feb 2008
    Posts
    1,852

    Re: Mutable Image in Java

    Hello, I think the code given below will give your more details knowledge about the Mutable Image in java than any explanation about it. So, understand the code and use it.

    Code:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    
    public class MutableImage extends MIDlet
    {
    	private Display  dis;
    	private ImageCanvas1 canvas;
    
    	public MutableImage()
    	{
    		dis = Display.getDisplay(this);
    		canvas  = new ImageCanvas1(this);
    	}
    
    	protected void startApp()
    	{
    		dis.setCurrent(canvas);
    	}
    
    	protected void pauseApp()
    	{
    	}
    
    	protected void destroyApp(boolean unconditional)
    	{
    		notifyDestroyed();
    	}
    
    	public void exitMIDlet()
    	{
    		destroyApp(true);
    	}
    }
    
    class ImageCanvas1 extends Canvas implements CommandListener
    {
    	private Command cmd;
    	private MutableImage MI;
    	private Image img;
    	private String msg = "Mutable Image Example";
    
    	public ImageCanvas1(MutableImage MI)
    	{
    		this.MI = MI;
    		cmd = new Command("Exit", Command.EXIT, 1);
    		addCommand(cmd);
    		setCommandListener(this);
    		try
    		{
    			img = Image.createImage(100, 20);
    			Graphics g = img.getGraphics();
    			Font font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN, Font.SIZE_MEDIUM);
    			g.setFont(font);
    			g.setColor(255, 0, 0);
    			g.fillRoundRect(0,0, img.getWidth()-1, img.getHeight()-1, 20, 20); 
    			g.setColor(0, 0, 255);           
    			g.drawString(msg,(img.getWidth()/2) - (font.stringWidth(msg)/2), 0, Graphics.TOP | Graphics.LEFT);
    		}
    		catch (Exception e)
    		{
    			System.err.println(e);
    		}    
    	}
    
    	protected void paint(Graphics g)
    	{
    		if(img != null)
    		{
    			g.drawImage(img, getWidth()/2, getHeight()/2, Graphics.VCENTER | Graphics.HCENTER);
    		}
    	}
    
    	public void commandAction(Command c, Displayable d)
    	{
    		String label = c.getLabel();
    		if(label.equals("Exit"))
    		{
    			MI.cmdMIDlet();
    		} 
    	}
    }

  4. #4
    Join Date
    Jan 2008
    Posts
    1,521

    Re: Mutable Image in Java

    The code given below will help you get the knowledge about the Mutable image. Use it to solve your problem.

    Code:
    import javax.microedition.lcdui.Canvas;
    import javax.microedition.lcdui.Command;
    import javax.microedition.lcdui.CommandListener;
    import javax.microedition.lcdui.Display;
    import javax.microedition.lcdui.Displayable;
    import javax.microedition.lcdui.Graphics;
    import javax.microedition.lcdui.Image;
    import javax.microedition.midlet.MIDlet;
    
    public class MutableImage extends MIDlet
    {
    private Display dis;
    private MyCanvas Mcanvas;
    
    public MutableImage()
    {
    dis = Display.getDisplay(this);
    Mcanvas = new MyCanvas(this);
    }
    
    protected void startApp() 
    {
    dis.setCurrent(Mcanvas);
    }
    
    protected void pauseApp() 
    {
    }
    
    protected void destroyApp(boolean unconditional) 
    {
    }
    
    public void exitMIDlet() 
    {
    destroyApp(true);
    notifyDestroyed();
    }
    
    public Display getDisplay() 
    {
    return dis;
    }
    
    }
    
    class MyCanvas extends Canvas implements CommandListener 
    {
    private Command cmd;
    private MutableImage MI;
    private Image img = Image.createImage(70, 70);
    public MyCanvas(MutableImage MI) 
    {
        this.MI = MI;
        cmd = new Command("Exit", Command.EXIT, 1);
        addCommand(cmd);
        setCommandListener(this);
        Graphics graphics = img.getGraphics();
        graphics.setColor(255, 0, 0);
        graphics.fillArc(10, 10, 60, 50, 180, 180);
    }
    protected void paint(Graphics graphics) 
    {
         graphics.setColor(255, 255, 255);
         graphics.fillRect(0, 0, getWidth(), getHeight());
         graphics.drawImage(img, 30, 30, Graphics.VCENTER | Graphics.HCENTER);
    }
    
    public void commandAction(Command command, Displayable dis) 
    {
    if (command == cmd) 
    {
    MI.exitMIDlet();
    }
    }
    }

Similar Threads

  1. Segment an image in java
    By Logan 2 in forum Software Development
    Replies: 7
    Last Post: 19-04-2010, 12:15 AM
  2. What is mutable and immutable Strings
    By Bottlenecked in forum Software Development
    Replies: 5
    Last Post: 03-02-2010, 01:05 PM
  3. Image Display In Java
    By Amaresh in forum Software Development
    Replies: 5
    Last Post: 30-01-2010, 09:20 AM
  4. GUI image program java
    By Caden Fernandes in forum Software Development
    Replies: 3
    Last Post: 12-11-2009, 11:48 AM
  5. Mirror image in Java
    By Soft Pack in forum Software Development
    Replies: 1
    Last Post: 18-12-2008, 07:34 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,041,434.57544 seconds with 16 queries