@@ -31,6 +31,8 @@ The robot character (an ant) should find its way from the start point (home) to
3131import java .awt .Image ;
3232import java .awt .event .ActionEvent ;
3333import java .awt .event .ActionListener ;
34+ import java .awt .event .ComponentAdapter ;
35+ import java .awt .event .ComponentEvent ;
3436import java .awt .event .MouseEvent ;
3537import java .awt .event .MouseListener ;
3638import java .awt .event .MouseMotionListener ;
@@ -113,7 +115,7 @@ public class Game extends JPanel implements MouseListener, MouseMotionListener {
113115 public Game (JFrame frame ) {
114116
115117 // change the color if needed
116-
118+
117119 bgColor = new Color (234 , 242 , 255 ,(int ) (0.7 * 255 )); // 0.7 is the opacity
118120 openTerrainColor = new Color (255 , 255 , 255 , (int ) (0.5 * 255 ));
119121 openTerrainBoarderColor = new Color (0 , 0 , 0 , (int ) (0.5 * 255 ));
@@ -134,13 +136,6 @@ public Game(JFrame frame) {
134136 buttonPanel = new JPanel ();
135137 buttonPanel .setLayout (new GridLayout (1 , buttonCount , 10 , 10 ));
136138
137- // set tile offset
138- int xOffset = (int ) ((frame .getWidth () - TILE_SIZE * NUM_COLS ) / 2 );
139- int yOffset = (int ) ((frame .getHeight () - TILE_SIZE * NUM_ROWS ) / 1.8 );
140-
141- Tile .setxOffset (xOffset );
142- Tile .setyOffset (yOffset );
143-
144139 //load all images
145140 loadImg ();
146141
@@ -167,32 +162,43 @@ public Game(JFrame frame) {
167162 iconSize = 20 ; // Define the size of your icons
168163 iconTextSpacing = 5 ; // Spacing between icon and text
169164 wordSpacing = 25 ; // Spacing between each icon-count pair
170-
171- terrainCountX = (int )(frame .getWidth ()/2.4 );
172- terrainCountY = frame .getHeight ()/15 ;
173165 iconScaling = 2.5 ;
174166
175- startTimer = false ;
176- startClicked = false ;
177- startTile = null ;
178- goalTile = null ;
179- startMovingAnt = false ;
180- noPath = false ;
181167 tobeDrawn = new LinkedList <Tile >();
182- obstacleCount = 0 ;
183- swamplandCount = 0 ;
184- grasslandCount = 0 ;
185- openTerrainCount = 0 ;
186168
187169 // set timer
188170 elapsedTimeStringBeforeSearch = "0:00:000" ;
189171 elapsedTimeStringAfterAnimation = "0:00:000" ;
190172 timerX = 100 ;
191173 timerY = frame .getHeight () - 100 ;
192-
193174
194175 setTimerMageCreation ();
195176 setTimerSolving ();
177+
178+ // resizeble windows
179+ resizeWindow ();
180+
181+ }
182+
183+ private void resizeWindow () {
184+ this .addComponentListener (new ComponentAdapter () {
185+ @ Override
186+ public void componentResized (ComponentEvent e ) {
187+
188+ // the top bar location
189+ terrainCountX = (int )(frame .getWidth ()/2.5 );
190+ terrainCountY = frame .getHeight ()/15 ;
191+
192+ // set the grid offset/start point
193+ int xOffset = (int ) ((frame .getWidth () - TILE_SIZE * NUM_COLS ) / 2 );
194+ int yOffset = (int ) ((frame .getHeight () - TILE_SIZE * NUM_ROWS ) / 1.8 );
195+
196+ Tile .setxOffset (xOffset );
197+ Tile .setyOffset (yOffset );
198+
199+ repaint ();
200+ }
201+ });
196202 }
197203
198204 private void loadImg () {
@@ -337,7 +343,7 @@ private void resetCameFrom(Tile[][] tiles) {
337343 }
338344
339345 private void selectGoalLocation () {
340- JButton result = new JButton ("Goal Location " );
346+ JButton result = new JButton ("Goal" );
341347 result .addActionListener (new ActionListener () {
342348 @ Override
343349 public void actionPerformed (ActionEvent e ) {
@@ -353,7 +359,7 @@ public void actionPerformed(ActionEvent e) {
353359 }
354360
355361 public void selectStartLocation () {
356- JButton result = new JButton ("Start Location " );
362+ JButton result = new JButton ("Start" );
357363 result .addActionListener (new ActionListener () {
358364 @ Override
359365 public void actionPerformed (ActionEvent e ) {
0 commit comments