⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jcownewdialog.java

📁 这是一款应用程序与数据库联接
💻 JAVA
字号:
/* ===========================================================
 * JDBMonitor : a flexiable JDBC Monitor for the Java(tm) platform
 * ===========================================================
 *
 * (C) Copyright 2006-2006, by yang zhongke
 *
 * Project Info:  http://www.cownew.com
 *
 * This library is free software; you can redistribute it and/or modify it 
 * under the terms of the GNU Lesser General Public License as published by 
 * the Free Software Foundation; either version 2.1 of the License, or 
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 * USA.  
 *
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 * in the United States and other countries.]
 *
 * ---------------
 * JCownewDialog.java
 * ---------------
 * (C) Copyright 2006-2006, by yang zhongke
 *
 * Original Author:  yang zhongke;
 *
 * Changes
 * -------
 *
 */
package com.cownew.JDBMonitor.listenerImpl.uicommon;

import java.awt.Container;
import java.awt.Dialog;
import java.awt.Frame;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;

/**
 * base class of Swing Dialog
 * @author yang zhongke
 */
public abstract class JCownewDialog extends JDialog
{
	protected boolean isOK = false;
	
	protected Container container;

	public JCownewDialog(Dialog owner) throws HeadlessException
	{
		super(owner);
		initUI();
	}

	public JCownewDialog(Dialog owner, boolean modal)
			throws HeadlessException
	{
		super(owner, modal);
		initUI();
	}

	public JCownewDialog(Frame owner) throws HeadlessException
	{
		super(owner);
		initUI();
	}

	public JCownewDialog(Frame owner, boolean modal) throws HeadlessException
	{
		super(owner, modal);
		initUI();
	}	
	
	/**
	 * create OK Button,set it as the default button
	 * when button clicked,dialog will be closed and return isOK as true
	 * @return
	 */
	final protected JButton createOKBtn()
	{
		JButton btnOK = new JButton("OK");
		this.getRootPane().setDefaultButton(btnOK);
		btnOK.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e)
			{
				ok();			
			}
			
		});
		getRootPane().setDefaultButton(btnOK);
		return btnOK;
	}
	
	/**
	 * create Cancel Button
	 * when button clicked,dialog will be closed and return isOK as false
	 * @return
	 */
	final protected JButton createCancelBtn()
	{
		JButton btnCancel = new JButton("Cancel");
		btnCancel.addActionListener(new ActionListener(){

			public void actionPerformed(ActionEvent e)
			{
				cancel();				
			}
			
		});
		return btnCancel;
	}
	
	/**
	 * whether user approve the setting of the dialog
	 * @return
	 */
	final public boolean isOK()
	{
		return isOK;
	}
	
	/**
	 * approve the setting
	 *
	 */
	protected void ok()
	{
		if (verifyData())
		{
			saveConfig();
			isOK = true;
			dispose();
		}
	}
	
	/**
	 * cancel the setting
	 *
	 */
	protected void cancel()
	{
		isOK = false;
		dispose();
	}
	
	/**
	 * init the UI,always create components here
	 *
	 */
	protected void initUI()
	{
		container = getContentPane();
		
		UIManager.addPropertyChangeListener(new PropertyChangeListener(){

			public void propertyChange(PropertyChangeEvent evt)
			{
				lookAndFeelChange();			
			}
        	
        });
		
		this.addWindowListener(new WindowAdapter(){
			public void windowOpened(WindowEvent we)
			{				
				onOpend(we);
			}

			public void windowClosed(WindowEvent we)
			{
				onClosed(we);
			}		
			
		});
		
		SwingUtils.centerInParent(getOwner(),this);
	}
	
	/**
	 * Verify the setting in the dialog	 
	 * @return if the setting is correct,return true false false
	 */
	protected boolean verifyData()
	{
		return true;
	}
	
	/**
	 * save the configuration 
	 *
	 */
	protected void saveConfig()
	{
		
	}
	
	/**
	 * load the configuration
	 *
	 */
	protected void loadConfig()
	{
		
	}
	
	/**
	 * onOpened invoked when the dialog is opened
	 * @param e
	 */
	protected void onOpend(WindowEvent e)
	{
		isOK = false;
		loadConfig();
	}

	/**
	 * onClosed invoked when the dialog is closed
	 * @param e
	 */
	protected void onClosed(WindowEvent e)
	{
				
	}
	
	/**
	 * handle the Exception
	 * @param e
	 */
	protected void handleException(Throwable e)
	{
		JOptionPane.showMessageDialog(this, e.toString(),"error",JOptionPane.ERROR_MESSAGE);
	}
	
	/**
	 * when the LookandFeel changed,this method will be invoked
	 *
	 */
	final protected void lookAndFeelChange()
	{
		SwingUtilities.updateComponentTreeUI(this);	
	}
}

⌨️ 快捷键说明

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