www.pudn.com > 4个swing界面.rar > InternalFrameAppFrame.java


package internalframe;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import com.borland.jbcl.layout.*;



public class InternalFrameAppFrame extends JFrame {


    public Integer FIRST_FRAME_LAYER  = new Integer(1);
    public Integer DEMO_FRAME_LAYER   = new Integer(2);
    public Integer PALETTE_LAYER     = new Integer(3);

  JInternalFrame f=new JInternalFrame("Use this frame to create other frame!",false,false,false);
  XYLayout xYLayout2 = new XYLayout();
  JButton jbtnCab = new JButton();
  JButton jbtnMoon = new JButton();
  JButton jButton4 = new JButton();
  JCheckBox jchckbxResize = new JCheckBox();
  JCheckBox jchckbxClose = new JCheckBox();
  JCheckBox jchckbxBig = new JCheckBox();
  JCheckBox jchckbxSmall = new JCheckBox();
  JButton jbtnFish = new JButton();
  JLabel jlblFrametitle = new JLabel();
  JTextField jtxtfldFrametitle = new JTextField();
  //XYLayout xYLayout1 = new XYLayout();
  JDesktopPane desktop=new JDesktopPane();
  /**Construct the frame*/
  public InternalFrameAppFrame() {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
    try {
      jbInit();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
  /**Component initialization*/
  private void jbInit() throws Exception  {
   //setIconImage(Toolkit.getDefaultToolkit().createImage(InternalFrameAppFrame.class.getResource("[Your Icon]")));

    this.setContentPane(desktop);
    this.setSize(new Dimension(634, 442));
    this.setTitle("Demo");
    f.getContentPane().setLayout(xYLayout2);
    jchckbxResize.setText("Resizeable");
    jchckbxClose.setText("Closable");
    jchckbxBig.setText("Bigable");
    jchckbxSmall.setText("Smallable");
    jbtnFish.setIcon(new ImageIcon(InternalFrameAppFrame.class.getResource("image/fish_small.gif")));
    jbtnFish.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jbtnFish_actionPerformed(e);
      }
    });
    jbtnCab.setIcon(new ImageIcon(InternalFrameAppFrame.class.getResource("image/cab_small.gif")));
    jbtnCab.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jbtnCab_actionPerformed(e);
      }
    });
    jbtnMoon.setIcon(new ImageIcon(InternalFrameAppFrame.class.getResource("image/moon_small.gif")));
    jbtnMoon.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jbtnMoon_actionPerformed(e);
      }
    });
    jButton4.setIcon(new ImageIcon(InternalFrameAppFrame.class.getResource("image/sun_small.gif")));
    jButton4.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(ActionEvent e) {
        jButton4_actionPerformed(e);
      }
    });
    jlblFrametitle.setText("FrameTitle");


    f.getContentPane().add(jchckbxResize,    new XYConstraints(44, 132, 92, -1));
    f.getContentPane().add(jchckbxBig,  new XYConstraints(44, 180, 92, -1));
    f.getContentPane().add(jchckbxClose,  new XYConstraints(184, 135, 92, -1));
    f.getContentPane().add(jchckbxSmall,     new XYConstraints(184, 180, 92, -1));
    f.getContentPane().add(jbtnFish,  new XYConstraints(44, 13, 99, 40));
    f.getContentPane().add(jbtnCab,    new XYConstraints(177, 13, 99, 42));
    f.getContentPane().add(jbtnMoon,    new XYConstraints(44, 66, 99, 42));
    f.getContentPane().add(jButton4,   new XYConstraints(177, 66, 99, 42));
    f.getContentPane().add(jlblFrametitle, new XYConstraints(44, 226, 77, 27));
    f.getContentPane().add(jtxtfldFrametitle,   new XYConstraints(188, 231, 88, 24));
    desktop.add(f, PALETTE_LAYER );





    firstFrames();
    f.getContentPane().setBackground(SystemColor.activeCaptionBorder);
    f.setBounds(20,20,350,400);
  }

  //create the first frames
  public void firstFrames()
  {
    //cerate the frame creater.
   f.setClosable(false);
   f.show();




/*this cab frame is the middle frames*/
  JInternalFrame jntrnlfrmCab= new JInternalFrame("Demo",true,true,true,true);
  desktop.add(jntrnlfrmCab,DEMO_FRAME_LAYER);

  JScrollPane jscrlpneTemp=new JScrollPane();
  jscrlpneTemp.getViewport().add(new JLabel( new ImageIcon(InternalFrameAppFrame.class.getResource("image/cab.gif"))),null);

  //creat a panel for the frame.
  JPanel p = new JPanel();
  p.setBackground(Color.white);
  p.setLayout(new BorderLayout() );
  p.add(jscrlpneTemp,BorderLayout.CENTER);


  jntrnlfrmCab.setContentPane(p);

  jntrnlfrmCab.setBounds(15,15,200,200);
  jntrnlfrmCab.show();
/*--------------------------------------------------*/
  //This code is not support by Archive Builder.

  /*JInternalFrame jntrnlfrmFish= new JInternalFrame(jtxtfldFrametitle.getText(),true,true,true,true);
  desktop.add(jntrnlfrmFish, FIRST_FRAME_LAYER);

  //creat a panel for the frame.
  JPanel p = new JPanel();
  p.setBackground(Color.white);
  p.setLayout(new BorderLayout() );
  p.add(new JLabel(new ImageIcon(InternalFrameAppFrame.class.getResource("image/fish.gif"))), BorderLayout.CENTER);

  jntrnlfrmFish.setContentPane(p);
  jntrnlfrmFish.setBounds(15,15,200,200);
  jntrnlfrmFish.setTitle("This frame is always on the bottom!");

  jntrnlfrmFish.show();*/
/*--------------------------------------------------*/


 /*this fish frame is always under other frames*/


  JInternalFrame jntrnlfrmFish= new JInternalFrame("This frame is always on the bottom!",true,true,true,true);
  desktop.add(jntrnlfrmFish,FIRST_FRAME_LAYER);

  JScrollPane jscrlpneTemp1=new JScrollPane();
  jscrlpneTemp1.getViewport().add(new JLabel( new ImageIcon(InternalFrameAppFrame.class.getResource("image/fish.gif"))),null);

  //creat a panel for the frame.
  JPanel p1 = new JPanel();
  p1.setBackground(Color.white);
  p1.setLayout(new BorderLayout() );
  p1.add(jscrlpneTemp1,BorderLayout.CENTER);


  jntrnlfrmFish.setContentPane(p1);

  jntrnlfrmFish.setBounds(15,100,200,200);
  jntrnlfrmFish.show();

  }


  /**Overridden so we can exit when window is closed*/
  protected void processWindowEvent(WindowEvent e) {
    super.processWindowEvent(e);
    if (e.getID() == WindowEvent.WINDOW_CLOSING) {
      System.exit(0);
    }
  }

  void jbtnFish_actionPerformed(ActionEvent e) {
  JInternalFrame jntrnlfrmFish= new JInternalFrame(jtxtfldFrametitle.getText(),jchckbxResize.isSelected(),jchckbxClose.isSelected(),jchckbxBig.isSelected(),jchckbxSmall.isSelected());
  desktop.add(jntrnlfrmFish,DEMO_FRAME_LAYER);

  JScrollPane jscrlpneTemp=new JScrollPane();
  jscrlpneTemp.getViewport().add(new JLabel( new ImageIcon(InternalFrameAppFrame.class.getResource("image/fish.gif"))),null);

  //creat a panel for the frame.
  JPanel p = new JPanel();
  p.setBackground(Color.white);
  p.setLayout(new BorderLayout() );
  p.add(jscrlpneTemp,BorderLayout.CENTER);


  jntrnlfrmFish.setContentPane(p);

  jntrnlfrmFish.setBounds(15,15,200,200);
  jntrnlfrmFish.show();
  }

  void jbtnCab_actionPerformed(ActionEvent e) {

  JInternalFrame jntrnlfrmCab= new JInternalFrame(jtxtfldFrametitle.getText(),jchckbxResize.isSelected(),jchckbxClose.isSelected(),jchckbxBig.isSelected(),jchckbxSmall.isSelected());
  desktop.add(jntrnlfrmCab,DEMO_FRAME_LAYER);

  JScrollPane jscrlpneTemp=new JScrollPane();
  jscrlpneTemp.getViewport().add(new JLabel( new ImageIcon(InternalFrameAppFrame.class.getResource("image/cab.gif"))),null);

  //creat a panel for the frame.
  JPanel p = new JPanel();
  p.setBackground(Color.white);
  p.setLayout(new BorderLayout() );
  p.add(jscrlpneTemp,BorderLayout.CENTER);


  jntrnlfrmCab.setContentPane(p);

  jntrnlfrmCab.setBounds(15,15,200,200);
  jntrnlfrmCab.show();

  }

  void jbtnMoon_actionPerformed(ActionEvent e) {
 JInternalFrame jntrnlfrmMoon= new JInternalFrame(jtxtfldFrametitle.getText(),jchckbxResize.isSelected(),jchckbxClose.isSelected(),jchckbxBig.isSelected(),jchckbxSmall.isSelected());
  desktop.add(jntrnlfrmMoon,DEMO_FRAME_LAYER);

  JScrollPane jscrlpneTemp=new JScrollPane();
  jscrlpneTemp.getViewport().add(new JLabel( new ImageIcon(InternalFrameAppFrame.class.getResource("image/moon.gif"))),null);

  //creat a panel for the frame.
  JPanel p = new JPanel();
  p.setBackground(Color.white);
  p.setLayout(new BorderLayout() );
  p.add(jscrlpneTemp,BorderLayout.CENTER);


  jntrnlfrmMoon.setContentPane(p);

  jntrnlfrmMoon.setBounds(15,15,200,200);
  jntrnlfrmMoon.show();
  }

  void jButton4_actionPerformed(ActionEvent e) {
 JInternalFrame jntrnlfrmSun= new JInternalFrame(jtxtfldFrametitle.getText(),jchckbxResize.isSelected(),jchckbxClose.isSelected(),jchckbxBig.isSelected(),jchckbxSmall.isSelected());
  desktop.add(jntrnlfrmSun,DEMO_FRAME_LAYER);

  JScrollPane jscrlpneTemp=new JScrollPane();
  jscrlpneTemp.getViewport().add(new JLabel( new ImageIcon(InternalFrameAppFrame.class.getResource("image/sun.gif"))),null);

  //creat a panel for the frame.
  JPanel p = new JPanel();
  p.setBackground(Color.white);
  p.setLayout(new BorderLayout() );
  p.add(jscrlpneTemp,BorderLayout.CENTER);


  jntrnlfrmSun.setContentPane(p);

  jntrnlfrmSun.setBounds(15,15,200,200);
  jntrnlfrmSun.show();
  }


}