Experience in creating single-host tetris games (4)

Source: Internet
Author: User

The following describes how to build the game tool interface. Define the following attributes in mainframe

Private gamepanel;
// Level
Private jlabel leveltextlabel = new jlabel ("level ");
Private jlabel levellabel = new jlabel ();
Private box leveltextbox = Box. createhorizontalbox ();
Private box levelbox = Box. createhorizontalbox ();
// Score
Private box scoretextbox = Box. createhorizontalbox ();
Private box scorebox = Box. createhorizontalbox ();
Private jlabel scoretextlabel = new jlabel ("score ");
Private jlabel scorelabel = new jlabel ();
// Next
Private box nexttextbox = Box. createhorizontalbox ();
Private jlabel nexttextlabel = new jlabel ("Next ");
// Continue
Private box resumebox = Box. createhorizontalbox ();
Private jlabel resumelabel = new jlabel ();
// Pause
Private box pausebox = Box. createhorizontalbox ();
Private jlabel pauselabel = new jlabel ();
// Start
Private box startbox = Box. createhorizontalbox ();
Private jlabel startlabel = new jlabel ();
// Tool
Private jpanel toolpanel = new jpanel ();
Add the following code to the constructor in the mainframe class to create the public mainframe (){
This. currentlevel = 1;

This. gamepanel = new gamepanel (this );

Boxlayout toolpanellayout = new boxlayout (this. toolpanel, boxlayout. y_axis );
This. toolpanel. setlayout (toolpanellayout );
This. toolpanel. setborder (New etchedborder ());
This. toolpanel. setbackground (color. Gray );
// Score
This. scoretextbox. Add (this. scoretextlabel );
This. scorelabel. settext (string. valueof (this. Score ));
This. scorebox. Add (this. scorelabel );
// Level
This. leveltextbox. Add (this. leveltextlabel );
This. levellabel. settext (string. valueof (this. currentlevel ));
This. levelbox. Add (this. levellabel );
// Continue
This. resumelabel. seticon (resume_icon );
This. resumelabel. setpreferredsize (new dimension (3, 25 ));
This. resumebox. Add (this. resumelabel );
// Pause button
This. pauselabel. seticon (pause_icon );
This. pauselabel. setpreferredsize (new dimension (3, 25 ));
This. pausebox. Add (this. pauselabel );
// Start
This. startlabel. seticon (start_icon );
This. startlabel. setpreferredsize (new dimension (3, 25 ));
This. startbox. Add (this. startlabel );
// Next
This. nexttextbox. Add (this. nexttextlabel );

This. toolpanel. Add (box. createverticalstrut (10 ));
This. toolpanel. Add (scoretextbox );
This. toolpanel. Add (box. createverticalstrut (10 ));
This. toolpanel. Add (scorebox );
This. toolpanel. Add (box. createverticalstrut (10 ));
This. toolpanel. Add (leveltextbox );
This. toolpanel. Add (box. createverticalstrut (10 ));
This. toolpanel. Add (levelbox );
This. toolpanel. Add (box. createverticalstrut (15 ));
This. toolpanel. Add (this. resumebox );
This. toolpanel. Add (box. createverticalstrut (15 ));
This. toolpanel. Add (this. pausebox );
This. toolpanel. Add (box. createverticalstrut (15 ));
This. toolpanel. Add (this. startbox );
This. toolpanel. Add (box. createverticalstrut (30 ));
This. toolpanel. Add (this. nexttextbox );

This. blankbox. Add (box. createhorizontalstrut (99 ));
This. toolpanel. Add (blankbox );

This. Add (this. gamepanel, borderlayout. center );
This. Add (this. toolpanel, borderlayout. East );
This. setpreferredsize (new dimension (349,416 ));
This. setdefaclocloseoperation (jframe. exit_on_close );
This. setlocation (350,200 );
This. setresizable (false );
This. settitle ("Tetris ");
This. Pack ();
}

 

 

 

 

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.