KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > adminGui > widget > MessageBox


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: $
8
package org.ozoneDB.adminGui.widget;
9
10 import java.awt.*;
11 import javax.swing.*;
12
13 /**
14  * Contains static methods for showing message dialogs
15  *
16  * @author Per Nyfelt
17  */

18 public class MessageBox {
19
20     private static void show(Component parentComponent, String JavaDoc message, String JavaDoc title, int messageType) {
21         JOptionPane pane = new JOptionPane(message, messageType);
22
23         pane.setBackground(Color.WHITE);
24         setBgColor(pane.getComponents(), Color.WHITE);
25
26         JDialog dialog = pane.createDialog(parentComponent, title);
27         dialog.show();
28     }
29
30     private static void setBgColor(Component[] cmps, Color bgColor) {
31         int numComponents = cmps.length;
32         for (int i = 0; i < numComponents; i++) {
33             Component c = cmps[i];
34             if (c instanceof Container) {
35                 setBgColor(((Container) c).getComponents(), bgColor);
36             }
37             c.setBackground(bgColor);
38         }
39     }
40
41     /** Shows a messagedialog with given messsage, title "Message" (= default) and no icon */
42     public static void show(String JavaDoc message) {
43         show(null, message, "Message", JOptionPane.PLAIN_MESSAGE);
44     }
45
46     /** Shows a messagedialog of type ERROR_MESSAGE with given title and message */
47     public static void showError(String JavaDoc title, String JavaDoc message) {
48         show(null, message, title, JOptionPane.ERROR_MESSAGE);
49     }
50
51     /** Shows a messagedialog of type INFORMATION_MESSAGE given with title and message */
52     public static void showInfo(String JavaDoc title, String JavaDoc message) {
53         show(null, message, title, JOptionPane.INFORMATION_MESSAGE);
54     }
55
56     /** Shows a messagedialog of type WARNING_MESSAGE with given title and message */
57     public static void showWarning(String JavaDoc title, String JavaDoc message) {
58         show(null, message, title, JOptionPane.WARNING_MESSAGE);
59     }
60
61 }
62
Popular Tags