Bom consegui criar a classe, porém ainda não consigo fazer os botões da tela funciona. Estou usando o NetBeans para fazer.
Deêm uma olhada de como está ficando o código.
Classe:
[code]public class Ordenacao {
public static void SelectionSort(int[] v) { //Declaração do método de seleção
int index_min,
aux;
for (int i = 0; i < v.length; i++) { // Para i = 0, i maior que v.tamanho, i soma mais um
index_min = i;
for (int j = i + 1; j < v.length; j++) {
if (v[j] < v[index_min]) {
index_min = j;
}
}
if (index_min != i) {
aux = v[index_min];
v[index_min] = v[i];
v[i] = aux;
}
}
}
public static void insertionSort(int[] array) {
for (int i = 1; i < array.length; i++)
{
int a = array[i];
int j;
for (j = i - 1; j >= 0 && array[j] > a; j--)
{
array[j + 1] = array[j];
array[j] = a;
}
}
}
public static void quick_sort(int []v,int ini, int fim) {
int meio;
if (ini < fim) {
meio = partition(v, ini, fim);
quick_sort(v, ini, meio);
quick_sort(v, meio + 1, fim);
}
}
public static int partition(int []v, int ini, int fim) {
int pivo, topo, i;
pivo = v[ini];
topo = ini;
for (i = ini + 1; i < fim; i++) {
if (v[i] < pivo) {
v[topo] = v[i];
v[i] = v[topo + 1];
topo++;
}
}
v[topo] = pivo;
return topo;
}
}[/code]
Tela:
[code]public class Order extends javax.swing.JFrame {
public Order() {
initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
OrdenacaoDeDados = new javax.swing.JPanel();
insercao = new javax.swing.JButton();
selecao = new javax.swing.JButton();
Quicksort = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
OrdenacaoDeDados.setBackground(new java.awt.Color(255, 255, 255));
OrdenacaoDeDados.setBorder(javax.swing.BorderFactory.createEtchedBorder());
insercao.setText("Inserção");
insercao.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
insercaoActionPerformed(evt);
}
});
selecao.setText("Seleção");
selecao.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
selecaoActionPerformed(evt);
}
});
Quicksort.setText("Quicksort");
javax.swing.GroupLayout OrdenacaoDeDadosLayout = new javax.swing.GroupLayout(OrdenacaoDeDados);
OrdenacaoDeDados.setLayout(OrdenacaoDeDadosLayout);
OrdenacaoDeDadosLayout.setHorizontalGroup(
OrdenacaoDeDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(OrdenacaoDeDadosLayout.createSequentialGroup()
.addContainerGap()
.addComponent(insercao)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(selecao)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(Quicksort)
.addContainerGap(125, Short.MAX_VALUE))
);
OrdenacaoDeDadosLayout.setVerticalGroup(
OrdenacaoDeDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, OrdenacaoDeDadosLayout.createSequentialGroup()
.addContainerGap(95, Short.MAX_VALUE)
.addGroup(OrdenacaoDeDadosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(insercao)
.addComponent(selecao)
.addComponent(Quicksort))
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(OrdenacaoDeDados, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(82, 82, 82)
.addComponent(OrdenacaoDeDados, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(85, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void insercaoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
private void selecaoActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
/*
* Set the Nimbus look and feel
*/
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/*
* If Nimbus (introduced in Java SE 6) is not available, stay with the
* default look and feel. For details see
* http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(Order.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(Order.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(Order.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Order.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>
/*
* Create and display the form
*/
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new Order().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JPanel OrdenacaoDeDados;
private javax.swing.JButton Quicksort;
private javax.swing.JButton insercao;
private javax.swing.JButton selecao;
// End of variables declaration
}[/code]