java - How to add a ball into my maze that I can move? -
i have maze , gui here seems have gone wrong, objective make grid 13 x 16 , have ball can controlled either arrow keys on keyboard or on gui, @ stage not matter which.
for reason maze hasn't formed can see here -
it supposed
my code follows:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class cballmaze extends jframe implements actionlistener { //below have declared different objects have used throughout program private jbutton buttonright, buttonleft, buttonup, buttondown, buttontl, buttontr, buttonbl, buttonbr, buttoncenter, optionone, optiontwo, optionthree, optionexit, scenarioact, scenariorun, scenarioreset, compassph; private jbutton [] game = new jbutton [208]; private jpanel panelcentre, panelright, panelbottom, buttonpanel, compasspanel, optionspanel, selectionpanel, panelact, panelrun, panelreset, panelslider; private jtextfield optiontf, squaretf, directiontf; private jlabel option, square, direction, compassdirection; private jslider speedslider; private string firstoption = "1", secondoption = "2", thirdoption = "3", updirection = "north", rightdirection = "east", downdirection = "south", leftdirection = "west"; private int i; private int[] map = new int[] { 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2, 3,1,3,3,3,1,3,3,3,1,3,3,3,3,3,3, 3,1,3,3,3,1,3,3,3,1,3,3,3,3,3,3, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 3,3,1,3,3,3,1,3,3,3,3,1,3,3,3,3, 3,3,1,3,3,3,1,3,3,3,3,1,3,3,3,3, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 3,1,3,3,3,1,3,3,3,1,3,3,3,3,3,3, 3,1,3,3,3,1,3,3,3,1,3,3,3,3,3,3, 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, 3,3,1,3,3,3,1,3,3,3,3,1,3,3,3,3, 3,3,1,3,3,3,1,3,3,3,3,1,3,3,3,3, 4,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, };
and
try { iconsand = new imageicon("sand.jpg"); } catch (exception e) { system.err.println("sand icon "+e); } try { iconball = new imageicon("sand60x60.png"); } catch (exception e) { system.err.println("ball icon "+e); } try { iconwhite = new imageicon("white32x32.jpg"); } catch (exception e) { system.err.println("white icon "+e); } try { iconend = new imageicon("sandstone.jpg"); } catch (exception e) { system.err.println("end icon"+e); } (i=0;i<208;i++) { game[i] = new jbutton (); if(map[i]==1) { game[i].seticon(iconsand); } if(map[i]==2) { game[i].seticon(iconball); } if(map[i]==3) { game[i].seticon(iconwhite); } if(map[i]==4) { game[i].seticon(iconend); } game[i].setborder(null); game[i].setpreferredsize(new dimension(32, 32)); game[i].addactionlistener(this); panelcentre.add(game[i]);
thanks help! here code panel center:
setdefaultcloseoperation(exit_on_close); container window = getcontentpane(); window.setlayout(new borderlayout() ); //panels panelcentre = new jpanel(); panelcentre.setpreferredsize(new dimension(625, 450)); panelcentre.setbackground(color.black); window.add(panelcentre); panelcentre.setlayout(new gridlayout(21, 30));
Comments
Post a Comment