

   import java.awt.*;
   import java.awt.event.*;
   import java.beans.*;
   import java.util.*;
   import java.io.*;
   import java.awt.geom.*;
   import javax.swing.*;
   import javax.swing.border.*;


	public class MainFrame extends JFrame implements ActionListener {

	  private Container contentPane;
	  private buttons bot;
	  private JPanel Semana;
	  private JPanel PanelTexto;
	  private JPanel  Horarios;
	  private JTextArea editor;
	  private JPanel fondo;
	  private JPanel titulo;
	  private JLabel label_titulo;
	  private JPanel botones_dia;
	  private JButton Aceptar,Cancelar;
	  JButton Btmp;
	  String s_fecha_file,bloque;
	  Properties Eventos;
	  FileOutputStream out;
	  String A2;
	  Asignador origen;
	  private JLabel profesor;
	  private JCheckBox solo_dia;
	  private JCheckBox semestre;

	   public MainFrame(String s_dia,String s_fecha, String A1, Asignador Origen, Properties P_eventos, JButton Btmp)  {

		 origen =Origen;
		 s_fecha_file = s_fecha;
		 Eventos = P_eventos;
		 A2 = A1;
		this.Btmp=Btmp;

		 setTitle("   "+s_dia+"   "+s_fecha_file); //SETEO DEL TITULO DEL FRAME

		 fondo =new JPanel();
		 fondo.setBackground(Color.orange);

//-----------------------------titulo-------------------------
titulo = new JPanel();
label_titulo = new JLabel();
label_titulo.setText("Seleccione un Bloque");//SE PIDE ELEGIR UN BLOQUE ANTES DE INGRESAR DATOS


label_titulo.setFont(new  Font("Papyrus", Font.BOLD, 16));

titulo.add(label_titulo,BorderLayout.CENTER);
titulo.setBackground(Color.ORANGE);

titulo.setBounds(101,0,300,35);

//------------------------------fin titulo---------------------------------



//------------------------------check box-------------------------------------------------

		Horarios = new JPanel();//CREANDO PANEL
		Horarios.setBackground(Color.orange);
        solo_dia = new JCheckBox("Por esta semana");
		semestre = new JCheckBox("Por el año");			//CRANDO LOS CHECK BOX PARA EL INGERESO DE DATOS
		solo_dia.setBackground(Color.ORANGE);//		COLOREANDO LOS CHECKBOX
		semestre.setBackground(Color.ORANGE);
		Horarios.add(solo_dia);
		Horarios.add(semestre);//AGRGANDO AL PANEL HORARIOS
		Horarios.setBounds(101,107,300,40);

//----------------------------fin check box---------------------------------------------


//-----------------------------------Botones------------------------------------------------


		bot =new buttons();
		bot.setLayout(new GridLayout(7,1));
		bot.setBorder(new javax.swing.border.MatteBorder(new Insets(1 ,1, 1, 1), new  Color(0, 0, 0)));
													// SE DETERMINAN LOS BORDE S Y FONDO DE LOS BOTONES
		bot.setBackground(Color.orange);
		bot.setSize(new Dimension(100,200));
		bot.setBounds(0,0,100,300); //SE CARGAN Y LOCALIZAN LOS BOTOTNES REFERENTES A LOS BLOQUES



///----------------------------------fin botones-------------------------------------




//-----------------------------EDITOR-------------------------------------------------

		PanelTexto = new JPanel();
		PanelTexto.setBackground(Color.orange);

		editor = new JTextArea(); //SE CREA EL AREA DE TEXTO
		editor.setFont(new Font("Papyrus", Font.PLAIN, 12));// se carga la fuente con la que se escribira en esta area
		editor.setBorder(BorderFactory.createEtchedBorder());
		//editor.setSize(new Dimension(100,200));//
		editor.setText("Seleccione un Bloque");
		editor.setEnabled(false);
		editor.setPreferredSize(new Dimension(200,25));// DETERMINANDO EL TAMAÑO DEL AREA
		profesor=new JLabel();// SE CREA UN Label en el c ual se escribirá lo que se pide en el JTextArea
		profesor.setText("Profesor responsable");
		PanelTexto.add(profesor,BorderLayout.NORTH); //se ASIGNAN LOS LUGARES DE ESTOS OBJETOS DENTRO DEL PANEL EDITOR
		PanelTexto.add(editor,BorderLayout.SOUTH);
		PanelTexto.setBounds(101,36,300,70);//SE DETALLA DONDE Y QUE TAMAÑO DEBE TENER ESTE PANEL DENTRO DEL FRAME PRINCIPAL

//-----------------------------END EDITOR--------------------------------------------
//----------------------------botones de dia-------------------------------

botones_dia=new JPanel();
Aceptar = new JButton("ACEPTAR");		//CREANDO BOTONES
Cancelar = new JButton("CANCELAR");
botones_dia.add(Aceptar,BorderLayout.WEST);
botones_dia.add(Cancelar,BorderLayout.EAST);
Aceptar.setActionCommand("Aceptar");		//SETEANDO LAS ACCIO NES
Aceptar.addActionListener(this);
Cancelar.setActionCommand("Cancelar");
Cancelar.addActionListener(this);
botones_dia.setBackground(Color.orange); //SE PINTAN LOS BOTONES
botones_dia.setBounds(101,147,300,70);



//----------------------------fin botones de dia-------------------------------
		bot.setBackground(Color.black);

		getContentPane().add(botones_dia);
		getContentPane().add(titulo);
		getContentPane().add(PanelTexto);
		getContentPane().add(Horarios);
		getContentPane().add(bot);
		getContentPane().add(fondo);

		bot.b1_2.addActionListener(this);
		bot.b3_4.addActionListener(this);//  AGRAGANDO LOS BOTONES AL ACTIONLISTENER
		bot.b5_6.addActionListener(this);
		bot.b7_8.addActionListener(this);
		bot.b9_10.addActionListener(this);
		bot.b11_12.addActionListener(this);
		bot.b13_14.addActionListener(this);

	   }
	  //----------------------------------implementacion de actionListener---------------------------------

	   public void actionPerformed(ActionEvent e)
					 {
						editor.setEnabled(true); //se habilita el area de texto

						String boton_presioando=new String("."+e.getActionCommand().toString());
					 					//seteando accion  de los botones.
				if ("Cancelar".equals(e.getActionCommand()))
				{
					Btmp.setForeground(Color.black);
							Eventos.put(s_fecha_file, "");
							try{
							   out = new FileOutputStream (A2+".bd");  //se crea el archivo de salida "año.bd"
							   Eventos.store(out, "Eventos");
							} catch (FileNotFoundException ex) {
							   System.err.println("\nOUTPUT FILE STREAM:\n" + ex);
							} catch (IOException ea) {
								System.err.println("\nOUTPUT FILE STREAM:\n" + ea);
							}
					this.dispose();//se cierra la ventana al apretar el boton CANCELAR

						}
				if ("Aceptar".equals(e.getActionCommand()))
				{
					String temp=new String("");
					String temp1=new String("");
					if((editor.getText().length()) == 0) Btmp.setForeground(Color.black);
					else {Btmp.setForeground(Color.red);
					}
					{	Eventos.put(s_fecha_file, editor.getText());
						Eventos.put(s_fecha_file+bloque, editor.getText());

					}
					if((semestre.isSelected())==true)
					{

						for (int i=1;i<10;i++)
						{
							temp=(String)(s_fecha_file.charAt(0)+""+s_fecha_file.charAt(1)+"."+"0"+i+"."+s_fecha_file.charAt(6)+s_fecha_file.charAt(7));
							temp1=temp+bloque;
							Eventos.put(temp,editor.getText());    //SE GUADA PARA LOS MESES DE 1 A 10
							Eventos.put(temp1,editor.getText());

						}
						for (int i=10;i<13;i++)
						{
							temp=(String)(s_fecha_file.charAt(0)+""+s_fecha_file.charAt(1)+"."+i+"."+s_fecha_file.charAt(6)+s_fecha_file.charAt(7));
							temp1=temp+bloque;
							Eventos.put(temp,editor.getText());// PARA LOS MESES DEL 10 AL 12
							Eventos.put(temp1,editor.getText());
							//se guarda en dos formatos, uno es para no alterar la manipulacion clase madre,
						    //y el otro es para manipulacion local
						}
						repaint();

					}

						try{
						   out = new FileOutputStream (A2+".bd");
						   Eventos.store(out, "Eventos");
					    	} catch (FileNotFoundException ex) {
						   System.err.println("\nOUTPUT FILE STREAM:\n" + ex);
							} catch (IOException ea) {			//	SE CAPTURA LAS EXEPCIONES POR ERROREES EN LA ESCRITURA ENLOS ARCHIVOS
						   System.err.println("\nOUTPUT FILE STREAM:\n" + ea);
							}
							repaint();	//REPINTANDO TODO DE NUEVO
							this.dispose();//se cierra la ventana al apretar el boton ACEPTAR
				}

				if ("b1_2".equals(e.getActionCommand()))
				{

					bloque=boton_presioando;
					label_titulo.setText("Asignación bloque 1-2");  // SE CAMBIA EL TITULO PARA AVISAR QUE YA SE PUEDE INGRESAR LOS DATOS
					editor.setText(Eventos.getProperty(s_fecha_file+bloque));  // SE RECUPERNA LOS DATOS DELARCHIVO
					repaint();											//GUARDADOS ANTERIORMENTE


								}
				if ("b3_4".equals(e.getActionCommand()))
				{
					//bloque=".b3_4";
					bloque=boton_presioando;//CAPTURANDO EL NOMBRE DEL BOTON PARA CARGAR DESPUES LO ESCRITO EN ESE HORARIO
					label_titulo.setText("Asignación bloque 3-4");
					editor.setText(Eventos.getProperty(s_fecha_file+bloque));
																			//SE CARGAN LAS ASIGNACIONES ANTEROIRMENTE HECHAS
					repaint();

										}
				if ("b5_6".equals(e.getActionCommand()))
				{
					bloque=boton_presioando;
					label_titulo.setText("Asignación bloque 5-6");
					editor.setText(Eventos.getProperty(s_fecha_file+bloque));
						//					SE CARGAN LAS ASIGNACIONES ANTEROIRMENTE HECHAS
					repaint();
										}
				if ("b7_8".equals(e.getActionCommand()))
				{
					bloque=boton_presioando;
					label_titulo.setText("Asignación bloque 7-8");
					editor.setText(Eventos.getProperty(s_fecha_file+bloque));
//					SE CARGAN LAS ASIGNACIONES ANTEROIRMENTE HECHAS
					repaint();
										}
				if ("b9_10".equals(e.getActionCommand()))
				{
					bloque=boton_presioando;
					label_titulo.setText("Asignación bloque 9-10");
					editor.setText(Eventos.getProperty(s_fecha_file+bloque));
//					SE CARGAN LAS ASIGNACIONES ANTEROIRMENTE HECHAS
					repaint();
										}
				if ("b11_12".equals(e.getActionCommand()))
				{
					bloque=boton_presioando;
					label_titulo.setText("Asignación bloque 11-12");
//					SE CARGAN LAS ASIGNACIONES ANTEROIRMENTE HECHAS
					editor.setText(Eventos.getProperty(s_fecha_file+bloque));
					repaint();
										}
				if ("b13_14".equals(e.getActionCommand()))
				{
					bloque=boton_presioando;
					label_titulo.setText("Asignación bloque 13-14");

					editor.setText(Eventos.getProperty(s_fecha_file+bloque));
//					SE CARGAN LAS ASIGNACIONES ANTEROIRMENTE HECHAS
					repaint();}


			 }
   }