1、import javax . swing . *; import Java . awt . *; Publiclyclassframeextension and sjframepublicmyframe()// Set the form title setTitle("MyFrame ").
2.// Create a JPanel to store four JPanel Button Panels = New JPanel (New Flow Layout). Center, 10, 10).
3.// Create four buttons and add them to jpanejbuttonbutton1= newjbutton ("button1"); jbutton button 2 = new jbutton(" button 2 "); jbutton button 3 = new jbutton(" button 3 ")jbutton button 4 = new jbutton(" button 4 "); button panel . add(button 1)button panel . add(button 2)button panel . add(button 3 button panel . add(button 4);
4.// Add JPanel to the bottom area of the form add (buttonpanelborderlayout.south).
5.// Set the form size and close the operation setsize (400,300); setDefaultCloseOperation(JFrame。 EXIT _ ON _ CLOSE); publicstaticvoidmain(String[]args){
6.// Create a form object, displaying myframeframe = newmyframe (); frame . set visible(true); In this sample code, we create a JPanel and use the FlowLayout layout manager to add four buttons to this JPanel. Then, add this JPanel to the bottom area of the form to achieve the effect of setting four buttons below the form.