Hola.. bueno estaba aburrido y bueno y quise hacer una aplicación en Java que te convierte el texto a negrita,cursiva y a plana
bueno aquí el código
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class clase21 extends JFrame implements ItemListener{
private JTextField texto;
private JCheckBox negrita,cursiva;
private Font fuente;
public clase21(){
super ("Fontenizar");
this.setLayout(new FlowLayout());
this.definirVentana();
this.setSize(400,400);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);
}
private void definirVentana() {
texto = new JTextField(20);
negrita = new JCheckBox("Negrita");
cursiva = new JCheckBox("Cursiva");
add(texto);
add(negrita);
add(cursiva);
negrita.addItemListener(this);
cursiva.addItemListener(this);
}
public void itemStateChanged(ItemEvent e) {
if(negrita.isSelected() && cursiva.isSelected()){
//cambie el texto a negrita y cursiva
fuente = new Font("Serief",Font.BOLD|Font.ITALIC,14);
texto.setFont(fuente);
}else if (cursiva.isSelected()){
//Cambie el texto a cursiva
fuente = new Font("Serief",Font.ITALIC,14);
texto.setFont(fuente);
}else if (negrita.isSelected()){
fuente = new Font("Serief",Font.BOLD,14);
texto.setFont(fuente);
}else{
fuente = new Font("Serief",Font.PLAIN,14);
texto.setFont(fuente);
}
}
}
Gracias.
Estaría genial que tu aplicación también se pueda seleccionar el tipo de letra.
Saludos.