/* Proyecto Final de las materias Topicos Selectos de Programacion y Estructura de Datos/
* Programa de intercalacion directa en swing.
* Fuente: .....------ Conocimientos adquiridos e investigacion en distintas fuentes ------.....
*********************************************
* InGeNiErIa En SiStEmAs CoMpUtAcIoNaLeS *
* InStItUtO tEcNoLoGiCo SuPeRiOr De JeReZ *
* EsTrUcTuRa De DaToS *
* ErNeStO rOsAlEs CaRlOs *
* ernestorosales@live.com *
*********************************************
*/
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
class IntercalacionDirectaSwing extends JFrame
{
JLabel l1,l2;
JTextField t1;
JButton b1;
public IntercalacionDirectaSwing()
{
setSize(300,350);
setTitle("Intercalacion Directa");
setVisible(true);
setDefaultCloseOperation(HIDE_ON_CLOSE);
setLocationRelativeTo(null);
Container contenedor=getContentPane();
contenedor.setLayout(new FlowLayout());
l1=new JLabel("Programa de Intercalacion Directa");
contenedor.add(l1);
l2=new JLabel("Tamano de vector");
contenedor.add(l2);
t1=new JTextField(10);
contenedor.add(t1);
b1=new JButton("HaCeR");
contenedor.add(b1);
ManejadorCamposTexto m=new ManejadorCamposTexto();
b1.addActionListener(m);
}
private static void Inter(int[] Arreglo1, int[] Arreglo2, int[] Arreglo3)
{
int Indice1=0;
int Indice2=0;
int Indice3=0;
while(Indice1<Arreglo1.length && Indice2<Arreglo2.length)
{
if(Arreglo1[Indice1]<Arreglo2[Indice2])
{
Arreglo3[Indice3]=Arreglo1[Indice1] ;
Indice1++;
}
else
{
Arreglo3[Indice3]=Arreglo2[Indice2];
Indice2++;
}
Indice3++;
}
if(Indice1<Arreglo1.length)
System.arraycopy(Arreglo1,Indice1,Arreglo3,Indice3,Arreglo1.length-Indice1);
else
System.arraycopy(Arreglo2,Indice2,Arreglo3,Indice3,Arreglo2.length-Indice2);
}
public static void erc(int arre[])
{
if(arre.length<=1)
return;
int tamano1=arre.length/2;
int tamano2=arre.length-tamano1;
int PrimeraMitad[]=new int[tamano1];
int SegundaMitad[]=new int[tamano2];
System.arraycopy(arre,0,PrimeraMitad,0,tamano1);
System.arraycopy(arre,tamano1,SegundaMitad,0,tamano2);
erc(PrimeraMitad);
erc(SegundaMitad);
IntercalacionDirectaSwing.Inter(PrimeraMitad,SegundaMitad,arre);
}
public static void main (String args[])
{
new IntercalacionDirectaSwing();
}
private class ManejadorCamposTexto implements ActionListener
{
public void actionPerformed(ActionEvent evento)
{
if(evento.getSource()==b1)
{
if(t1.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Ingresa Dato");
}
else
{
String nt=t1.getText();
int t=Integer.parseInt(nt);
int[] v=new int[t];
for(int i=0;i<t;i++)
{
v[i]=Integer.parseInt(JOptionPane.showInputDialog("Ingresa dato "+(i+1)+" : "));
}
t1.setText("");
IntercalacionDirectaSwing.erc(v);
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<< Codigo obtenido de la pag:
//***************************** http://www.daniweb.com/forums/thread14841.html
//***************************** Permite imprimir el arreglo en un Mensaje de dialogo.
StringBuilder builder = new StringBuilder(v.length);
for (int i=0;i<v.length;builder.append(v[i++])) builder.append(" ");
JOptionPane.showMessageDialog(null, builder.toString(), "Datos en Orden", JOptionPane.INFORMATION_MESSAGE);
}
}
}
}
}
No hay comentarios:
Publicar un comentario