爱心技术专栏专题

内部窗体设计与窗体定位

摘录:爱心 来源:爱心 加入时间:2006年09月14日
摘要:
内部窗体设计与窗体定位
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.UIManager;
class Mywindow extends JFrame
{
JButton button1;
JButton button2;
转载:转载请保留本信息,本文来自
http://www.51dibs.com
/html/2006/article/info/a_9b00faf4ced3f6e2.htm

内部窗体设计与窗体定位

站点:爱心种子小博士 关键字:内部窗体设计与窗体定位

   
内部窗体设计与窗体定位
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)见下面的说明!
jpanel=(JPanel)this.getContentPane();
jpanel.setLayout(new GridLayout(1,2));

button1=new JButton("我");
button2=new JButton("你");

//------------------------------------------------------
interframe1=new JInternalFrame("内窗体A",true,true,true,true);
interframe1.setSize(150,250);
interframe1.setVisible(true); // 必须加上此句 !否则内部窗体无法 !
interframe1.getContentPane().add(button1);
JDesktopPane desk1=new JDesktopPane();
desk1.add(interframe1);
jpanel.add(desk1);
//----------------------------------------------------
interframe2=new JInternalFrame("内窗体B",true,true,true,true);
interframe2.setSize(150,250);
interframe2.setVisible(true);
interframe2.getContentPane().add(button2,BorderLayout.CENTER);
interframe2.getContentPane().add( new JLabel("你好啊"),BorderLayout.NORTH);
JDesktopPane desk2=new JDesktopPane();
desk2.add(interframe2);
jpanel.add(desk2);
}
//--------------------------------------------------------

public Dimension getPreferredSize()
{
return new Dimension(500,500);
/*注意:这种方式设置窗体大小显示的效果更好!
*如果直接这样设置setSize(400,400)大小 ,效果不好
* 建议初学者测试!
*/
}

}
public class interframe
{
public static void main(String args[])
{ Mywindow win=new Mywindow();
win.pack();
// win.setVisible(true); 如果有此句,内部窗体不显示!
// 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);}
});
}

}

客户服务中心信箱:[email protected] [email protected] 网站地图

声明

合作伙伴: