Java learning notes-swing-Basic swing Program (improved map display in the map editor Framework)

Source: Internet
Author: User

Ah, the last time I got a good job at AM, I was so sleepy that I didn't have to figure it out. There are still many problems with the map display, for example, when you scale the window, there will be gaps between those images (that is, jlabel's jlmap). How can this problem be solved? In fact, there are many methods, such as setting border for each jlabel (in fact, just think about it, but I have never done it), but I set a layout for this jpicon and set parameters for gridlayout, set the gap between jlabels to zero. Of course, it is divided into upper and lower and left. After this setting, the jlabel inside jpicon will be tight, hey. In addition, the buttons in the east direction must be the same as the fat ones, and the original size of the buttons cannot be restored. This is because within girdlayout, only the control is stretched and filled, therefore, this time we will give an improvement solution to restore the control's own size. However, it is similar to the method of inserting the image to the center. We will add a layer-center container jpanel, then use the flowlayout layout to pull ~ Hey, wow, I have added a lot of jpanels, and my head is dizzy. This time, we will only make a simple supplement and improvement. We will try again later.

Here we will modify the jpicon layout in the center area of the borderlayout of the large frame so that there is no gap between the jlabel in it:

E.g .:

Jpicon = new jpanel (New gridlayout (height, width, 0, 0 ));
For (INT I = 0, j = 0; I ...{
J = Rand. nextint (4 );
Jlmap = new jlabel (LS. landstyles [J]);
Jpicon. Add (jlmap );
}

When jpicon is constructed, the gridlayout layout is used. The first two parameters are the height and width, and the last two parameters are the gaps between the upper and lower components and the left and right components.

The next step is to improve the component size of east. The general idea is also described in the preface, so the code is provided here.

E.g .:

Jpeast = new jpanel (New gridlayout (0, 1 ));

Jpeastco = new jpanel (New flowlayout ());
Jpeastco. Add (jbicon );
Jpeast. Add (jpeastco );

Jpeastco = new jpanel (New flowlayout ());
Jpeastco. Add (jbsave );
Jpeast. Add (jpeastco );

Jpeastco = new jpanel (New flowlayout ());
Jpeastco. Add (jbloadmapfromfile );
Jpeast. Add (jpeastco );

Jpeastco = new jpanel (New flowlayout ());
Jpeastco. Add (JTF );
Jpeast. Add (jpeastco );

Jpeastco = new jpanel (New flowlayout ());
Jpeastco. Add (jltips );
Jpeast. Add (jpeastco );

Here we declare a new jpanel: jpeasteo, which is a container that truly puts buttons and text areas, and only one control is put in one container (a waste of time, just call add once ). Because the added object instance (for personal understanding, please correct the error), rather than reference, this jpeastco can be used repeatedly, in addition, the modification points will not change the last added items.Note that gridlayout () is used in the layout of jpeast. 0 indicates that any column can exist, and 1 indicates that only one row exists. The preceding parameter setting column and the following parameter setting row.

This should be better. The two bugs left over last time are considered as basic solutions. Next, we need to solve the format problem of the map file, that is, what is used to save the terrain information. First, the number cannot be used. Unless the terrain is less than two digits, that is, up to 10 terrain can be used to represent the terrain with Arabic numerals. If there are more than 10 terrain, when reading a terrain file, the data in the Section 124 does not represent the terrain No. 1, No. 2, no. 4, No. 1, or No. 24, there is absolutely no such uncertainty in the terrain. You can find a solution on your own ~ Hey, you can recommend a good method ~ That's what I think. (Consider a more economical and environmentally friendly method, and prompt: optimal binary tree! Hey, and then directly save it as a binary file. The map file is difficult for small people to edit and study. It's not possible without your map editor. Well, that's it, you have to compile a data structure ...... Hey hey, try again later ).

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.