import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Thepvc extends Frame
implements WindowListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
Button design,open1,open2,reset;
TextArea text;
Box basebox ,box1,box2, box3;
FileDialog filedialog_load;//声明两个文件对话框
Thepvc()
{
design=new Button("设计");
open1=new Button("打开");
open1.addActionListener((ActionListener) this);
open2=new Button("打开");
open2.addActionListener((ActionListener) this);
filedialog_load=new FileDialog(this ,"打开文件对话框",FileDialog.SAVE);
filedialog_load.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
filedialog_load.setVisible(false);
}
});
reset=new Button("复位");
box1=Box.createVerticalBox();
box1.add(new Label("第一步 导入人员资料 "));
box1.add(Box.createVerticalStrut(2));
box1.add(new Label("第二步 选择照片位置 "));
box1.add(Box.createVerticalStrut(2));
box1.add(new Label("进行证卡验证"));
box2=Box.createVerticalBox();
box2.add(new TextField(30));
box2.add(Box.createVerticalStrut(2));
box2.add(new TextField(30));
box2.add(Box.createVerticalStrut(2));
box2.add(design);
box3=Box.createVerticalBox();
box3.add(open1);
box3.add(Box.createVerticalStrut(2));
box3.add(open2);
box3.add(Box.createVerticalStrut(2));
box3.add(reset);
basebox=Box.createHorizontalBox();
basebox.add(box1);
basebox.add(Box.createHorizontalStrut(2));
basebox.add(box2);
basebox.add(Box.createHorizontalStrut(2));
basebox.add(box3);
basebox.add(text);
text=new TextArea(12,12);
add(basebox);
setLayout(new FlowLayout());
setBounds(0,0,600,600);
setVisible(true);
addWindowListener(this);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==open1||e.getSource()==open2)
{
filedialog_load.setVisible(true);
String name=filedialog_load.getFile();
if(name!=null)
{
text.setText("");
}
}
}
public void windowActivated(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{ setBounds(0,0,400,400);
validate();
}
public void windowClosing(WindowEvent e)
{
dispose();
}
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
public void windowIconified(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
setBounds(0,0,400,400);
validate();
}
public void windowOpened(WindowEvent e){}
}
public class Thepv
{
public static void main(String args[])
{
Thepvc thepvc=new Thepvc();
}
}
import java.awt.*;
import java.awt.event.*;
class Thepvc extends Frame
implements WindowListener
{
/**
*
*/
private static final long serialVersionUID = 1L;
Button design,open1,open2,reset;
TextArea text;
Box basebox ,box1,box2, box3;
FileDialog filedialog_load;//声明两个文件对话框
Thepvc()
{
design=new Button("设计");
open1=new Button("打开");
open1.addActionListener((ActionListener) this);
open2=new Button("打开");
open2.addActionListener((ActionListener) this);
filedialog_load=new FileDialog(this ,"打开文件对话框",FileDialog.SAVE);
filedialog_load.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
filedialog_load.setVisible(false);
}
});
reset=new Button("复位");
box1=Box.createVerticalBox();
box1.add(new Label("第一步 导入人员资料 "));
box1.add(Box.createVerticalStrut(2));
box1.add(new Label("第二步 选择照片位置 "));
box1.add(Box.createVerticalStrut(2));
box1.add(new Label("进行证卡验证"));
box2=Box.createVerticalBox();
box2.add(new TextField(30));
box2.add(Box.createVerticalStrut(2));
box2.add(new TextField(30));
box2.add(Box.createVerticalStrut(2));
box2.add(design);
box3=Box.createVerticalBox();
box3.add(open1);
box3.add(Box.createVerticalStrut(2));
box3.add(open2);
box3.add(Box.createVerticalStrut(2));
box3.add(reset);
basebox=Box.createHorizontalBox();
basebox.add(box1);
basebox.add(Box.createHorizontalStrut(2));
basebox.add(box2);
basebox.add(Box.createHorizontalStrut(2));
basebox.add(box3);
basebox.add(text);
text=new TextArea(12,12);
add(basebox);
setLayout(new FlowLayout());
setBounds(0,0,600,600);
setVisible(true);
addWindowListener(this);
validate();
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==open1||e.getSource()==open2)
{
filedialog_load.setVisible(true);
String name=filedialog_load.getFile();
if(name!=null)
{
text.setText("");
}
}
}
public void windowActivated(WindowEvent e)
{
}
public void windowDeactivated(WindowEvent e)
{ setBounds(0,0,400,400);
validate();
}
public void windowClosing(WindowEvent e)
{
dispose();
}
public void windowClosed(WindowEvent e)
{
System.exit(0);
}
public void windowIconified(WindowEvent e)
{
}
public void windowDeiconified(WindowEvent e)
{
setBounds(0,0,400,400);
validate();
}
public void windowOpened(WindowEvent e){}
}
public class Thepv
{
public static void main(String args[])
{
Thepvc thepvc=new Thepvc();
}
}
design = new Button("设计");
open1 = new Button("打开");
open1.addActionListener((ActionListener) this); 《===== 这里addActionListener 函数需要的是java.awt.event.ActionListener
而 ThePvc实现的是java.awt.event.WindowListener