package com.ttc;
import java.awt.Button;
import java.awt.Dialog;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.JobAttributes.DialogType;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
public class test6 extends Frame implements ActionListener
{
static Frame frm = new Frame();
static Label welcome = new Label("请关闭对话框");
static Dialog dlg = new Dialog(frm);
static Button Close_btn = new Button("关闭");
static Button Cancel_btn = new Button("取消");
static WinLis wlis = new WinLis();
public static void main (String args[])
{
frm.setTitle("Dialog");
frm.setSize(200,150);
frm.setLocation(200, 200);
welcome.setAlignment(Label.CENTER);
dlg.setTitle("你确定要关闭?");
dlg.setSize(160, 120);
dlg.setLayout(new FlowLayout(FlowLayout.CENTER,5,30));
dlg.add(Close_btn);
dlg.add(Cancel_btn);
Close_btn.addActionListener((ActionListener) frm);
Cancel_btn.addActionListener((ActionListener) frm);
frm.addWindowListener(wlis);
frm.setVisible(true);
}
static class WinLis extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
dlg.setLocation(230, 200);
dlg.show();
}
}
public void actionPerformed(ActionEvent e)
{
Button btn = (Button)e.getSource();
if(btn == Close_btn)
{
dlg.dispose();
frm.dispose();
}
else if(btn == Cancel_btn);
dlg.hide();
}
}
为什么会报
Exception in thread "main" java.lang.ClassCastException: java.awt.Frame
at com.ttc.test6.main(test6.java:33) |