Java internal form design and form positioning

Source: Internet
Author: User

Import javax.swing.*;


import java.awt.*;


import java.awt.event.*;


import Javax.swing.UIManager;


class Mywindow extends JFrame


{


JButton button1;


JButton button2;


JInternalFrame interframe1,interframe2;


JPanel JPanel;


Mywindow ()


{


setvisible (TRUE);


//setsize (400,400) See the instructions below!


jpanel= (JPanel) This.getcontentpane ();


jpanel.setlayout (New GridLayout (1,2));


button1=new JButton ("I");


button2=new JButton ("You");


//------------------------------------------------------


interframe1=new jinternalframe ("inner form a", true,true,true,true);


interframe1.setsize (150,250);


interframe1.setvisible (TRUE); Must add this sentence! Otherwise the internal form cannot!


Interframe1.getcontentpane (). Add (button1);


jdesktoppane desk1=new JDesktopPane ();


Desk1.add (INTERFRAME1);


Jpanel.add (DESK1);


//----------------------------------------------------


interframe2=new jinternalframe ("inside Form B", true,true,true,true);


interframe2.setsize (150,250);


interframe2.setvisible (TRUE);


Interframe2.getcontentpane (). Add (Button2,borderlayout.center);


Interframe2.getcontentpane (). Add (New JLabel ("Hello"), Borderlayout.north);


jdesktoppane desk2=new JDesktopPane ();


Desk2.add (interframe2);


Jpanel.add (DESK2);


}


//--------------------------------------------------------


public Dimension getpreferredsize ()


{


return new Dimension (500,500);


/* Note: This way to set the size of the form to display a better result!


* If the setsize (400,400) size is set directly, the effect is not good


* Recommended Beginners Test!


*/


}


}


public class Interframe


{


public static void Main (String args[])


{Mywindow win=new mywindow ();


Win.pack ();


//Win.setvisible (TRUE); If this is the case, the internal form is not displayed!


//Win.setsize (new Dimension (400,400));


Dimension screensize = Toolkit.getdefaulttoolkit (). Getscreensize ();


Dimension framesize = Win.getsize ();


if (Framesize.height > Screensize.height)


{


framesize.height = screensize.height;


}


if (Framesize.width > Screensize.width)


{


framesize.width = screensize.width;


}


win.setlocation (screensize.width-framesize.width)/2, (Screensize.height-framesize.height)/2);


Win.addwindowlistener (New Windowadapter ()


{


public void windowclosing (WindowEvent e)


{system.exit (0);}


});


}


}

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.