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 b2d80e9

Browse files
author
javiluli
committed
Cambio el sistema de seleccion de los diseños graficos en la Clase Barras
1 parent 864bdfd commit b2d80e9

File tree

3 files changed

+78
-65
lines changed

3 files changed

+78
-65
lines changed

‎ordenaciones.jar

-54 Bytes
Binary file not shown.

‎src/principal/Barras.java

Lines changed: 34 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public class Barras extends JPanel {
1818
private static int NUM_BARS = 32;
1919
private static int BAR_WIDTH = getWinWidth() / getNUM_BARS();
2020
private static int BAR_HEIGHT = getWinHeight() / getNUM_BARS();
21+
private boolean marcarSepacaion = false;
2122

2223
/**
2324
* Constructor de iniciar el array con numeros ordenados.
@@ -65,48 +66,38 @@ public void paintComponent(Graphics g) {
6566
super.paintComponent(graphics);
6667
graphics.setColor(Color.WHITE);
6768
int opcionGrafico = Main.getComboboxtiposgraficos().getSelectedIndex();
68-
if (opcionGrafico == 0)
69-
pintarEscalera(graphics);
70-
else if (opcionGrafico == 1)
71-
pintarPiramideHorizontal(graphics);
72-
else if (opcionGrafico == 2)
73-
pintarCuadrado(graphics);
74-
else if (opcionGrafico == 3)
75-
pintarPunto(graphics);
76-
}
7769

78-
private void pintarEscalera(Graphics2D graphics) {
7970
for (int i = 0; i < getNUM_BARS(); i++) {
80-
int height = (Sorts.n[i] * getBAR_HEIGHT()) + getBAR_HEIGHT();
81-
int xBegin = i + (getBAR_WIDTH() - 1) * i;
82-
int yBegin = getWinHeight() - height;
83-
graphics.fill3DRect(xBegin, yBegin, getBAR_WIDTH(), height, true);
71+
comunes(i, graphics, opcionGrafico);
8472
}
8573
}
8674

87-
private void pintarPiramideHorizontal(Graphics2D graphics) {
88-
for (int i = 0; i < getNUM_BARS(); i++) {
89-
int height = (Sorts.n[i] * getBAR_HEIGHT()) + getBAR_HEIGHT();
90-
int xBegin = i + (getBAR_WIDTH() - 1) * i;
91-
int yBegin = ((getWinHeight() - height) / 2);
92-
graphics.fill3DRect(xBegin, yBegin, getBAR_WIDTH(), height, true);
93-
}
94-
}
75+
private void comunes(int i, Graphics2D graphics, int opcionGrafico) {
76+
int height = 0, xBegin = 0, yBegin = 0;
77+
height = (Sorts.n[i] * getBAR_HEIGHT()) + getBAR_HEIGHT();
78+
xBegin = i + (getBAR_WIDTH() - 1) * i;
79+
// --------------------------------------------------------------------------------------------
9580

96-
private void pintarCuadrado(Graphics2D graphics) {
97-
for (int i = 0; i < getNUM_BARS(); i++) {
98-
int xBegin = i + (getBAR_WIDTH() - 1) * i;
99-
int auxDistancia = (Sorts.n[i] * getBAR_HEIGHT()) + getBAR_HEIGHT();
100-
int yBegin = getWinHeight() - auxDistancia;
101-
graphics.fillRect(xBegin, yBegin, getBAR_HEIGHT(), getBAR_HEIGHT());
81+
// SELECCION ENTRE EL ESTILO GRAFICO DE "ESCALERAS" Y "PIRAMIDE HORIZONTAL"
82+
if (opcionGrafico == 1) { // GRAFICOS "Piramide horizontal"
83+
// Al dividir entre 2 de divide el espacio entre las barras y los lados de la
84+
// ventana.
85+
yBegin = ((getWinHeight() - height) / 2);
86+
} else if (opcionGrafico != 1) { // GRAFICOS "Escalera"
87+
yBegin = ((getWinHeight() - height));
10288
}
103-
}
104-
105-
private void pintarPunto(Graphics2D graphics) {
106-
for (int i = 0; i < getNUM_BARS(); i++) {
107-
int xBegin = i + (getBAR_WIDTH() - 1) * i;
108-
int auxDistancia = (Sorts.n[i] * getBAR_HEIGHT()) + getBAR_HEIGHT();
109-
int yBegin = getWinHeight() - auxDistancia;
89+
// --------------------------------------------------------------------------------------------
90+
91+
// SELECCION ENTRE LOS DISTINTOS TIPOS DE ESTILOS GRAFICOS
92+
if (opcionGrafico == 0 || opcionGrafico == 1) { // GRAFICOS "Escalera" Y "Piramide horizontal"
93+
if (marcarSepacaion) { // EFECTO GRAFICO CON EL CONTORNO BARRAS
94+
graphics.fill3DRect(xBegin, yBegin, getBAR_WIDTH(), height, true);
95+
} else if (!marcarSepacaion) { // EFECTO GRAFICO SIN EL CONTORNO BARRAS
96+
graphics.fillRect(xBegin, yBegin, getBAR_HEIGHT(), height);
97+
}
98+
} else if (opcionGrafico == 2) { // GRAFICOS "Cuadrado"
99+
graphics.fillRect(xBegin, yBegin, getBAR_HEIGHT(), getBAR_HEIGHT());
100+
} else if (opcionGrafico == 3) { // GRAFICOS "Punto"
110101
graphics.fillOval(xBegin, yBegin, getBAR_HEIGHT(), getBAR_HEIGHT());
111102
}
112103
}
@@ -152,4 +143,12 @@ public static int getBAR_HEIGHT() {
152143
public static void setBAR_HEIGHT(int bAR_HEIGHT) {
153144
BAR_HEIGHT = bAR_HEIGHT;
154145
}
146+
147+
public boolean isMarcarSepacaion() {
148+
return marcarSepacaion;
149+
}
150+
151+
public void setMarcarSepacaion(boolean marcarSepacaion) {
152+
this.marcarSepacaion = marcarSepacaion;
153+
}
155154
}

‎src/principal/Main.java

Lines changed: 44 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,31 @@
11
package Principal;
22

3+
import java.awt.Color;
4+
import java.awt.Font;
5+
import java.awt.Panel;
6+
import java.awt.SystemColor;
7+
import java.awt.event.ActionEvent;
8+
import java.awt.event.ActionListener;
9+
import java.util.Hashtable;
10+
11+
import javax.swing.ImageIcon;
12+
import javax.swing.JButton;
13+
import javax.swing.JCheckBox;
14+
import javax.swing.JComboBox;
315
import javax.swing.JFrame;
4-
import javax.swing.JPanel;
516
import javax.swing.JLabel;
617
import javax.swing.JOptionPane;
7-
8-
import java.awt.Font;
9-
18+
importjavax.swing.JPanel;
19+
import javax.swing.JSlider;
20+
importjavax.swing.SwingConstants;
1021
import javax.swing.border.LineBorder;
22+
import javax.swing.event.ChangeEvent;
23+
import javax.swing.event.ChangeListener;
1124

1225
import Adicionales.*;
13-
import Sorts.*;
26+
import Sorts.Sorts;
1427
import Sorts.Algoritmos.*;
1528

16-
import java.awt.Color;
17-
18-
import javax.swing.SwingConstants;
19-
import javax.swing.JComboBox;
20-
import javax.swing.JButton;
21-
import java.awt.event.ActionListener;
22-
import java.util.Hashtable;
23-
import java.awt.event.ActionEvent;
24-
import javax.swing.JSlider;
25-
import javax.swing.event.ChangeListener;
26-
27-
import javax.swing.event.ChangeEvent;
28-
import java.awt.Panel;
29-
import java.awt.SystemColor;
30-
import javax.swing.ImageIcon;
31-
3229
public class Main extends Sorts {
3330
// Nombre de cada algoritmo Sort
3431
private final String[] nombreAlgoritmos = { "Bubble", "Cocktail", "Cycle", "Gnome", "Heap", "Insertion", "Merge",
@@ -45,6 +42,8 @@ public class Main extends Sorts {
4542
// COMBOBOX
4643
private final JComboBox<String> comboBoxTipoSort = new JComboBox<String>(nombreAlgoritmos);
4744
private static final JComboBox<Object> comboBoxTiposGraficos = new JComboBox<Object>(nombreGrafico);
45+
// private final JComboBox<String> comboBoxTipoSort = new JComboBox<String>();
46+
// private static final JComboBox<Object> comboBoxTiposGraficos = new JComboBox<Object>();
4847
// JLABEL
4948
private final JLabel lblTitleAlgoritmo = new JLabel("Seleccionar algoritmo de ordenacion");
5049
private final JLabel lblTitle = new JLabel("Panel de control");
@@ -65,6 +64,8 @@ public class Main extends Sorts {
6564
private final JButton btnInformacion = new JButton("Informacion");
6665
private final JButton btnGithub = new JButton();
6766
private final JButton btnCodepen = new JButton();
67+
// JCHECKBOX
68+
private final JCheckBox chckbxContornoBarras = new JCheckBox("Marcar el contorno de las barras");
6869
// JSLIDER
6970
private final JSlider sliderTamBarras = new JSlider();
7071
private final JSlider sliderRetardo = new JSlider();
@@ -199,16 +200,16 @@ public void actionPerformed(ActionEvent e) {
199200
}
200201
});
201202
panelOpcionesMenu.add(btnDesordenar);
202-
lblCambios.setForeground(Color.WHITE);
203203

204204
// Label para el recuento de cambios realizados en el array.
205+
lblCambios.setForeground(Color.WHITE);
205206
lblCambios.setFont(new Font("Arial", Font.BOLD, 13));
206207
lblCambios.setBounds(10, 215, 250, 30);
207208
panelOpcionesMenu.add(lblCambios);
208-
lblAccesos.setForeground(Color.WHITE);
209209

210210
// Label para el recuento de accesos realizados en el array.
211211
lblAccesos.setFont(new Font("Arial", Font.BOLD, 13));
212+
lblAccesos.setForeground(Color.WHITE);
212213
lblAccesos.setBounds(10, 256, 237, 30);
213214
panelOpcionesMenu.add(lblAccesos);
214215
lblNumeroBarras.setHorizontalAlignment(SwingConstants.RIGHT);
@@ -312,13 +313,14 @@ public void stateChanged(ChangeEvent e) {
312313
// Boton para saltar o salir de la animacion
313314
btnSaltarSort.setBackground(Color.BLACK);
314315
btnSaltarSort.setForeground(Color.WHITE);
316+
btnSaltarSort.setFont(new Font("Arial", Font.BOLD, 13));
317+
btnSaltarSort.setBounds(160, 129, 110, 30);
315318
btnSaltarSort.addActionListener(new ActionListener() {
316319
public void actionPerformed(ActionEvent e) {
317-
Delay.n = 1 / 2;
320+
Delay.n = 0;
318321
}
319322
});
320-
btnSaltarSort.setFont(new Font("Arial", Font.BOLD, 13));
321-
btnSaltarSort.setBounds(160, 129, 110, 30);
323+
322324
panelOpcionesMenu.add(btnSaltarSort);
323325

324326
// Boton para ver informacion sobre la aplicacion
@@ -370,6 +372,22 @@ public void actionPerformed(ActionEvent e) {
370372
lblTituloGraficos.setBounds(10, 88, 120, 30);
371373
panelOpcionesMenu.add(lblTituloGraficos);
372374

375+
// Radio button para poner o quitar separacion entre barras.
376+
chckbxContornoBarras.setForeground(Color.WHITE);
377+
chckbxContornoBarras.setBackground(Color.BLACK);
378+
chckbxContornoBarras.setFont(new Font("Arial", Font.BOLD, 13));
379+
chckbxContornoBarras.setBounds(10, 185, 260, 23);
380+
chckbxContornoBarras.addActionListener(new ActionListener() {
381+
public void actionPerformed(ActionEvent e) {
382+
if (chckbxContornoBarras.isSelected())
383+
barras.setMarcarSepacaion(true);
384+
else if (!chckbxContornoBarras.isSelected())
385+
barras.setMarcarSepacaion(false);
386+
panelBarras.repaint();
387+
}
388+
});
389+
panelOpcionesMenu.add(chckbxContornoBarras);
390+
373391
// Label para el titulo de los controles.
374392
lblTitle.setBounds(10, 11, 280, 24);
375393
lblTitle.setForeground(Color.WHITE);
@@ -648,8 +666,4 @@ public void setPanelBarras(JPanel panelBarras) {
648666
public static JComboBox<Object> getComboboxtiposgraficos() {
649667
return comboBoxTiposGraficos;
650668
}
651-
652-
// public static JComboBox<Object> getComboboxtiposgraficos() {
653-
// return comboBoxTiposGraficos;
654-
// }
655669
}

0 commit comments

Comments
(0)

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