MYSTERY ZILLION တွင် English သို့မဟုတ် Unicode ဖြင့်သာ အသုံးပြုခွင့်ရှိသည်။ ဇော်ဂျီ ၊ ဧရာ စသည်တို့ကို အသုံးပြုခွင့် မရှိ။ Unicode fonts များမှာ Mon3,Yunghkio, Myanamr3 စသည်များ အသုံးပြုနိုင်သည်။ Unicode Guide ကို ဒီမှာ Download ချပါ။ Zawgyi to Unicode Converter
Don't share ebook or software if nobody request. You can find free book websites on here. We are welcome for discussion or asking question instead.

java နဲ့ animation image လေး ရေးချင်တယ်

edited December 2010 in Java
java နဲ့ animation image လေး ရေးချင်တယ် ။

ရေးတတ်သောသူများ source code နဲ့ အတူ ရှင်းပြပေးပါလား ခင်ဗျား ။

bitmap , gif , jpeg တို့ကို သုံးပြီး applet မှာ display လုပ်လို့ ရတယ် ။
ပြီးတော့ animation images လေးတွေ ဖန်တီးလို့ ရတယ် နော် ။

ကျွန်တော် getImage(url) ကို သုံးပြီး java applet မှာ ဖွင့်ကြည့်တာ အဆင်ပြေပါတယ် ။
ဒါပေမယ့် animation ကို မရေးတတ်ဘူး ဖြစ်နေတယ် ။

Example :

1:import java.awt.Graphics;
2:import java.awt.Image;
3:
4:public class LadyBug extends java.applet.Applet {
5:
6: Image bugimg;
7:
8: public void init() {
9: bugimg = getImage(getCodeBase(),
10: "images/ladybug.gif");
11: }
12:
13: public void paint(Graphics g) {
14: g.drawImage(bugimg, 10, 10,this);
15: }
16:}


ဒိ example မှာ ladybug image ကို bugimg က hold လုပ်ထားတယ် ။

init() method က load လုပ်ပေးတယ် ။

paint() method ကတော့ screen တွင် image ပေါ်စေရန် draw လုပ်ပေးတယ်ပေါ့ ။

ဒီလောက် အထိကတော့ အဆင်ပြေနေပါတယ် ။

သိချင်တာက ဒီမှာ :

drawImage() က draw လုပ်ဖို့ ၊ x နဲ့ y , width နဲ့ height , ပြီးတော့ image bounding အတွက် အလုပ်လုပ်တယ်ပြောတယ် ။

positioning , setBound() တို့ကို သေချာသိချင်ပါသည် ။

animation image ရေးနည်းလေးလည်း သိချင်ပါသည် ။

မှတ်ချက်များ

  • edited May 2011 Registered Users
    Java နဲ့ Animation ရေးချင်သပဆိုရင်တော့
    Thread နဲ့ Array ကိုရေးနိုင်ဖို့လိုမယ်နော်။ code နမူနာကြည့်ကြည့်
    <pre lang="java">
    import java.awt.Image;import java.util.ArrayList;/** The
    Animation class manages a series of images (frames) and the
    amount of time to display each frame.*/public class Animation {
    private ArrayList frames; private int currFrameIndex; private
    long animTime; private long totalDuration; /** Creates a new,
    empty Animation. */ public Animation() { frames = new
    ArrayList(); totalDuration = 0; start(); } /** Adds an image to
    the animation with the specified duration (time to display the
    image). */ public synchronized void addFrame(Image image, long
    duration) { totalDuration += duration; frames.add(new
    AnimFrame(image, totalDuration)); } /** Starts this animation
    over from the beginning. */ public synchronized void start() {
    animTime = 0; currFrameIndex = 0; } /** Updates this animation's
    current image (frame), if necessary. */ public synchronized void
    update(long elapsedTime) { if (frames.size() > 1) { animTime +=
    elapsedTime; if (animTime >= totalDuration) { animTime = animTime
    % totalDuration; currFrameIndex = 0; } while (animTime >
    getFrame(currFrameIndex).endTime) { currFrameIndex++; } } } /**
    Gets this Animation's current image. Returns null if this
    animation has no images. */ public synchronized Image getImage()
    { if (frames.size() == 0) { return null; } else { return
    getFrame(currFrameIndex).image; } } private AnimFrame
    getFrame(int i) { return (AnimFrame)frames.get(i); } private
    class AnimFrame { Image image; long endTime; public
    AnimFrame(Image image, long endTime) { this.image = image;
    this.endTime = endTime; } }}
    </pre>
  • edited May 2011 Registered Users
    အပေါ်က Animation class ကို ဟောဒါလေးနဲ့ run ကြည့်ဗျာ
    image file နေရာမှာတော့ ကိုယ့် image ရှိတဲ့ path ကိုသေချာထည့်ပေးဖို့တော့လိုမယ်နော်
    <pre lang="java">
    import java.awt.*;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;

    public class AnimationTest1 {

    public static void main(String args[]) {

    DisplayMode displayMode;

    if (args.length == 3) {
    displayMode = new DisplayMode(
    Integer.parseInt(args[0]),
    Integer.parseInt(args[1]),
    Integer.parseInt(args[2]),
    DisplayMode.REFRESH_RATE_UNKNOWN);
    }
    else {
    displayMode = new DisplayMode(800, 600, 16,
    DisplayMode.REFRESH_RATE_UNKNOWN);
    }

    AnimationTest1 test = new AnimationTest1();
    test.run(displayMode);
    }

    private static final long DEMO_TIME = 5000;

    private SimpleScreenManager screen;
    private Image bgImage;
    private Animation anim;

    public void loadImages() {
    // load images
    bgImage = loadImage("images/background.jpg");
    Image player1 = loadImage("images/player1.png");
    Image player2 = loadImage("images/player2.png");
    Image player3 = loadImage("images/player3.png");

    // create animation
    anim = new Animation();
    anim.addFrame(player1, 250);
    anim.addFrame(player2, 150);
    anim.addFrame(player1, 150);
    anim.addFrame(player2, 150);
    anim.addFrame(player3, 200);
    anim.addFrame(player2, 150);
    }


    private Image loadImage(String fileName) {
    return new ImageIcon(fileName).getImage();
    }


    public void run(DisplayMode displayMode) {
    screen = new SimpleScreenManager();
    try {
    screen.setFullScreen(displayMode, new JFrame());
    loadImages();
    animationLoop();
    }
    finally {
    screen.restoreScreen();
    }
    }


    public void animationLoop() {
    long startTime = System.currentTimeMillis();
    long currTime = startTime;
    while (currTime - startTime < DEMO_TIME) {
    long elapsedTime =
    System.currentTimeMillis() - currTime;
    currTime += elapsedTime;

    // update animation
    anim.update(elapsedTime);

    // draw to screen
    Graphics g =
    screen.getFullScreenWindow().getGraphics();
    draw(g);
    g.dispose();

    // take a nap
    try {
    Thread.sleep(20);
    }
    catch (InterruptedException ex) { }
    }

    }


    public void draw(Graphics g) {
    // draw background
    g.drawImage(bgImage, 0, 0, null);

    // draw image
    g.drawImage(anim.getImage(), 0, 0, null);
    }

    }</pre>
  • edited May 2011 Registered Users
    can't run . don't have "SimpleScreenManager.java" .If possible, pls post that file.Thank in advance to JPro.Zack
  • edited May 2011 Registered Users
    <pre lang="java">
    import java.awt.*;
    import javax.swing.JFrame;

    /**
    The SimpleScreenManager class manages initializing and
    displaying full screen graphics modes.
    */
    public class SimpleScreenManager {

    private GraphicsDevice device;

    /**
    Creates a new SimpleScreenManager object.
    */
    public SimpleScreenManager() {
    GraphicsEnvironment environment =
    GraphicsEnvironment.getLocalGraphicsEnvironment();
    device = environment.getDefaultScreenDevice();
    }


    /**
    Enters full screen mode and changes the display mode.
    */
    public void setFullScreen(DisplayMode displayMode, JFrame window)
    {
    window.setUndecorated(true);
    window.setResizable(false);

    device.setFullScreenWindow(window);
    if (displayMode != null &&
    device.isDisplayChangeSupported())
    {
    try{
    device.setDisplayMode(displayMode);
    }
    catch (IllegalArgumentException ex) {
    // ignore - illegal mode for this device
    }
    }
    }


    /**
    Returns the window currently used in full screen mode.
    */
    public Window getFullScreenWindow() {
    return device.getFullScreenWindow();
    }


    /**
    Restores the screen's display mode.
    */
    public void restoreScreen() {
    Window window = device.getFullScreenWindow();
    if (window != null) {
    window.dispose();
    }
    device.setFullScreenWindow(null);
    }

    }
    </pre>
Sign In or Register to comment.