Get the App
SLTechnology News&Howtos  ›  Development  › 

How to realize the billiard game with java

Shulou Source: shulou.com Published: 2022-06-03 20:02:14 10月01日 Update

This article mainly explains "how to realize the billiard game with java". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how to realize the billiard game with java".

Thinking

1 window loading creates a window 2 to display pictures in the window, in order (desktop, ball) otherwise it will be overwritten. 3. Change the XBI y of the ball and refresh the window

Ecipse

1. New folder established at the same level of src

New- > folder---- > image (filename) the picture is directly cpoy from the outside and copied on the filename

two。 The following direct complete code comments are all in it

Package day01;import java.awt.*; / / Guide package import javax.swing.*;// guide package public class BallGame extends JFrame {/ * inherits JFrame*/ Image ball=Toolkit.getDefaultToolkit (). GetImage ("image/ball.png"); Image desk=Toolkit.getDefaultToolkit (). GetImage ("image/desk.jpg"); double x windows 100; double yballs 100; boolean right=true; / / methods for drawing desktop windows public void paint (Graphics g) {/ / System.out.println ("once"); g.drawImage (desk, 0,0, null) G.drawImage (ball, (int) x, (int) y, null); / / right x diameter 1; if (right) x diameter 10; else x color 10; if (x > 856-40-30) / / seat frame and ball diameter right=false; if (x500-40-30) | | y

Tags: Billiards method code entry content picture file name desktop diameter program learning practical deeper up and down sequence interest function peer utility Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information MySQL Microsoft Shulou Technology Apple