Take the snake as a child to play for example, for Java Image Interface learning sentiment

Source: Internet
Author: User

Brief introduction:

All the time I've been using code to write graphical interfaces I've never done before, (-?-;), but have chosen to open this road, I think everything is going to be a bit, so maybe it might be a lot easier to re-write things after many months. Moreover, if you forget it later, you can also look at it here, by the way Gao's own literary ability. Forgive me to hit the word more ugly understand, these are more or less exist their own emotions written out, see the text good.

Read after me: This article is suitable for some just get started to learn the graphical interface of Bo friends , of course, more or less understand the basic knowledge of Java (class-related knowledge, generic collection, etc.), otherwise look good. An appendix will be given at the end of the project document. I hate books on a line of shy and difficult to understand the text, a little fresh activity is not, probably and I do not like endorsement has a relationship O (^▽^) O.

This time I will take a game as an example to begin to introduce my own insight into the graphical interface of some knowledge.

Game: Greedy snake;

Development tools: Eclipse Java naon,jdk1.7 above;

Development environment: WINDOWS10 or Ubuntu14.04 (I was compiled under these two platforms, the effect, I was recommended Ubuntu, because I do not know why the windows under the interface is often empty?) To click Run as Java application a lot more, (-?-;) will not necessarily have a game interface appear. If you have bo friends know, hope to be able to guide the younger brother, in this first thank you .

The game interface here (well, like I put on the Ubuntu desktop, Windows can not see, etc will be posted, compared to simple, time relationship, I first say some)

—————————————————— I'm a split line ————————————————————

Body:

What is 01.JFrame?

Since it is to write the image interface, then the first to have a framework is cutting! So JFrame is the ancestor of this image interface framework class, so we're going to inherit this class. First in new>>class>>xxxx.class; I suggested that different classes be placed in different packages, so the regulations are clear (this is nonsense). I first name this frame is called Snakefram.java, code see below, look at the comment (knocking on the blackboard);

1  PackageCom.hcc.ui;2 3 ImportJavax.swing.JFrame;4 ImportJava.awt.Toolkit;5 Importjava.awt.Dimension;6 7 8  Public classSnakeframeextendsJFrame {9 Ten     Private Final int_windowwidth = 530; One     Private Final int_windowheight = 450; A      PublicSnakeframe () -     {         -          This. Settitle ("The first draft of the Snake 1.0"); the          -          This. SetSize (_windowwidth, _windowheight); -Toolkit _toolkit =Toolkit.getdefaulttoolkit (); -Dimension _screensize = _toolkit.getscreensize ();//get the size of your computer screen +         Final int_screenwidth =_screensize.width; -         Final int_screenheight =_screensize.height; +         //Center A          This. setlocation (_screenwidth- This. GetWidth ())/2, (_screenheight- This. GetHeight ())/2); at      -          This. Setdefaultcloseoperation (Exit_on_close);//default shutdown operation, note that the program will not quit, will stay in the background -          -          This. setresizable (false);//set to window unchanged, note the default can stretch what -                  -          This. setvisible (true);//set to visible, note default is not visible in  -          This. setlayout (NULL);//set the layout to empty, note that there are many layout methods, but there is no need to     } +      -}
Snakeframe.class

This is relatively simple, general words jframe this write ok

< note: Not to be continued >

Take the snake as a child for example, for the Java Image Interface Learning comprehension

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.