Java swing image button Layout

Source: Internet
Author: User
Package ELTs. ui; import javax. swing. *; import javax. swing. border. *; import Java. AWT. *; public class menuframe extends jframe {public menuframe () {Init ();} private void Init () {settitle ("online evaluation"); setsize (600,400 ); setresizable (false); setdefaclocloseoperation (jframe. exit_on_close); setlocationrelativeto (null); // Add the main panel setcontentpane (createcontentpane ();} // create the main panel private jpanel createcontentpane () {jpanel P = new jpanel (New borderlayout (); p. add (borderlayout. north, createimagepane (); p. add (borderlayout. center, createcenterpane (); p. add (borderlayout. south, new jlabel ("copyright piracy required", jlabel. right); Return P;} // create the private jpanel createcenterpane () {jpanel P = new jpanel (New borderlayout () in the middle ()); info = new jlabel ("Welcome *** to take the test", jlabel. center); p. add (borderlayout. north, Info); p. add (createmenupane (); Return P;} // Private jpanel createmenupane () {jpanel P = new jpanel (); jbutton start = createimagebutton ("START", "exam.png"); p. add (start); jbutton result = createimagebutton ("score", "result.png"); p. add (result); jbutton message = createimagebutton ("rule", "message.png"); p. add (Message); jbutton exit = createimagebutton ("exit", "exit.png"); p. add (exit); Return P;} // auxiliary method, used to create the image button private jbutton createimagebutton (string text, string image) {imageicon icon = new imageicon (getclass (). getresource (image); jbutton BTN = new jbutton (text, icon); BTN. sethorizontaltextposition (jbutton. center); BTN. setverticaltextposition (jbutton. bottom); Return BTN;} private jpanel createimagepane () {jpanel P = new jpanel (); imageicon icon2 = new imageicon (getclass (). getresource ("title.png"); p. add (New jlabel (icon2); Return P;} // defines the private property private jlabel Info; // main method public static void main (string [] ARGs) {menuframe menu = new menuframe (); menu. setvisible (true );}}

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.