0% found this document useful (0 votes)
2 views

Tarea1 Java Swing

The document contains a Java Swing application called 'formularioSwitch' that allows users to select font properties such as font type, style, and size. It features a graphical user interface with a preview label that updates based on user selections. The application is designed to run as a JFrame and includes an 'Accept' button to apply the chosen font settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Tarea1 Java Swing

The document contains a Java Swing application called 'formularioSwitch' that allows users to select font properties such as font type, style, and size. It features a graphical user interface with a preview label that updates based on user selections. The application is designed to run as a JFrame and includes an 'Accept' button to apply the chosen font settings.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Formulario 1 / Editor de texto

CLASE formularioSwitch
package hola;

import javax.swing.*;

import java.awt.*;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

public class formularioSwitch extends JFrame {

private JComboBox<String> fontCombo;

private JComboBox<String> styleCombo;

private JComboBox<Integer> sizeCombo;

private JLabel previewLabel;

public formularioSwitch() {
setTitle("Selector de Fuente");

setSize(500, 400);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

setLayout(new BorderLayout(10, 10));

JPanel topPanel = new JPanel(new GridLayout(3, 2, 5, 5));

String[] fonts =
GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();

fontCombo = new JComboBox<>(fonts);

topPanel.add(new JLabel("Fuente:"));

topPanel.add(fontCombo);

//Reparar aqui

String[] styles = {"Sin Formato", "Negrita", "Cursiva", "Negrita Cursiva"};

styleCombo = new JComboBox<>(styles);

topPanel.add(new JLabel("Estilo:"));

topPanel.add(styleCombo);

Integer[] sizes = {3, 5, 8, 10, 12, 14, 18, 24, 36};

sizeCombo = new JComboBox<>(sizes);

topPanel.add(new JLabel("Tamaño:"));

topPanel.add(sizeCombo);

add(topPanel, BorderLayout.NORTH);

previewLabel = new JLabel("The quick brown fox jumps over the lazy dog",
JLabel.CENTER);

previewLabel.setBorder(BorderFactory.createTitledBorder("Vista Previa"));

previewLabel.setFont(new Font("Arial", Font.PLAIN, 14));

add(previewLabel, BorderLayout.CENTER);

JPanel buttonPanel = new JPanel();

JButton acceptButton = new JButton("Aceptar");


acceptButton.addActionListener(e -> updateFont());

buttonPanel.add(acceptButton);

add(buttonPanel, BorderLayout.SOUTH);

setLocationRelativeTo(null);

setVisible(true);

private void updateFont() {

String fontName = (String) fontCombo.getSelectedItem();

int style = styleCombo.getSelectedIndex();

int size = (Integer) sizeCombo.getSelectedItem();

previewLabel.setFont(new Font(fontName, style, size));

public static void main(String[] args) {

SwingUtilities.invokeLater(formularioSwitch::new);

You might also like