example5_2.java

来自「书中的例题」· Java 代码 · 共 36 行

JAVA
36
字号
 /* 建立JFrame子类的内部窗体 */
 import javax.swing.*;
 import java.awt.*;
 import java.awt.event.*;
 class Rootwindow extends JFrame implements ActionListener
 {
   Container con;
   Rootwindow()
   { 
	 setSize(200,200);
	 setVisible(true);
     con=getContentPane(); 
	 con.setLayout(new FlowLayout());
     JButton jbtn=new JButton("打开一个内部窗体");
	 con.add(jbtn);
	 jbtn.addActionListener(this);
	 validate();
     addWindowListener(new WindowAdapter()
         {public void windowClosing(WindowEvent e)
            {System.exit(0);}
         });
   }
  public void actionPerformed(ActionEvent e)
	{ JInternalFrame intf;
	  intf=new JInternalFrame("内部窗体",true,true,true,true);
      intf.setSize(60,60);
	  intf.setVisible(true);
	  con.add(intf);
	  JTextArea text=new JTextArea(5,15);
      intf.getContentPane().add(text,BorderLayout.CENTER);
   }
}
public class Example5_2
{  public static void main(String args[])
   { Rootwindow win=new Rootwindow();   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?