Java border/borderlayout implements groupbox

Source: Internet
Author: User

Groupbox similar to C ++ is not found in Java. After searching, you can find that it is implemented using borderlayout and border.

Take notes as follows:

Code:
  1. Import java. AWT .*;
  2. Import javax. Swing. Border .*;
  3. Import java. AWT. event .*;
  4. Import javax. Swing .*;
  5. Public class test5 {
  6. Public static void main (string [] ARGs ){
  7. Smallframe Sf = new smallframe ();
  8. SF. setvisible (true );
  9. }
  10. }
  11. Class smallframe extends jframe {
  12. Container P;
  13. Jlabel tip = new jlabel ("Enter your student ID :");
  14. Jtextfield stunotext = new jtextfield ();
  15. Jpanel viewpane = new jpanel ();
  16. Jbutton OK = new jbutton ("OK ");
  17. Jbutton reset = new jbutton ("reset ");
  18. Public smallframe (){
  19. Super ("query by student ID ");
  20. Setbounds (200,100,350,280 );
  21. Setresizable (false );
  22. Setdefaclocloseoperation (exit_on_close );
  23. P = getcontentpane ();
  24. P. setlayout (null );
  25. Tip. setbounds (70, 20,100, 20 );
  26. Tip. setforeground (color. Red );
  27. Stunotext. setbounds (155, 20,100, 20 );
  28. P. Add (TIP );
  29. P. Add (stunotext );
  30. OK. setbounds (90, 60, 60, 20 );
  31. OK. setforeground (color. Green );
  32. P. Add (OK );
  33. Reset. setbounds (180, 60, 60, 20 );
  34. Reset. setforeground (color. Green );
  35. P. Add (reset );
  36. // Key code block
  37. Titledborder TB = new titledborder (borderfactory. createlineborder (new color (255, 0, 0), "query result ");
  38. TB. settitlecolor (color. Blue );
  39. Viewpane. setborder (TB );
  40. Viewpane. setlayout (null );
  41. Jlabel stunolabe = new jlabel ("student ID :");
  42. Stunolabe. setbounds (80,130, 80, 20 );
  43. Stunolabe. setforeground (new color (34,139, 34 ));
  44. P. Add (stunolabe );
  45. Jtextfield stunotextf = new jtextfield ();
  46. Stunotextf. setbounds (150,130, 90, 20 );
  47. P. Add (stunotextf );
  48. Jlabel stunamelabe = new jlabel ("name :");
  49. Stunamelabe. setbounds (80,160, 80, 20 );
  50. Stunamelabe. setforeground (new color (34,139, 34 ));
  51. P. Add (stunamelabe );
  52. Jtextfield nametextf = new jtextfield ();
  53. Nametextf. setbounds (150,160, 90, 20 );
  54. P. Add (nametextf );
  55. Jlabel stuagelabe = new jlabel ("Age :");
  56. Stuagelabe. setbounds (80,190, 80, 20 );
  57. Stuagelabe. setforeground (new color (34,139, 34 ));
  58. P. Add (stuagelabe );
  59. Jtextfield agetextf = new jtextfield ();
  60. Agetextf. setbounds (150,190, 90, 20 );
  61. P. Add (agetextf );
  62. Viewpane. Add (New jbutton ("hkjj "));
  63. Viewpane. setbounds (18,100,310,141 );
  64. P. Add (viewpane );
  65. }
  66. }

The above program:

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.