
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class DialogRecordName extends JDialog implements ActionListener{
	private JLabel msg;
	JTextField name;
	private JButton OK;
	private JButton cancel;
	private int option=0;

	public DialogRecordName(MineFrame parent, int second,int grade){
		super(parent, "",JDialog.ModalityType.APPLICATION_MODAL);	

		switch(grade){
		case Grade.LOWER: 
			setTitle("ɼ¼");
			break;
		case Grade.MEDIAL: 
			setTitle("мɼ¼");
			break;
		case Grade.HIGHER: 
			setTitle("߼ɼ¼");
			break;
		}
		msg = new JLabel("ĳɼǣ" + second + "룬ԭм¼֡");
		name =  new JTextField(20);
		OK = new JButton("ȷ");
		cancel = new JButton("ȡ");
		OK.addActionListener(this);
		cancel.addActionListener(this);
		
		this.setLayout(new GridLayout(2,1));
		
		this.add(msg);
		JPanel downPanel = new JPanel();
		downPanel.add(name);
		downPanel.add(OK);
		downPanel.add(cancel);
		this.add(downPanel);
		this.pack();
		this.setLocationRelativeTo(parent);
		//setVisible(true);
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getSource().equals(OK)){
			option=1;
			dispose();
		}
		else{
			option=0;
			dispose();
		}
	}
	public int openDialog() {
        this.setVisible(true);
        return option;
    }
}
