📄 testapplet.java_
字号:
package eatbean.util.algorithm;import java.awt.*;import java.awt.event.*;import java.applet.*;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2002</p> * <p>Company: </p> * @author unascribed * @version 1.0 */public class TestApplet extends Applet { private int[][] map = { { 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 1, 0, 0, 0, 0, 0 }, { 0, 1, 0, 1, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 1, 1, 0, 0, 0 }, { 0, 1, 0, 1, 1, 1, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 1, 0, 1, 0, 0, 0 }, { 0, 1, 0, 1, 1, 1, 1, 0, 0 }, { 0, 1, 0, 1, 0, 0, 1, 1, 1 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 1, 1, 1, 0, 0 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 1, 1, 1, 1, 1, 1 }, { 0, 1, 0, 0, 0, 0, 0, 0, 0 }, { 0, 1, 0, 1, 0, 1, 0, 0, 0 }, }; private final int SPACE = 20; private Node path = null; boolean isStandalone = false; Button button1 = new Button(); //Get a parameter value public String getParameter(String key, String def) { return isStandalone ? System.getProperty(key, def) : (getParameter(key) != null ? getParameter(key) : def); } //Construct the applet public TestApplet() { } //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { button1.setLabel("button1"); button1.setBounds(new Rectangle(223, 10, 65, 39)); button1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { button1_actionPerformed(e); } }); this.setLayout(null); this.add(button1, null); } //Start the applet public void start() { } //Stop the applet public void stop() { } //Destroy the applet public void destroy() { } //Get Applet information public String getAppletInfo() { return "Applet Information"; } //Get parameter info public String[][] getParameterInfo() { return null; } public void paint(Graphics g) { drawMatrix(g); drawPath(g); } private void drawMatrix(Graphics g) { int x, y; for(y = 0; y < map.length; y++) for(x = 0; x < map[0].length; x++) { g.drawString(Integer.toString(map[y][x]), SPACE+x*SPACE, SPACE+y*SPACE); } x = map[0].length; y = map.length; for(int xx = 0; xx < x; xx++) g.drawString("_"+xx, SPACE+xx*SPACE, SPACE+y*SPACE); for(int yy = 0; yy < y; yy++) g.drawString("|"+yy, SPACE+x*SPACE, SPACE+yy*SPACE); } private void drawPath(Graphics g) { if(path == null) System.out.println("path == null"); Node tmp = path; while(tmp != null) { g.drawString("■", SPACE+tmp.x*SPACE, SPACE+tmp.y*SPACE); //System.out.println(tmp); tmp = tmp.parent; } } void button1_actionPerformed(ActionEvent e) { System.out.println("Triger ActionPerform Event"); PathFinder pathFinder = new PathFinder(map, 0); Node sNode = new Node(0, 0); Node eNode = new Node(8, 15); path = pathFinder.findPath(sNode, eNode); this.repaint(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -