Buenas noches, necesito que al seleccionar ASCENDENTE se muestre el vector ordenado y al seleccionar DESCENDENTE cambie a ese orden pero no se como colocar los metodos de la burbuja para que se muestren en el TextTarea.
Codigo:
<pre lang='java'>
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import javax.swing.*;
public class Taller1 extends Applet implements ActionListener{
JButton ba,bm;
Label l1,lv1;
TextField t1;
TextArea ta;
Panel p1, p2, p3,p4,p5;
Choice Selector;
int a[] = new int[3];
int i = 0;
int contba = 0;
int buffer= 0;
int a1[];
int j;
String burbuja;
public Taller1(){
setLayout(new FlowLayout());
p1 = new Panel(new GridLayout(1,1,10,10));
p2 = new Panel(new GridLayout(1,2,10,10));
p3 = new Panel(new GridLayout(1,3,10,10));
p4 = new Panel(new BorderLayout());
p5 = new Panel(new BorderLayout());
ba = new JButton("AGREGAR");
bm = new JButton("MOSTRAR");
Selector = new Choice();
Selector.addItem( "ORDEN" );
Selector.addItem( "ASCENDENTE" );
Selector.addItem( "DESCENDENTE" );
lv1 = new Label("");
t1 = new TextField();
ta = new TextArea();
ta.setEditable(false);
l1 = new Label("Numero");
p1.add(l1);
p1.add(t1);
p2.add(lv1,BorderLayout.NORTH);
p2.add(p1,BorderLayout.CENTER);
p2.add(Selector,BorderLayout.SOUTH);
p3.add(ba);
p3.add(bm);
p4.add(ta,BorderLayout.NORTH);
p4.add(p3,BorderLayout.SOUTH);
p5.add(p2,BorderLayout.NORTH);
p5.add(p4,BorderLayout.SOUTH);
add(p5);
ba.addActionListener(this);
bm.addActionListener(this);
}
public void actionPerformed(ActionEvent evento){
if(evento.getSource() == ba){
try{
a[i++] = Integer.parseInt(t1.getText());
contba++;
t1.setText(null);
}catch(NumberFormatException nfe){
JOptionPane.showMessageDialog(null,"DEBE INGRESAR NUMEROS");
i--;
t1.setText(null);
}
if(contba==3){
JOptionPane.showMessageDialog(null,"NO SE PUEDE INGRESAR MAS DATOS");
t1.setEnabled(false);
ba.setEnabled(false);
}
}
if (evento.getSource()==bm){
ta.setText("");
for(int k= 0; k < a.length; k++){
ta.append(" "+a[k]);
}
}
for(i = 0; i < a.length; i++)
{
for(j = 0; j < i; j++)
{
if(a[i] < a[j])
{
buffer = a[j];
a[j] = a[i];
a[i] = buffer;
}
}
}
}
public boolean action( Event evt,Object obj ) {
if( evt.target instanceof Choice )
{
burbuja = (String)obj;
repaint();
}
return true;
}
}