java自定义的异常类为什么没有显示出错的对话框?跪求解释
importjava.awt.*;importjava.awt.event.*;importjavax.swing.*;importjavax.swing.event.C...
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
public class Shiyan extends JFrame implements ActionListener
{ private static JTextArea text_1;
private static JLabel jl1;
private JLabel jl2;
private JButton bt1,bt2,bt3,bt4;
private JComboBox cbx;
static JPanel pane2=new JPanel(new GridLayout(1,2));
static JPanel pane1=new JPanel(new GridLayout(1,2));
public Shiyan() throws MyException
{
super("猫狗小虎威");
Container contentPane = getContentPane();
this.setLocation(200,200);
this.setBounds(300,240,360,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(new GridLayout(5,1));
text_1=new JTextArea(4,4);
//text_1.addMouseListener();
//JPanel pane1=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane1);
//JPanel pane2=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane2);
JPanel pane3=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane3);
JPanel pane4=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane4);
pane2.add(text_1);
JLabel jl1=new JLabel(" ——————异常处理部分——————");
pane1.add(jl1);
JLabel jl2=new JLabel("标签B");
pane2.add(jl2);
bt1=new JButton("按钮bt1");
bt1.addActionListener(this);
pane3.add(bt1);
setVisible(true);
JComboBox jc = new JComboBox();
pane3.add(jc);
jc.addItem("英文单词");
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==bt1)
{if(text_1.getText().equals("123"))
try {
throw new MyException("错误:输入不可以是123啊");
} catch (MyException e1) {
// TODO Auto-generated catch block
;
}
}
} 展开
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.CaretEvent;
import javax.swing.event.CaretListener;
public class Shiyan extends JFrame implements ActionListener
{ private static JTextArea text_1;
private static JLabel jl1;
private JLabel jl2;
private JButton bt1,bt2,bt3,bt4;
private JComboBox cbx;
static JPanel pane2=new JPanel(new GridLayout(1,2));
static JPanel pane1=new JPanel(new GridLayout(1,2));
public Shiyan() throws MyException
{
super("猫狗小虎威");
Container contentPane = getContentPane();
this.setLocation(200,200);
this.setBounds(300,240,360,200);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.getContentPane().setLayout(new GridLayout(5,1));
text_1=new JTextArea(4,4);
//text_1.addMouseListener();
//JPanel pane1=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane1);
//JPanel pane2=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane2);
JPanel pane3=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane3);
JPanel pane4=new JPanel(new GridLayout(1,2));
this.getContentPane().add(pane4);
pane2.add(text_1);
JLabel jl1=new JLabel(" ——————异常处理部分——————");
pane1.add(jl1);
JLabel jl2=new JLabel("标签B");
pane2.add(jl2);
bt1=new JButton("按钮bt1");
bt1.addActionListener(this);
pane3.add(bt1);
setVisible(true);
JComboBox jc = new JComboBox();
pane3.add(jc);
jc.addItem("英文单词");
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{if(e.getSource()==bt1)
{if(text_1.getText().equals("123"))
try {
throw new MyException("错误:输入不可以是123啊");
} catch (MyException e1) {
// TODO Auto-generated catch block
;
}
}
} 展开
4个回答
2012-07-14
展开全部
没有使用对话框。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询