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:
- Import java. AWT .*;
- Import javax. Swing. Border .*;
- Import java. AWT. event .*;
- Import javax. Swing .*;
- Public class test5 {
- Public static void main (string [] ARGs ){
- Smallframe Sf = new smallframe ();
- SF. setvisible (true );
- }
- }
- Class smallframe extends jframe {
- Container P;
- Jlabel tip = new jlabel ("Enter your student ID :");
- Jtextfield stunotext = new jtextfield ();
- Jpanel viewpane = new jpanel ();
- Jbutton OK = new jbutton ("OK ");
- Jbutton reset = new jbutton ("reset ");
- Public smallframe (){
- Super ("query by student ID ");
- Setbounds (200,100,350,280 );
- Setresizable (false );
- Setdefaclocloseoperation (exit_on_close );
- P = getcontentpane ();
- P. setlayout (null );
- Tip. setbounds (70, 20,100, 20 );
- Tip. setforeground (color. Red );
- Stunotext. setbounds (155, 20,100, 20 );
- P. Add (TIP );
- P. Add (stunotext );
- OK. setbounds (90, 60, 60, 20 );
- OK. setforeground (color. Green );
- P. Add (OK );
- Reset. setbounds (180, 60, 60, 20 );
- Reset. setforeground (color. Green );
- P. Add (reset );
- // Key code block
- Titledborder TB = new titledborder (borderfactory. createlineborder (new color (255, 0, 0), "query result ");
- TB. settitlecolor (color. Blue );
- Viewpane. setborder (TB );
- Viewpane. setlayout (null );
- Jlabel stunolabe = new jlabel ("student ID :");
- Stunolabe. setbounds (80,130, 80, 20 );
- Stunolabe. setforeground (new color (34,139, 34 ));
- P. Add (stunolabe );
- Jtextfield stunotextf = new jtextfield ();
- Stunotextf. setbounds (150,130, 90, 20 );
- P. Add (stunotextf );
- Jlabel stunamelabe = new jlabel ("name :");
- Stunamelabe. setbounds (80,160, 80, 20 );
- Stunamelabe. setforeground (new color (34,139, 34 ));
- P. Add (stunamelabe );
- Jtextfield nametextf = new jtextfield ();
- Nametextf. setbounds (150,160, 90, 20 );
- P. Add (nametextf );
- Jlabel stuagelabe = new jlabel ("Age :");
- Stuagelabe. setbounds (80,190, 80, 20 );
- Stuagelabe. setforeground (new color (34,139, 34 ));
- P. Add (stuagelabe );
- Jtextfield agetextf = new jtextfield ();
- Agetextf. setbounds (150,190, 90, 20 );
- P. Add (agetextf );
- Viewpane. Add (New jbutton ("hkjj "));
- Viewpane. setbounds (18,100,310,141 );
- P. Add (viewpane );
- }
- }
The above program: