"Peng" last book said, the Java game map construction is an extremely simple thing, this book to connect the previous article, explore the role of the game in the mobile problem.
As we all know, [role] is the soul of a game, there is no role in the game, is no soul of the game.
So, how to let this important role [move] up.
Now "The ROC" first demonstrated a simple example, thinking of the use of the.
file Example2.java
package Org.loon.chair.example2;
import Java.awt.Container;
import javax.swing.JFrame;
/**
*
* @author Chenpeng
*
* Loon Framework in Game
*
*/
Public class Example2 extends JFrame {
Public Example2 () {
The default form name
Settitle ("movement and limitation of roles in Example2[java game");
Get an example of our custom panel [map Panel]
Mypanel panel = new mypanel ();
Container ContentPane = Getcontentpane ();
Contentpane.add (panel);
Execute and build the form setup
Pack ();
}
Public Static void Main (string[] args) {
Example2 e1 = new Example2 ();
Set Allow form close operation
E1.setdefaultcloseoperation (Jframe.exit_on_close);
Show form
E1.setvisible (true);
}
}
file Mypanel.java
package Org.loon.chair.example2;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import Java.awt.event.KeyListener;
import Javax.swing.ImageIcon;
import Javax.swing.JPanel;
/**
* Custom panel in Example1 to depict the underlying map.
*
* @author Chenpeng
*
* Loon Framework in Game
*
* PS: Please note that this is different from the previous precedent, new keyboard event monitoring
*/
Public class Mypanel extends JPanel implements KeyListener {
Width and height of the form