All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.becausetesting.commonswindow.utils.ui.JMessageDialogUtils Maven / Gradle / Ivy

package com.github.becausetesting.commonswindow.utils.ui;

/*-
 * false
 * commons-window
 * sectionDelimiter
 * Copyright (C) 2016 Alter Hu
 * sectionDelimiter
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */

/*-
 * #%L
 * commons-window
 * $Id:$
 * $HeadURL:$
 * %%
 * Copyright (C) 2016 Alter Hu
 * %%
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * #L%
 */


import javax.swing.JFrame;
import javax.swing.JOptionPane;

import org.apache.log4j.Logger;

/** refer this page: center the frame or user's screenshot
 * http://alvinalexander.com/java/joptionpane-showmessagedialog-examples-1
 * that when you supply a null argument like that, the JOptionPane dialog will be centered on the user’s screen. 
 * When you supply a JFrame reference, the dialog is centered on that JFrame, so this behavior can be slightly different.
 * @author ahu
 *
 */
public class JMessageDialogUtils {
	private static Logger log=Logger.getLogger(JMessageDialogUtils.class);

	public static void warning(JFrame frame,String title,Object message){
		JOptionPane.showMessageDialog(frame, message, title, JOptionPane.WARNING_MESSAGE);
		log.warn(message);
	}
	
	public static void error(JFrame frame,String title,Object message){
		JOptionPane.showMessageDialog(frame, message, title, JOptionPane.ERROR_MESSAGE);
		log.error(message);
	}
	public static void info(JFrame frame,String title,Object message){
		JOptionPane.showMessageDialog(frame, message, title, JOptionPane.INFORMATION_MESSAGE);
		log.info(message);
	}
	public static void question(JFrame frame,String title,Object message){
		JOptionPane.showMessageDialog(frame, message, title, JOptionPane.QUESTION_MESSAGE);
		//log.debug(message);
	}
	/**
	 * @param frame the object
	 * @param title the title
	 * @param message the message
	 * @return 0=yes or ok
	 */
	public static int confirm(JFrame frame,String title,Object message){
		int showConfirmDialog = JOptionPane.showConfirmDialog(frame, message, title, JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
		return showConfirmDialog;
	}
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy