Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 53770ba

Browse files
author
javiluli
committed
Modifico los metodos para mostrar el tiempo
1 parent 272166c commit 53770ba

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

‎ordenaciones.jar

87 Bytes
Binary file not shown.

‎src/principal/Main.java

Lines changed: 52 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@ public class Main extends Sorts {
4242
private final Panel panelVisorMemoria = new Panel();
4343
// COMBOBOX
4444
private final JComboBox<String> comboBoxTipoSort = new JComboBox<String>(nombreAlgoritmos);
45-
// private JComboBox<String> comboBoxTipoSort = new JComboBox<String>();
46-
4745
// JLABEL
4846
private final JLabel lblTitleAlgoritmo = new JLabel("Algoritmo de ordenacion");
4947
private final JLabel lblTitle = new JLabel("Panel de control");
5048
private JLabel lblNumeroBarras = new JLabel("Numero de barras");
5149
private JLabel lblRetardo = new JLabel("Retardo: 1 ms");
52-
private static JLabel lblTiempo = new JLabel("Tiempo: 0 s 0 ms");
50+
private static JLabel lblTiempo = new JLabel("Tiempo: 0 m 0 s 0 ms");
5351
private static JLabel lblMemoriaUsada = new JLabel("Memoria usada: 0 MB");
5452
private static JLabel lblMemoriaMax = new JLabel("Memoria maxima: 0 MB");
5553
private static JLabel lblMemoriaLibre = new JLabel("Memoria libre: 0 MB");
@@ -84,6 +82,7 @@ public static void main(String[] args) {
8482
} catch (Exception e) {
8583
}
8684
}
85+
// ---------------------------------------------------------------------------------------------
8786

8887
public Main() {
8988
}
@@ -99,6 +98,7 @@ public Main() {
9998
Main(Sorts sorts) {
10099
this.sorts = sorts;
101100
}
101+
// ---------------------------------------------------------------------------------------------
102102

103103
public void main() {
104104
initialize();
@@ -108,11 +108,12 @@ public void main() {
108108
getPanelBarras().add(barras);
109109
barras.setLayout(null);
110110
getPanelBarras().setVisible(true);
111-
frame.setTitle("Visualizador de prdenacion de matrices");
111+
frame.setTitle("Visualizador de ordenacion de matrices");
112112
frame.setResizable(false);
113113
frame.setVisible(true);
114114
sorting();
115115
}
116+
// ---------------------------------------------------------------------------------------------
116117

117118
private void initialize() {
118119
final Color BLACK_SECUNDARIO = new Color(15, 15, 15);
@@ -359,6 +360,7 @@ public void actionPerformed(ActionEvent e) {
359360
lblTitle.setFont(new Font("Arial", Font.BOLD, 18));
360361
panelMenu.add(lblTitle);
361362
}
363+
// ---------------------------------------------------------------------------------------------
362364

363365
/**
364366
* Seleccion se cada uno de los metodos de ordenacion.
@@ -415,6 +417,7 @@ public void sorting() {
415417
reinicio();
416418
pausa();
417419
}
420+
// ---------------------------------------------------------------------------------------------
418421

419422
/**
420423
* Pinta los textos debidamente actualizados en funcion del metodo de
@@ -426,6 +429,7 @@ public void textos() {
426429
calcularTiempo();
427430
calcularMemoria();
428431
}
432+
// ---------------------------------------------------------------------------------------------
429433

430434
/**
431435
* Calcula la memoria y cambia los labels correspondientes.
@@ -436,24 +440,37 @@ public void calcularMemoria() {
436440
lblMemoriaLibre.setText("Memoria libre: " + memoria.libre + " MB");
437441
lblMemoriaUsada.setText("Memoria usada: " + memoria.usada + " MB");
438442
}
443+
// ---------------------------------------------------------------------------------------------
439444

440445
/**
441446
* Tiempo usado para en la ejecucion entre el inicio y final de un algoritmo de
442447
* ordenacion.
443448
*/
444-
private int calcSegundos(int tiempo) {
445-
return (int) (tiempo / 1000);
449+
private int calcMin(int tiempo) {
450+
int min = tiempo;
451+
min = (min / 1000) / 60;
452+
return min;
453+
454+
}
455+
456+
private int calcSeg(int tiempo) {
457+
int seg = tiempo;
458+
seg = (seg / 1000) - (60 * calcMin(seg));
459+
return seg;
446460
}
447461

448-
private int calcMilisegundos(int tiempo) {
449-
tiempo = tiempo - (1000 * calcSegundos((int) tiempo));
450-
return tiempo;
462+
private int calcMil(int tiempo) {
463+
int mil = tiempo;
464+
mil = mil - (1000 * (mil / 1000));
465+
return mil;
451466
}
452467

453468
public void calcularTiempo() {
454469
tiempo = fin - inicio;
455-
lblTiempo.setText("Tiempo: " + calcSegundos((int) tiempo) + " s " + calcMilisegundos((int) tiempo) + " ms");
470+
lblTiempo.setText("Tiempo: " + calcMin((int) tiempo) + " m " + calcSeg((int) tiempo) + " s "
471+
+ calcMil((int) tiempo) + " ms");
456472
}
473+
// ---------------------------------------------------------------------------------------------
457474

458475
/**
459476
* Reinicia algunas variables y textos despues de terminar un sort.
@@ -465,6 +482,7 @@ public void reinicio() {
465482
memoria = new Memoria(0);
466483
Delay.n = sliderRetardo.getValue();
467484
}
485+
// ---------------------------------------------------------------------------------------------
468486

469487
/**
470488
* Mantiene un cicuito cerrado para la seleccion del Sort evitando que el
@@ -479,6 +497,7 @@ public void pausa() {
479497
}
480498
sorting();
481499
}
500+
// ---------------------------------------------------------------------------------------------
482501

483502
/**
484503
* Obtiene el tamaño seleccionado en el menu y cambia el tamaño de las barras
@@ -491,6 +510,7 @@ public void cambioNumBarras() {
491510
barras.barras();
492511
barras.repaint();
493512
}
513+
// ---------------------------------------------------------------------------------------------
494514

495515
/**
496516
* Cambio el retardo o lentitud con la que se sejecuta la animacion de la
@@ -501,25 +521,44 @@ public void cambioRetardo() {
501521
Delay.delay();
502522
lblRetardo.setText("Retardo: " + Delay.n + " ms");
503523
}
524+
// ---------------------------------------------------------------------------------------------
504525

526+
/**
527+
* La clase SliderNumBarasPersonalizado agrega valores a un Slider para
528+
* personalizar la forma de mostrar los distintos valores. En concreto agrega
529+
* valores en base 2 del binario.
530+
*/
505531
class SliderNumBarasPersonalizado {
506532

533+
/**
534+
* Convierte un numero entero en un String.
535+
*
536+
* @param n la n indica el exponente por el cual se calcula.
537+
* @return the string
538+
*/
507539
private String convertirIntToString(int n) {
508540
final int base = 2;
509541
String valor = String.valueOf((int) Math.pow(base, n));
510542
return valor;
511543
}
512544

545+
/**
546+
* Establece los valores em funcion de la cantidad recividad por parametro.
547+
*
548+
* @param n la n es el numero de valores agreados.
549+
* @return un hashtable con los valores agregados en base 2.
550+
*/
513551
public Hashtable<Integer, JLabel> establecerValoresSlider(int n) {
514-
Hashtable<Integer, JLabel> position = new Hashtable<Integer, JLabel>();
552+
Hashtable<Integer, JLabel> posiciones = new Hashtable<Integer, JLabel>();
515553
JLabel lblLabel;
516554
for (int i = 0; i <= n; i++) {
517-
position.put(i, lblLabel = new JLabel(convertirIntToString(i)));
555+
posiciones.put(i, lblLabel = new JLabel(convertirIntToString(i)));
518556
lblLabel.setForeground(Color.WHITE);
519557
}
520-
return position;
558+
return posiciones;
521559
}
522560
}
561+
// ---------------------------------------------------------------------------------------------
523562

524563
public static JLabel getLblAccesos() {
525564
return lblAccesos;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /