📄 exceptiondialog.java
字号:
package com.cownew.PIS.ui.ctrl.dialog;
import java.awt.BorderLayout;
import java.awt.HeadlessException;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.cownew.PIS.framework.client.MainFrame;
import com.cownew.ctk.common.StringUtils;
import com.cownew.ctk.ui.swing.SwingUtils;
public class ExceptionDialog extends JDialog
{
private static final String DEFAULTDESC = "系统运行发生未知错误,请将下面的错误信息发送给开发人员!";
private static final long serialVersionUID = 1L;
private JPanel jContentPane = null;
private JTextArea txtMsg = null;
private JScrollPane jScrollPane = null;
private JTextArea txtStackTrace = null;
private JButton btnClose = null;
private JButton btnCopyStackTrace = null;
public ExceptionDialog() throws HeadlessException
{
super(MainFrame.getMainFrame());
initialize();
}
/**
* This method initializes this
*
* @return void
*/
private void initialize()
{
this.setSize(559, 258);
this.setTitle("错误");
this.setContentPane(getJContentPane());
}
/**
* This method initializes jContentPane
*
* @return javax.swing.JPanel
*/
private JPanel getJContentPane()
{
if (jContentPane == null)
{
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getTxtMsg(), null);
jContentPane.add(getJScrollPane(), null);
jContentPane.add(getBtnClose(), null);
jContentPane.add(getBtnCopyStackTrace(), null);
jContentPane.setLayout(new BorderLayout());
}
return jContentPane;
}
/**
* This method initializes txtMsg
*
* @return javax.swing.JTextArea
*/
private JTextArea getTxtMsg()
{
if (txtMsg == null)
{
txtMsg = new JTextArea();
txtMsg.setBounds(new Rectangle(20, 20, 518, 33));
txtMsg.setEditable(false);
txtMsg.setLineWrap(true);
txtMsg.setWrapStyleWord(true);
txtMsg.setBackground(getBackground());
txtMsg.setText(DEFAULTDESC);
}
return txtMsg;
}
/**
* This method initializes jScrollPane
*
* @return javax.swing.JScrollPane
*/
private JScrollPane getJScrollPane()
{
if (jScrollPane == null)
{
jScrollPane = new JScrollPane();
jScrollPane.setBounds(new Rectangle(21, 62, 521, 129));
jScrollPane.setViewportView(getTxtStackTrace());
}
return jScrollPane;
}
/**
* This method initializes txtStackTrace
*
* @return javax.swing.JTextArea
*/
private JTextArea getTxtStackTrace()
{
if (txtStackTrace == null)
{
txtStackTrace = new JTextArea();
txtStackTrace.setLineWrap(true);
}
return txtStackTrace;
}
/**
* This method initializes btnClose
*
* @return javax.swing.JButton
*/
private JButton getBtnClose()
{
if (btnClose == null)
{
btnClose = new JButton();
btnClose.setBounds(new Rectangle(69, 195, 97, 23));
btnClose.setText("关闭");
btnClose.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e)
{
btnClose_actionPerformed(e);
}
});
}
return btnClose;
}
/**
* This method initializes btnCopyStackTrace
*
* @return javax.swing.JButton
*/
private JButton getBtnCopyStackTrace()
{
if (btnCopyStackTrace == null)
{
btnCopyStackTrace = new JButton();
btnCopyStackTrace.setBounds(new Rectangle(384, 196, 113, 24));
btnCopyStackTrace.setText("复制错误信息");
btnCopyStackTrace
.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e)
{
btnCopyStackTrace_actionPerformed(e);
}
});
}
return btnCopyStackTrace;
}
protected void btnCopyStackTrace_actionPerformed(ActionEvent e)
{
txtStackTrace.selectAll();
txtStackTrace.copy();
}
protected void btnClose_actionPerformed(ActionEvent e)
{
dispose();
}
public void setException(Throwable t)
{
txtStackTrace.setText(StringUtils.stackToString(t));
txtStackTrace.setCaretPosition(0);
}
public void setDescription(String desc)
{
txtMsg.setText(desc);
}
public static void showException(Throwable t)
{
ExceptionDialog dlg = new ExceptionDialog();
dlg.setModal(true);
dlg.setDescription(DEFAULTDESC);
dlg.setException(t);
SwingUtils.centerAtScreen(dlg);
dlg.show();
}
public static void showException(Throwable t,String desc)
{
ExceptionDialog dlg = new ExceptionDialog();
dlg.setModal(true);
dlg.setDescription(desc);
dlg.setException(t);
SwingUtils.centerAtScreen(dlg);
dlg.show();
}
} // @jve:decl-index=0:visual-constraint="10,10"
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -