ÔÆÌ⺣ - רҵÎÄÕ·¶ÀýÎĵµ×ÊÁÏ·ÖÏíÆ½Ì¨

µ±Ç°Î»ÖãºÊ×Ò³ > ¡¶JavaÓïÑԿγÌÉè¼Æ¡·ÂÛÎÄÄ£°å

¡¶JavaÓïÑԿγÌÉè¼Æ¡·ÂÛÎÄÄ£°å

  • 62 ´ÎÔĶÁ
  • 3 ´ÎÏÂÔØ
  • 2025/7/6 3:25:49

±¾¿Æ¿Î³ÌÉè¼ÆÂÛÎÄ

this.setTitle(\ÀÏÏİæÌ°³ÔÉßСÓÎÏ·\ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(null); this.setResizable(false); int left = 10; optionPanel = new GameOptionPanel(); gamePanel = c.getGamePanel(); snake = c.getSnake(); ground = c.getGround(); food = c.getFood(); infoLabel = c.getGameInfoLabel() == null ? new JLabel() : c .getGameInfoLabel(); c.setGameInfoLabel(infoLabel); optionPanel.getButton_griddingColor().addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { Color griddingColor = JColorChooser.showDialog( MainFrame.this, \ÇëÑ¡ÔñÍø¸ñµÄÑÕÉ«\Color.LIGHT_GRAY); if (griddingColor != null) ground.setGriddingColor(griddingColor); } }); optionPanel.getButton_backgroundColor().addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { Color backgroundColor = JColorChooser .showDialog(MainFrame.this, \ÇëÑ¡Ôñ±³¾°µÄÑÕÉ«\ new Color(0xcfcfcf)); if (backgroundColor != null) gamePanel.setBackgroundColor(backgroundColor); } }); optionPanel.getButton_foodColor().addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { Color foodColor = JColorChooser.showDialog( MainFrame.this, \ÇëÑ¡ÔñʳÎïµÄÑÕÉ«\Color.DARK_GRAY); if (foodColor != null)

37

±¾¿Æ¿Î³ÌÉè¼ÆÂÛÎÄ

food.setColor(foodColor); } }); optionPanel.getButton_headColor().addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { Color headColor = JColorChooser .showDialog(MainFrame.this, \ÇëÑ¡ÔñÉßÍ·µÄÑÕÉ«\ new Color(0xFF4500)); if (headColor != null) snake.setHeadColor(headColor); } }); optionPanel.getButton_bodyColor().addActionListener( new ActionListener() { public void actionPerformed(ActionEvent arg0) { Color bodyColor = JColorChooser.showDialog( MainFrame.this, \ÇëÑ¡ÔñÉßÉíÌåµÄÑÕÉ«\Color.DARK_GRAY); if (bodyColor != null) snake.setBodyColor(bodyColor); } }); this.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent arg0) { controller.pauseGame(); if (optionPanel.getPauseButton().isEnabled()) optionPanel.getPauseButton().setText(\¼ÌÐøÓÎÏ·\ } }); gamePanel.addFocusListener(new FocusAdapter() { public void focusGained(FocusEvent arg0) { // controller.continueGame(); } public void focusLost(FocusEvent arg0) { controller.pauseGame(); if (optionPanel.getPauseButton().isEnabled()) optionPanel.getPauseButton().setText(\¼ÌÐøÓÎÏ·\ } });

38

±¾¿Æ¿Î³ÌÉè¼ÆÂÛÎÄ

optionPanel.getRadioButton_map2().addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent e) { controller.setMap(optionPanel.getRadioButton_map2() .isSelected() ? 2 : 1); } }); optionPanel.getNewGameButton().addActionListener(new ActionListener() { /** * ¿ªÊ¼ÓÎÏ·µÄ°´Å¥ */ public void actionPerformed(ActionEvent e) {

// TODO Auto-generated method stub if (controller.isPlaying()) { return; }

controller.newGame(); } });

optionPanel.getStopGameButton().addActionListener(new ActionListener() { /** * Í£Ö¹ÓÎÏ·µÄ°´Å¥ */ public void actionPerformed(ActionEvent e) { controller.stopGame(); } });

optionPanel.getPauseButton().setEnabled(false); optionPanel.getStopGameButton().setEnabled(false);

optionPanel.getPauseButton().addActionListener(new ActionListener() { /** * ÔÝÍ£/¼ÌÐøÓÎÏ·µÄ°´Å¥ */ public void actionPerformed(ActionEvent e) { if (controller.isPausingGame()) { controller.continueGame();

39

±¾¿Æ¿Î³ÌÉè¼ÆÂÛÎÄ

} else { controller.pauseGame(); } if (controller.isPausingGame()) optionPanel.getPauseButton().setText(\¼ÌÐøÓÎÏ·\ else optionPanel.getPauseButton().setText(\ÔÝÍ£ÓÎÏ·\ } });

optionPanel.getCheckBox_drawGridding().addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent arg0) { optionPanel.getButton_griddingColor().setVisible( optionPanel.getCheckBox_drawGridding() .isSelected()); ground.setDrawGridding(optionPanel .getCheckBox_drawGridding().isSelected()); } }); optionPanel.getButton_default().addActionListener(new ActionListener() { /** * »Ö¸´Ä¬ÈÏÉèÖõİ´Å¥ */ public void actionPerformed(ActionEvent e) {

gamePanel

.setBackgroundColor(GamePanel.DEFAULT_BACKGROUND_COLOR); optionPanel.getCheckBox_drawGridding().setSelected(false); ground.setGriddingColor(Ground.DEFAULT_GRIDDING_COLOR); snake.setHeadColor(Snake.DEFAULT_HEAD_COLOR); snake.setBodyColor(Snake.DEFAULT_BODY_COLOR); optionPanel.getRadioButton_map1().setSelected(true);

} });

infoLabel.setBounds(10, 0, infoLabel.getSize().width - 10, infoLabel .getSize().height);

gamePanel.setBounds(0, infoLabel.getSize().height, gamePanel.getSize().width, gamePanel.getSize().height); JPanel subPanel = new JPanel(); subPanel.setLayout(null);

40

ËÑË÷¸ü¶à¹ØÓÚ£º ¡¶JavaÓïÑԿγÌÉè¼Æ¡·ÂÛÎÄÄ£°å µÄÎĵµ
  • ÊÕ²Ø
  • Î¥¹æ¾Ù±¨
  • °æÈ¨ÈÏÁì
ÏÂÔØÎĵµ10.00 Ôª ¼ÓÈëVIPÃâ·ÑÏÂÔØ
ÍÆ¼öÏÂÔØ
±¾ÎÄ×÷Õߣº...

¹²·ÖÏí92ƪÏà¹ØÎĵµ

Îĵµ¼ò½é£º

±¾¿Æ¿Î³ÌÉè¼ÆÂÛÎÄ this.setTitle(\ÀÏÏİæÌ°³ÔÉßСÓÎÏ·\ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setLayout(null); this.setResizable(false); int left = 10; optionPanel = new GameOptionPanel(); gamePanel = c.getGamePanel(); snake = c.getSnake(); ground = c.getGround(); food = c.getFood(); infoLabel = c.getGameInfoLabel() == null ? new JLabel() : c

¡Á ÓοͿì½ÝÏÂÔØÍ¨µÀ£¨ÏÂÔØºó¿ÉÒÔ×ÔÓɸ´ÖƺÍÅŰ棩
µ¥Æª¸¶·ÑÏÂÔØ
ÏÞÊ±ÌØ¼Û£º10 Ôª/·Ý Ô­¼Û:20Ôª
VIP°üÔÂÏÂÔØ
ÌØ¼Û£º29 Ôª/Ô ԭ¼Û:99Ôª
µÍÖÁ 0.3 Ôª/·Ý ÿÔÂÏÂÔØ150·Ý
ȫվÄÚÈÝÃâ·Ñ×ÔÓɸ´ÖÆ
VIP°üÔÂÏÂÔØ
ÌØ¼Û£º29 Ôª/Ô ԭ¼Û:99Ôª
µÍÖÁ 0.3 Ôª/·Ý ÿÔÂÏÂÔØ150·Ý
ȫվÄÚÈÝÃâ·Ñ×ÔÓɸ´ÖÆ
×¢£ºÏÂÔØÎĵµÓпÉÄÜ¡°Ö»ÓÐĿ¼»òÕßÄÚÈݲ»È«¡±µÈÇé¿ö£¬ÇëÏÂÔØÖ®Ç°×¢Òâ±æ±ð£¬Èç¹ûÄúÒѸ¶·ÑÇÒÎÞ·¨ÏÂÔØ»òÄÚÈÝÓÐÎÊÌ⣬ÇëÁªÏµÎÒÃÇЭÖúÄã´¦Àí¡£
΢ÐÅ£ºfanwen365 QQ£º370150219
Copyright © ÔÆÌ⺣ All Rights Reserved. ËÕICP±¸16052595ºÅ-3 ÍøÕ¾µØÍ¼ ¿Í·þQQ£º370150219 ÓÊÏ䣺370150219@qq.com