这段代码的意思是什么,需要保证…Java基础知识

这段代码的意思是什么,需要保证…Java基础知识,java,Java,大家好,这对你们中的大多数人来说可能很容易,但我今天在课堂上得到了要分析的代码,我刚开始学习Java,我想知道是否有人可以告诉我其他代码的意思,我真的不明白。不过,我确实理解我在某些地方做了标记 **I have no clue about this following statement** public class PONG extends JComponent implements ActionListener, MouseMotionListener, KeyListener {

大家好,这对你们中的大多数人来说可能很容易,但我今天在课堂上得到了要分析的代码,我刚开始学习Java,我想知道是否有人可以告诉我其他代码的意思,我真的不明白。不过,我确实理解我在某些地方做了标记

   **I have no clue about this following statement**

public class PONG extends JComponent implements ActionListener, MouseMotionListener, KeyListener {

    **are these the initial values?**


    private static final long serialVersionUID = 1L;
            private int scorefinal;
            private int ballx = 150;
            private int bally = 30;
            private int ballx1 = 100;
            private int bally1 = 10;
            private int paddlex = 0;
            private int ballySpeed = 7;
            private int ballxSpeed = 5;
            private int bally1Speed = 14;
            private int ballx1Speed = 10;

            public int score = 0;
            public int score1 = 0;
            public int bestscore;
            public int bestscore1;
            public boolean gameOver, started;
        **Is this saying how fast the ball moves?**


Timer tt = new Timer(10, g);
        tt.start();

        }
    **I do not know the following block of code**
        public void newball(int ballx, int bally, int ballxspeed, int       ballyspeed) {

            ballx = 150; 
            bally = 30;
            ballxspeed = 5;
            ballyspeed = 7;
            return;
        }
            **So how is the scoring calculated?**   
            if (score >= 5) {
                g.setColor(Color.red);
                g.setFont(new Font("Arial", 8, 50));
                g.drawString(String.valueOf(score + score1), 30 / 1 - 15, 80);
            } else {
                g.setColor(Color.white);
                g.setFont(new Font("Arial", 8, 50));
                g.drawString(String.valueOf(score), 30 / 1 - 15, 80);
            }
            // start && gameOver
            g.setColor(Color.white);
            g.setFont(new Font("Arial", 8, 50));

            if (gameOver) {
    **I do not understand the 50/ 1-15, 200**
                g.drawString(String.valueOf(" Best Score :" + scorefinal), 50 / 1 - 15, 200);

            }
        }


        public void actionPerformed(ActionEvent e) {

            ballx = ballx + ballxSpeed;
            bally = bally + ballySpeed;


**I think these are the boundaries but i am not entirely sure
            // Window Down 
            if (ballx >= paddlex && ballx <= paddlex + 100 && bally >= 475) {

                ballySpeed = -7;
                score++;

            }

            if (bally >= 700 ) {

                score = 0;
                bally = 30;
                gameOver = true;

            }

            // Window up
            if (bally <= 0) {

                ballySpeed = 7;

            }

            // Window right
            if (ballx >= 775) {

                ballxSpeed = -5;

            }

            // Window left
            if (ballx <= 0) {

                ballxSpeed = 5;

            }

            //i do not know what this means
            ballx1 = ballx1 + ballx1Speed;
            bally1 = bally1 + bally1Speed;

            // Window down
            if (ballx1 >= paddlex && ballx1 <= paddlex + 100 && bally1 >= 475) {

                bally1Speed = -14;
                score1++;

            }

            if (bally1 >= 700) {

                score1 = 0;
                bally1 = 10;


            }

            // Window up
            if (bally1 <= 0) {

                bally1Speed = 14;

            }

            // Window right
            if (ballx1 >= 775) {

                ballx1Speed = -10;

            }

            // Window left
            if (ballx1 <= 0) {

                ballx1Speed = 10;

            }


        **/i understand this has something to do with mouse events but i dont get the -50 part, and what is the overrides mean**
        public void mouseMoved(MouseEvent e) {

            paddlex = e.getX() - 50;
            repaint();
        }

        @Override
        public void mouseDragged(MouseEvent e) {
        }

        @Override
        public void keyTyped(KeyEvent e) {

        }

        @Override
        public void keyPressed(KeyEvent e) {

        }

        @Override
        public void keyReleased(KeyEvent e) {
**我对下面这句话一无所知**
公共类PONG扩展JComponent实现ActionListener、MouseMotionListener、KeyListener{
**这些是初始值吗**
私有静态最终长serialVersionUID=1L;
私人决赛;
私人int ballx=150;
私人int bally=30;
私人int ballx1=100;
私人int bally1=10;
私有整数x=0;
私用int-ballySpeed=7;
私人int ballxSpeed=5;
私人速度=14;
私人速度=10;
公共智力得分=0;
公共int评分1=0;
公众智力最佳分数;
公众智力最佳成绩1分;
公共布尔游戏结束,开始;
**这是说球移动有多快**
定时器tt=新定时器(10,g);
tt.start();
}
**我不知道下面的代码块**
公共无效新球(int-ballx、int-bally、int-ballxspeed、int-ballyspeed){
ballx=150;
bally=30;
球速=5;
ballyspeed=7;
返回;
}
**那么分数是如何计算的?**
如果(分数>=5){
g、 setColor(Color.red);
g、 setFont(新字体(“Arial”,8,50));
g、 抽绳(字符串值(分数+分数1),30/1-15,80);
}否则{
g、 setColor(Color.white);
g、 setFont(新字体(“Arial”,8,50));
g、 抽绳(弦.值(分数),30/1-15,80);
}
//开始游戏(&G)
g、 setColor(Color.white);
g、 setFont(新字体(“Arial”,8,50));
如果(游戏结束){
**我不明白50/1-15200**
g、 抽绳(String.valueOf(“最佳分数:+scorefinal”),50/1-15200;
}
}
已执行的公共无效操作(操作事件e){
ballx=ballx+ballx速度;
巴利=巴利+巴利速度;
**我认为这是界限,但我不能完全确定
//窗口关闭
如果(ballx>=桨叶x&&ballx=475){
ballySpeed=-7;
分数++;
}
如果(巴利>=700){
得分=0;
bally=30;
gameOver=true;
}
//开窗
如果(巴利=775){
球速=-5;
}
//左窗
如果(ballx=ballx&&ballx1=475){
速度=-14;
分数1++;
}
如果(球1>=700){
得分1=0;
bally1=10;
}
//开窗
如果(bally1=775){
球速=-10;
}
//左窗

if(ballx1@Override意味着在您的例子“JComponent”中,来自已实现类或“Super类”的代码将被实现其方法的子类覆盖。您的PONG类将方法拉入并更改它需要从Super类更改以实现其目标的方法

无论是否更改,所有方法都需要重写

导入是项目依赖项


main方法是程序的开始;代码由计算机从JFrame的实例化开始逐行执行,直到计时器过期并结束程序。

如果只有少数代码您不懂,请不要发布200行不相关的代码。更改标题以反映您不懂的代码站起来,说出你不理解的地方。在你的问题主体中也这样做。投票结束,因为现在还不清楚。你不理解的部分是什么?如果你想得到具体的答案和帮助,那么请提出具体的问题。我已经添加了以**开头的具体部分/问题,感谢你的反馈。看起来你是不理解它的全部代码,而不仅仅是某些部分。拿一本书来研究-这是我的建议非常感谢你,这有助于澄清一些事情!没问题。只是一个提示;如果你的问题是具体的,你得到的答案将更有帮助。