现在的位置: 首页 > 综合 > 正文

JInternalFrame_1

2014年02月18日 ⁄ 综合 ⁄ 共 5163字 ⁄ 字号 评论关闭

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.beans.PropertyVetoException;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.han.ImageScale;

/**
 * @author HAN
 * 
 */
public class JInternalFrame_1 extends JFrame {

	/**
	 * 
	 */
	private static final long serialVersionUID = 3109941155578827051L;

	JInternalFrame internalFramePersonel = null;
	JInternalFrame internalFrameCount = null;
	JInternalFrame internalFramePayment = null;
	JDesktopPane desktopPane = null;

	public JInternalFrame_1() {
		// TODO Auto-generated constructor stub
		JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT));
		JButton buttonPersonel = new JButton("人事管理");
		JButton buttonCount = new JButton("帐套管理");
		JButton buttonPayment = new JButton("待遇管理");
		panel.add(buttonPersonel);
		panel.add(buttonCount);
		panel.add(buttonPayment);

		Container container = getContentPane();
		container.add(panel, BorderLayout.NORTH);
		desktopPane = new JDesktopPane();
		container.add(desktopPane, BorderLayout.CENTER);
		URL resource = this.getClass().getResource("/images/LightHouse.jpg");
		ImageIcon imageIcon = new ImageIcon(resource);
		JLabel backLabel = new JLabel(imageIcon);
		backLabel.setBounds(0, 0, imageIcon.getIconWidth(),
				imageIcon.getIconHeight());

		// "new Integer(Integer.MIN_VALUE)" ensures that its layer is always
		// under the others.
		desktopPane.add(backLabel, new Integer(Integer.MIN_VALUE));

		desktopPane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);

		// the reason for non-using the inner hidden class is that the variable
		// that it will use is must be "final",
		// and this causes it can not be assigned in the inner hidden class.
		// So we use the inner class instead, which is parallel to the level
		// "method".
		buttonPersonel.addActionListener(new ButtonPersonelActionListener());

		buttonCount.addActionListener(new ButtonCountActionListener());
		buttonPayment.addActionListener(new ButtonPaymentActionListener());
	}

	private class ButtonPersonelActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub

			if (internalFramePersonel == null
					|| internalFramePersonel.isClosed()) {
				JInternalFrame[] allFrames = desktopPane.getAllFrames();
				int titleBarHight = 30 * allFrames.length;
				int x = titleBarHight + 10;
				int y = x;
				int width = 250;
				int height = 180;
				internalFramePersonel = new JInternalFrame("人事管理", true, true,
						true, true);
				internalFramePersonel.setVisible(true);
				internalFramePersonel.setBounds(x, y, width, height);
				desktopPane.add(internalFramePersonel);
			}

			try {
				// indispensable for the visualization of the internal frame
				internalFramePersonel.setSelected(true);
			} catch (PropertyVetoException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}

	private class ButtonCountActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub

			if (internalFrameCount == null || internalFrameCount.isClosed()) {
				JInternalFrame[] allFrames = desktopPane.getAllFrames();
				int titleBarHight = 30 * allFrames.length;
				int x = titleBarHight + 10;
				int y = x;
				int width = 250;
				int height = 180;
				internalFrameCount = new JInternalFrame("帐套管理", true, true,
						true, true);
				internalFrameCount.setVisible(true);
				internalFrameCount.setBounds(x, y, width, height);
				URL resource = this.getClass().getResource("/images/Luxun.jpg");
				BufferedImage imageScaled = null;
				BufferedImage in;
				try {
					in = ImageIO.read(resource);
					imageScaled = ImageScale.scale(in, 0.05, 0.05, 1);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				ImageIcon imageIcon = new ImageIcon(imageScaled);
				internalFrameCount.setFrameIcon(imageIcon);
				desktopPane.add(internalFrameCount);
			}

			try {
				// indispensable for the visualization of the internal frame
				internalFrameCount.setSelected(true);
			} catch (PropertyVetoException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}

		}
	}

	private class ButtonPaymentActionListener implements ActionListener {
		public void actionPerformed(ActionEvent e) {
			// TODO Auto-generated method stub

			if (internalFramePayment == null || internalFramePayment.isClosed()) {
				JInternalFrame[] allFrames = desktopPane.getAllFrames();
				int titleBarHight = 30 * allFrames.length;
				int x = titleBarHight + 10;
				int y = x;
				int width = 250;
				int height = 180;
				internalFramePayment = new JInternalFrame("待遇管理", true, true,
						true, true);
				internalFramePayment.setVisible(true);
				internalFramePayment.setBounds(x, y, width, height);
				URL resource = this.getClass().getResource("/images/Luxun.jpg");
				BufferedImage imageScaled = null;
				BufferedImage in;
				try {
					in = ImageIO.read(resource);
					imageScaled = ImageScale.scale(in, 0.05, 0.05, 1);
				} catch (IOException e1) {
					// TODO Auto-generated catch block
					e1.printStackTrace();
				}
				ImageIcon imageIcon = new ImageIcon(imageScaled);
				internalFramePayment.setFrameIcon(imageIcon);
				desktopPane.add(internalFramePayment);
			}

			try {
				// indispensable for the visualization of the internal frame
				internalFramePayment.setSelected(true);
			} catch (PropertyVetoException e1) {
				// TODO Auto-generated catch block
				e1.printStackTrace();
			}
		}
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		JInternalFrame_1 frame = new JInternalFrame_1();
		frame.setTitle("企业人事管理系统 ");
		frame.setVisible(true);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.setBounds(100, 100, 570, 470);
	}

}

抱歉!评论已关闭.