Datos de la Institución
Instituto Tecnológico de León
CODIGO EDITOR DE TEXTO
Carrera: Sistemas Computacionales
Materia: Tópicos Avanzados en Programacion
Nombre:
Macias Campos Ariadne Lizett
Docente:
Luis Eduardo Gutiérrez Ayala
Grupo: 4C
Fecha: 23/03/2024
R01/09/2014 EP-F-09
Av. Tecnológico s/n Fracc. Industrial Julián de Obregón C.P. 37290
León, Gto. México. Tel. 01 (477) 7105200, email tecleon@[Link]
[Link] | [Link]
PROBLEMÁTICA DEL CODIGO
El siguiente código de Java representa una aplicación de GUI (Interfaz Gráfica de Usuario) que permite al
usuario ajustar diferentes atributos de un campo de texto, como el tipo de letra, tamaño, estilo, color de
texto y color de fondo;
DIAGRAMA UML
CLASE ColorsRGB
package lettersWorks;
public enum ColorsRGB {
Marine(102,205,170),
Claire(223,190,153),
LightSea(102,205,170),
Melocoton(236,145,146),
Red(219,83,117),
Blue(0,204,255),
Olivo(181,189,137),
Lila(204,204,255),
PaleGreen(152,251,152),
LightCoral(240,128,128),
Teal(0,128,128),
Pink(253,202,225),
Sky(135,206,235),
DarkOrchid(153,50,204),
Lavander(230,230,250),
White(255,255,255),
Black(0,0,0);
private int r,g,b;
private ColorsRGB(int r, int g, int b) {
this.r = r;
this.g = g;
this.b = b;
}
public void setR(int r) {
this.r = r;
}
public void setG(int g) {
this.g = g;
}
public void setB(int b) {
this.b = b;
}
public int getR() {
return r;
}
public int getG() {
return g;
}
public int getB() {
return b;
}
}
CLASE LettersTunes
package lettersWorks;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class TunesLetters{
private JFrame win;
private JPanel pan_Central;
private JPanel pan_Diseño;
private JPanel pan_Texto;
private JPanel panelTipo;
private JLabel[] etiquetas_Txto;
private JComboBox tipo_Fonts;
private JList listDefaultColorsFont, listDefaultColorsFondo;
private JLabel insercionTexto;
private JSpinner siz_Fuente;
private JRadioButton[] butt_Radio;
private ButtonGroup opcionesDiseño;
private JSlider[] RGB;
private JButton[] botonAceptar;
private JTextField areaTxto;
private ColorsRGB coloresFondos;
private ColorsRGB coloresLetras;
private JScrollPane scrolpaneFont;
private JScrollPane scrolpaneFondo;
public TunesLetters() {
win = new JFrame("Documento - Bienvenido a Word flasheado");
areaTxto = new JTextField("");
pan_Central = new JPanel();
pan_Diseño = new JPanel();
pan_Texto = new JPanel();
panelTipo = new JPanel();
tipo_Fonts = new JComboBox(GraphicsEnvironment.
getLocalGraphicsEnvironment().
getAvailableFontFamilyNames());
listDefaultColorsFont = new JList([Link]());
listDefaultColorsFondo = new JList([Link]());
butt_Radio = new JRadioButton[4];
for (int i = 0; i < butt_Radio.length; i++) {
butt_Radio[i] = new JRadioButton();
}
etiquetas_Txto = new JLabel[11];
for (int i = 0; i < etiquetas_Txto.length; i++) {
etiquetas_Txto[i] = new JLabel();
}
RGB = new JSlider[6];
for (int i = 0; i < [Link]; i++) {
RGB[i] = new JSlider([Link], 0, 255, 0);
}
botonAceptar = new JButton[2];
for (int i = 0; i < [Link]; i++) {
botonAceptar[i] = new JButton();
}
SpinnerNumberModel size = new SpinnerNumberModel(12, 11, 51, 1);
siz_Fuente = new JSpinner(size);
opcionesDiseño = new ButtonGroup();
Atributos();
Armado();
Escuchas();
Mostrar();
}
private void Atributos() {
EstiloLetra();
botonAceptarColor();
Colorletra();
ColorFondo();
Paneles();
[Link](560, 700);
[Link](JFrame.EXIT_ON_CLOSE);
[Link](null);
[Link](false);
pan_Diseñ[Link](250, 80, 285, 68);
pan_Diseñ[Link](null);
pan_Texto.setBounds(250, 180, 285, 400);
pan_Texto.setLayout(null);
pan_Central.setLayout(null);
pan_Central.setBackground(new Color(216,191,216));
tipo_Fonts.setBounds(10, 110, 180, 30);
siz_Fuente.setBounds(195, 110, 40, 30);
[Link]( 20, 40, 250, 330);
}
private void Paneles() {
etiquetas_Txto[6] = new JLabel("Tipo y Tamaño de letra");
etiquetas_Txto[6].setBounds(32, 70, 300, 30);
etiquetas_Txto[6].setFont(new Font("Baskerville Old Face", [Link], 16));
etiquetas_Txto[7] = new JLabel("Ingrese su texto");
etiquetas_Txto[7].setBounds(74, 2, 200, 30);
etiquetas_Txto[7].setFont(new Font("Baskerville Old Face", [Link], 18));
etiquetas_Txto[8] = new JLabel("Estilo de letra");
etiquetas_Txto[8].setBounds(84, 2, 200, 30);
etiquetas_Txto[8].setFont(new Font("Baskerville Old Face", [Link], 18));
etiquetas_Txto[9] = new JLabel("Color de texto");
etiquetas_Txto[9].setBounds(75, 170, 300, 30);
etiquetas_Txto[9].setFont(new Font("Baskerville Old Face", [Link], 16));
etiquetas_Txto[10] = new JLabel("Color de fondo");
etiquetas_Txto[10].setBounds(75, 420, 300, 30);
etiquetas_Txto[10].setFont(new Font("Baskerville Old Face", [Link], 16));
}
private void Armado() {
[Link](pan_Central, [Link]);
pan_Central.add(pan_Diseño);
pan_Central.add(pan_Texto);
pan_Central.add(panelTipo);
pan_Texto.add(areaTxto);
for (int i = 0; i < etiquetas_Txto.length; i++) {
switch (i) {
case 8 ->
pan_Diseñ[Link](etiquetas_Txto[8]);
case 7 ->
pan_Texto.add(etiquetas_Txto[7]);
default ->
pan_Central.add(etiquetas_Txto[i]);
}
}
for (JRadioButton butt_RadioGenerado : butt_Radio) {
opcionesDiseñ[Link](butt_RadioGenerado);
pan_Diseñ[Link](butt_RadioGenerado);
}
for (JSlider RGBGenerado : RGB) {
pan_Central.add(RGBGenerado);
}
for (JButton botonAceptarGenerado : botonAceptar) {
pan_Central.add(botonAceptarGenerado);
}
pan_Central.add(tipo_Fonts);
pan_Central.add(listDefaultColorsFont);
pan_Central.add(listDefaultColorsFondo);
pan_Central.add(siz_Fuente);
JScrollPane scrollPaneFont = new JScrollPane(listDefaultColorsFondo);
[Link](147, 460, 80, 144); // Establece los límites del JScrollPane
pan_Central.add(scrollPaneFont);
JScrollPane scrollPaneFondo = new JScrollPane(listDefaultColorsFont);
[Link](147, 210, 80, 144); // Establece los límites del JScrollPane
pan_Central.add(scrollPaneFondo);
private void Escuchas() {
siz_Fuente.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
SpinnerNumberModel modelo = (SpinnerNumberModel)siz_Fuente.getModel();
if (siz_Fuente.getValue() == [Link]()) {
siz_Fuente.setValue(12);
siz_Fuente.setValue((Integer) [Link]() + 1);
}
if (siz_Fuente.getValue() == [Link]()) {
siz_Fuente.setValue(50);
siz_Fuente.setValue((Integer) [Link]() - 1);
}
[Link](new Font((String) tipo_Fonts.getSelectedItem(),[Link]().getStyle(), (int)
siz_Fuente.getValue()));
}
});
tipo_Fonts.addItemListener((ItemEvent e) -> {
[Link](new Font((String) tipo_Fonts.getSelectedItem(),[Link]().getStyle(), (int)
siz_Fuente.getValue()));
});
butt_Radio[0].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
[Link](new Font((String) tipo_Fonts.getSelectedItem(),[Link], (int) siz_Fuente.getValue()));
}
});
butt_Radio[1].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
[Link](new Font((String) tipo_Fonts.getSelectedItem(),[Link], (int) siz_Fuente.getValue()));
}
});
butt_Radio[2].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
[Link](new Font((String) tipo_Fonts.getSelectedItem(),[Link], (int) siz_Fuente.getValue()));
}
});
butt_Radio[3].addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
[Link](new Font((String) tipo_Fonts.getSelectedItem(),[Link] | [Link], (int)
siz_Fuente.getValue()));
}
});
[Link]((ListSelectionEvent e) -> {
ColorsRGB coloresLetras = (ColorsRGB) [Link]();
[Link](new Color([Link](), [Link](), [Link]()));
});
[Link]((ListSelectionEvent e) -> {
ColorsRGB coloresFondos = (ColorsRGB) [Link]();
[Link](new Color([Link](), [Link](), [Link]()));
});
botonAceptar[0].addActionListener((ActionEvent e) -> {
coloresLetras= [Link];
[Link](RGB[0].getValue());
[Link](RGB[1].getValue());
[Link](RGB[2].getValue());
[Link](new Color([Link](), [Link](), [Link]()));
});
botonAceptar[1].addActionListener((ActionEvent e) -> {
coloresFondos= [Link];
[Link](RGB[3].getValue());
[Link](RGB[4].getValue());
[Link](RGB[5].getValue());
[Link](new Color([Link](), [Link](), [Link]()));
});
}
private void Mostrar() {
[Link](true);
}
private void botonAceptarColor() {
botonAceptar[0].setText("Aceptar");
botonAceptar[0].setBounds(148, 360, 76, 27);
pan_Central.add(botonAceptar[0]);
botonAceptar[1].setText("Aceptar");
botonAceptar[1].setBounds(148, 610, 76, 27);
pan_Central.add(botonAceptar[1]);
}
private void Colorletra() {
[Link](157, 210, 57, 144);
RGB[0].setBounds(31, 210, 31, 150);
etiquetas_Txto[0] = new JLabel("R");
etiquetas_Txto[0].setBounds(40, 351, 100, 50);
etiquetas_Txto[0].setFont(new Font("Times New Roman", [Link], 18));
RGB[1].setBounds(62, 210, 30, 150);
etiquetas_Txto[1] = new JLabel("G");
etiquetas_Txto[1].setBounds(70, 351, 100, 50);
etiquetas_Txto[1].setFont(new Font("Times New Roman", [Link], 18));
RGB[2].setBounds(92, 210, 30, 150);
etiquetas_Txto[2] = new JLabel("B");
etiquetas_Txto[2].setBounds(101, 351, 100, 50);
etiquetas_Txto[2].setFont(new Font("Times New Roman", [Link], 18));
}
private void ColorFondo() {
[Link](436, 210, 57, 144);
RGB[3].setBounds(31, 460, 31, 150);
etiquetas_Txto[3] = new JLabel("R");
etiquetas_Txto[3].setBounds(40, 601, 100, 50);
etiquetas_Txto[3].setFont(new Font("Times New Roman", [Link], 18));
RGB[4].setBounds(62, 460, 30, 150);
etiquetas_Txto[4] = new JLabel("G");
etiquetas_Txto[4].setBounds(70, 601, 100, 50);
etiquetas_Txto[4].setFont(new Font("Times New Roman", [Link], 18));
RGB[5].setBounds(92, 460, 30, 150);
etiquetas_Txto[5] = new JLabel("B");
etiquetas_Txto[5].setBounds(101, 601, 100, 50);
etiquetas_Txto[5].setFont(new Font("Times New Roman", [Link], 18));
}
private void EstiloLetra() {
butt_Radio[0] = new JRadioButton("Bold");
butt_Radio[1] = new JRadioButton("Plain");
butt_Radio[2] = new JRadioButton("Italic");
butt_Radio[3] = new JRadioButton("Bold Italic");
butt_Radio[0].setBounds(7, 40, 60, 20);
butt_Radio[1].setBounds(64, 40, 70, 20);
butt_Radio[2].setBounds(134, 40, 60, 20);
butt_Radio[3].setBounds(194, 40, 90, 20);
}
}
CLASE NewMain
package lettersWorks;
public class NewMain {
public static void main(String[] args) {
new LettersTunes();
}
}
INSTRUCCIONES DE USO
Los estilos de letra, tamaño de letra, tipo de letra
generan el cambio instantáneo en el texto al igual que
cualquier selección en los JList de colores de texto y
Colores de fondo.
Pero los JSliders requieren de primero elegir o mover
los valores en RGB y entonces presionar el
respectivo botón de “Aceptar”.