Novice Small project-java tank Wars

Source: Internet
Author: User

1. Interface (graphical-front-end section)

    • Graphical use for interaction, whether it is in the form of text to the user choice, or graphic mode of choice is an interactive way. In Java if we need to use the graphical interface, we have to think of the GUI (Graphic user interface), then we need to use, we go directly to the API (graphical display allows us to finish the project to see the results comfortable, not all the code)
    • To do the GUI, it is necessary to think of the AWT in Java (Abstract Windows Toolkit), we need to use this class library to write graphics. Why is it called an abstract window? Because Java is a cross-platform, Java-written interface source program finally in the computer implementation may be finished by other languages. (AWT is originally intended to be platform-independent, meaning that the interface on any operating system is displayed on the long-width pattern will not change, to maintain aesthetics.) But AWT used something about the operating system when it was designed, and didn't do it completely across platforms. The operation of AWT is not used for Java virtual machines. But swing development is a Java virtual machine, it's completely cross-platform, so now it's swing, but its basic knowledge is AWT.
    • When it comes to AWT we need to understand the difference between component and container, see API. Component is everything that can be displayed, container inherits component, so container is also something to show, but container has a feature that can contain everything that is visible. So container can accommodate conponent, or it can accommodate itself. (Knowledge of the front-end engineer should also understand the difference between the container and the conponent system)

2. Writing Windows

  • We need to know what the window shows. Baidu search this little game, or on the small game site to play a few times can know the rules of the game http://www.7k7k.com/swf/129505.htm
  • We can see the game interface and game play method
  • Draw a window first, and the method we need to write a window can be copied in the frame class in case you write it wrong. We need the window: Black Bottom, the border can be changed with the drag, set the window size, the window is written above the Tankgame (total of four requirements)
  • In the Windows class we can find these methods: (1)setSize (int width, int height)(2)setvisible (Boolean b)
  • In the frame class we can find these methods: (1)Settitle (String title)(2)setresizable(boolean resizable) (3) setbackground (Color bgColor)
  • The program you are writing to (1) should go to the directory where the Java files are located. (2) Data type problem (see my Java data type)
  • 1 Importjava.awt.*;2  Public classTankgameextendsFrame {3    Public voidShowframe () {4 SetBackground (color.black);5Settitle ("Tankgame");6Setresizable (true);7SetVisible (true);8SetSize (514,450);9     Ten      One  A   } -  -  the    -    Public Static voidMain (string[] args) { -     -  +     Newtankgame (). Showframe (); -  +  A   } at   

  • Turning off this interface requires that you enter CTRL + C at the command line (no event handling, just like you created a thing for someone else, but you haven't been able to delete a thing for someone else, that fork is just an image, it doesn't make any sense, it's the same image as every image on the interface)

  • The coordinates of the computer screen start from the top left, the x-axis is up, the y-axis is facing down
  • But we are not satisfied with this window because the interface is different from what we see (e.g.)
  • So we need to use the panel (this container needs to be used with frame to show it) see container's Add method

  • We can get through panel methods (from container and component). Set size, background color, visible (1) setbackground (color C) (2)setSize (int width, int height) (3)setvisible (Boolean b)
  • The personal code is just a test, not exactly as required.
  • 1 Importjava.awt.*;2  Public classTankgameextendsFrame {3    Public voidShowframe () {4 SetBackground (color.black);5Settitle ("Tankgame");6Setresizable (true);7SetVisible (true);8SetSize (514,450);9     Ten      One  A   } -  -  the    -    Public Static voidMain (string[] args) { -     -  +Tankgame tankgame=Newtankgame (); - tankgame.showframe (); +Tankgametwo tankgametwo=Newtankgametwo (); A Tankgametwo.showpanel (); at Tankgame.add (tankgametwo); -      -  -   } -    -  in } -  classTankgametwoextendspanel{ to    voidShowpanel () { + SetBackground (color.orange); -SetSize (90,90); theSetVisible (true); *   } $ Panax Notoginseng    -  the}

  • If we follow this code, we'll find that we can't see the frame color at all, and the color we see is the panel color (if you sway the frame, the frame color will show)
  • Workaround call a method in a method in two classes (because by default there is a layout manager, we set the size to no use for them, so we need to set it manually, cancel the layout manager)
  • 1 Importjava.awt.*;2  Public classTankgameextendsFrame {3    Public voidShowframe () {4 SetBackground (color.gray);5Settitle ("Tankgame");6Setresizable (true);7SetVisible (true);8SetSize (514,450);9SetLayout (NULL);Ten      One      A  -   } -  the  -    -    Public Static voidMain (string[] args) { -     +  -Tankgame tankgame=Newtankgame (); + tankgame.showframe (); ATankgametwo tankgametwo=Newtankgametwo (); at Tankgametwo.showpanel (); - Tankgame.add (tankgametwo); -      -  -   } -    in  - } to  classTankgametwoextendspanel{ +    voidShowpanel () { - SetBackground (color.black); theSetSize (415,415); *SetVisible (true); $SetLayout (NULL);Panax Notoginseng   } -  the    +  A}

  • So how do you get the panel to move in the middle of the frame relative to the frames, with a method that sets X, Y, and size
  • The interface does a bit ugly, this need to spend a lot of adjustment, I have no tools to slowly adjust (or control the page on the game interface to set, screenshots will know the size of the front-end engineers often do)
  • So the question is, how do you make the panel follow container changes? This method is implemented by the layout manager.
  • There are many kinds of layout managers under this interface
  • This allows the Panle to move with the frame without changing the overall layout (the logical relationship is that frame uses the crossbow manager to lay out the panel)
  • Not finished,,,,,,

3. Window picture processing (not referring to the background of the window)

    • On the interface we can see which pictures we need, on the line.

4. Processing of animations (artificial animation + auto animation)

5. Path of the animation

Novice Small project-java tank Wars

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.