Docsity

JList Colores codigo java, Ejercicios de Programación Java

Toggle sidebar
bg1
NOMBRE:
José de Jesús Gaytán Ramírez
MAESTRO(A):
Ing. Luis Eduardo Gutiérrez Ayala
MATERIA:
Tópicos Avanzados de Programación (TAP)
SEMESTRE:
4to
CARRERA:
Sistemas Computacionales
HORA:
Martes y jueves 10:30-12:15
Viernes 11:20-12:10
AULA:
C-C-LC1
pf3
pf4
pf5
pf8

Vista previa parcial del texto

¡Descarga JList Colores codigo java y más Ejercicios en PDF de Programación Java solo en Docsity!

NOMBRE:

José de Jesús Gaytán Ramírez

MAESTRO(A):

Ing. Luis Eduardo Gutiérrez Ayala

MATERIA:

Tópicos Avanzados de Programación (TAP)

SEMESTRE:

4to

CARRERA:

Sistemas Computacionales

HORA:

Martes y jueves 10:30-12:

Viernes 11:20-12:

AULA:

C-C-LC 1

Redacción del problema

Realizar un programa que muestra 2 Jlist con al menos 15 colores, los colores deberán estar dentro de una Enumeración con los atributos RGB. Al seleccionar un color de la lista deberá de modificar el color de frente o del fondo del área de prueba. Use un solo escucha para las 2 listas.

Código fuente

clase package JList; import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.ListSelectionModel; import javax.swing.SwingConstants; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; <<

private int r,g,b; private ColorEnum (int r, int g, int b){ this.r = r; this.g = g; this.b = b; } public int getR() {return r;} public int getG() {return g;} public int getB() {return b;} } //Constructor inicializador de los componentes public Lista(){ ventana = new JFrame("LISTA DE COLORES"); panelF = new JPanel(); panelPrueba = new JPanel(); listaF = new JList(ColorEnum.values()); listaP = new JList(ColorEnum.values()); scrollF = new JScrollPane(listaF); scrollP = new JScrollPane(listaP); etiqueta = new JLabel("etiqueta", SwingConstants.CENTER); etiqP = new JLabel("Area de Prueba", SwingConstants.CENTER);

this.atributos(); this.armado(); this.escuchas(); this.lanzar_IGU(); } //Atributos de los componentes private void atributos() { ventana.setSize(800, 300); panelPrueba.setSize(200,100); panelPrueba.setBackground(Color.PINK); listaF.setSelectedIndex(0); listaF.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); listaF.setFont(new Font ("Arial", Font.BOLD, 20)); listaP.setSelectedIndex(0); listaP.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); listaP.setFont(new Font ("Arial", Font.BOLD, 20)); etiqP.setFont(new Font("", Font.CENTER_BASELINE, 30)); } //Armado de la interfaz private void armado() { ventana.add(panelF); ventana.add(etiqueta, BorderLayout.SOUTH); panelF.add(scrollF, BorderLayout.EAST);

panelF.setBackground(new Color (selectF.getR(), selectF.getG(), selectF.getB())); ColorEnum selectP = (ColorEnum) listaP.getSelectedValue(); panelPrueba.setBackground(new Color (selectP.getR(), selectP.getG(), selectP.getB())); String numeros = " "; for (int selectedIndice : listaF.getSelectedIndices()){ numeros += selectedIndice + " "; } etiqueta.setText(" " + listaF.getSelectedValuesList() + " " + numeros); } } } Clase Main package JList; public class PruebaLista { public static void main(String[] args) { new Lista(); } }

Capturas de pantalla del funcionamiento del código