Duvida em vetor e swing

0 respostas
A

eu criei essas duas classes e estou usando swing eu tenho que criar um vetor para coloca-lo em ordem, pegar o maior o menor e depois inverter a posição deles e no momento só consegui criar o vetor e mostra-lo no swing

import java.*;

public class Lista {	

public int maxSize;

private int [] intLista, intmaior;
public Lista (int s){
	maxSize = s;
	intLista = new int [maxSize];
	intmaior = new int[10];
}

public void carrega (){
	for (int i = 0; i < maxSize; i++)
		intLista [i] = (int) (Math.random()*10 );
		
}

	
public void mostra (){
	for (int i = 0; i < maxSize; i++)
		
		System.out.println(intLista[i]);
}

public int getmaxSize (){
	return maxSize;
}

public  int getElementodovetor (int p){
	return intLista [p];
}

public static void main (String args []){
	Lista L = new Lista(10);
	L.carrega();
	L.mostra();
	
}

}


import java.awt.<em>;

import java.awt.event.</em>;

import javax.swing.*;

public class Lista1 extends JFrame implements ActionListener {

JButton btncarrega;

JButton btnresultado;

JButton btnordem;

JButton btnmenor;

JButton btnmaior;

JButton btninverte;

JButton btnlimpa;

JTextField edtmaior;

JTextField edtmenor;

JTextField edtordem;

JTextField edtinverte;

JTextField edtresultado;

JTextField edtnumero;

Lista objListaDos;
Lista1 (){

setTitle (CAlculo de Fibonacci);

setBounds (200,250,800,150);

getContentPane().setLayout (new GridLayout (3,2));
btncarrega = new JButton (Carrega);

btnresultado= new JButton (Resultado);

btnordem= new JButton (" Colocar em Ordem");

btnmenor= new JButton (" Menor “);

btnmaior= new JButton ( Maior");

btnlimpa= new JButton (" Limpa “);

btninverte= new JButton ( Inverte ");

edtmaior= new JTextField (20);

edtmenor= new JTextField (20);

edtordem= new JTextField (20);

edtinverte= new JTextField (20);

edtresultado = new JTextField (20);

edtnumero = new JTextField (20);

objListaDos = new Lista (10);

edtresultado.setEditable(false);
getContentPane().add (btncarrega);

getContentPane().add (edtresultado);
getContentPane().add (btnresultado);

getContentPane().add (edtmaior);

getContentPane().add (edtinverte);

getContentPane().add (edtmenor);

getContentPane().add (edtordem);
getContentPane().add (btnmaior);

getContentPane().add (btnmenor);

getContentPane().add (btninverte);

getContentPane().add (btnordem);

getContentPane().add (btnlimpa);

edtresultado.setBackground (Color. yellow);

edtmaior.setBackground (Color. green);
btncarrega.addActionListener (this);

btnresultado.addActionListener (this);

btnlimpa.addActionListener (this);

setDefaultCloseOperation (EXIT_ON_CLOSE);
}

public void actionPerformed (ActionEvent e){

if (e.getSource()==btncarrega)
	objListaDos.carrega ();

 if (e.getSource()==btnlimpa){

edtresultado.setText("");
edtmaior.setText("");
edtmenor.setText("");
edtinverte.setText("");	
edtordem.setText("");
}


if (e.getSource()==btnresultado){

		
for (int i=0; i &lt; objListaDos.getmaxSize(); i++){
	edtresultado.setText(edtresultado.getText()+ " -" + objListaDos.getElementodovetor(i));
}
}

}

public static void main (String args[]){

JFrame janela = new Lista1 ();
janela.setVisible(true);

}

}

Criado 7 de setembro de 2006
Respostas 0
Participantes 1