View Javadoc

1   package net.sf.mmapps.applications.developer.dialog;
2   
3   import java.awt.*;
4   import java.awt.event.*;
5   import java.io.*;
6   
7   import javax.swing.*;
8   /***
9    *
10   * @author Kees Jongenburger
11   * @version $Id: ExceptionDialog.java,v 1.1.1.1 2004/02/06 08:44:07 keesj Exp $
12   **/
13  public class ExceptionDialog extends JDialog implements ActionListener{
14      
15      /*** Creates a new instance of ExceptionDialog */
16      public ExceptionDialog(Frame parent ,String message,Throwable t) {
17          super(parent, true);
18  
19  	JLabel jLabel = new JLabel(message);
20  	getContentPane().add(jLabel,BorderLayout.NORTH);
21  	JTextArea textArea = new JTextArea(10,60);
22  
23  	StringWriter st = new StringWriter();
24  	PrintWriter p = new PrintWriter(st);
25  	t.printStackTrace(p);
26  	textArea.setText(st.toString());
27  	JScrollPane sp = new JScrollPane();
28          
29  	sp.setViewportView(textArea);
30  	getContentPane().add(sp,BorderLayout.CENTER);
31          
32          
33          JPanel jPanel = new JPanel();
34          jPanel.setLayout(new FlowLayout(FlowLayout.CENTER));
35          JButton button = new JButton("ok");
36          button.addActionListener(this);
37          jPanel.add(button);
38          getContentPane().add(jPanel,BorderLayout.SOUTH);
39  	pack();
40          addWindowListener(new java.awt.event.WindowAdapter() {
41              public void windowClosing(java.awt.event.WindowEvent evt) {
42                  closeDialog();
43              }
44          });
45          setName("Exception dialog");
46      }
47  
48      public void show(){
49          Dimension dim = getOwner().getSize();
50          Point point = getOwner().getLocation();
51          setLocation(point.x + (dim.width /2) - getWidth() /2, point.y +(dim.height /2) - getHeight()/ 2);
52          super.show();
53      }
54      
55      private void closeDialog() {
56          setVisible(false);
57          dispose();
58      }
59      public void actionPerformed(ActionEvent event){
60          closeDialog();
61      }
62  }