A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

  1. 先第一种,为了解题而解题。

  2. ==== Main.java ====
  3. public class Main {
  4. private double TotalHeight = 100;
  5. private double CurHeight = 50;

  6. public void drop(int times) {
  7. if ((times - 1) == 0) {
  8. return;
  9. }

  10. setTotalHeight(getTotalHeight() + 2 * getCurHeight());
  11. setCurHeight(getCurHeight() / 2);

  12. drop(times - 1);
  13. }

  14. public double getTotalHeight() {
  15. return TotalHeight;
  16. }

  17. public void setTotalHeight(double totalHeight) {
  18. TotalHeight = totalHeight;
  19. }

  20. public double getCurHeight() {
  21. return CurHeight;
  22. }

  23. public void setCurHeight(double curHeight) {
  24. CurHeight = curHeight;
  25. }

  26. public static void main(String[] args) {
  27. Main main = new Main();
  28. main.drop(2);
  29. System.out.println("Total height is " + main.getTotalHeight());
  30. System.out.println("Current height is " + main.getCurHeight());
  31. }
  32. }

  33. ==== 然后是第二种 =====

  34. ==== Main.java ====
  35. package main;

  36. import javax.swing.JFrame;

  37. import panel.BallPanel;
  38. import time.Delay;

  39. public class MainFrame extends JFrame {
  40. public MainFrame(String title) {
  41. super(title);
  42. }

  43. public static void main(String[] args) {
  44. Delay delay = new Delay();

  45. MainFrame frame = new MainFrame("Hello JFrame");
  46. BallPanel ballPanel = new BallPanel();
  47. frame.add(ballPanel);
  48. frame.setSize(500, 500);
  49. frame.setVisible(true);
  50. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  51. delay.initDelay();

  52. ballPanel.setDelay(delay.getDelay());
  53. ballPanel.loopDrop(0);
  54. }
  55. }
复制代码


0 个回复

您需要登录后才可以回帖 登录 | 加入黑马