Foro de elhacker.net

Programación => Java => Mensaje iniciado por: Senior++ en 10 Octubre 2012, 20:24 pm



Título: (Aporte) Código fuente Pasar texto a negrita y cursiva o plana
Publicado por: Senior++ en 10 Octubre 2012, 20:24 pm
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

Código
  1. import javax.swing.*;
  2. import java.awt.*;
  3. import java.awt.event.*;
  4.  
  5.  
  6. public class clase21 extends JFrame implements ItemListener{
  7.  
  8. private JTextField texto;
  9. private JCheckBox negrita,cursiva;
  10. private Font fuente;
  11.  
  12. public clase21(){
  13.  
  14. super ("Fontenizar");
  15.  
  16. this.setLayout(new FlowLayout());
  17. this.definirVentana();
  18. this.setSize(400,400);
  19. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  20. this.setVisible(true);
  21. }
  22.  
  23. private void definirVentana() {
  24. texto = new JTextField(20);
  25. negrita =  new JCheckBox("Negrita");
  26. cursiva = new JCheckBox("Cursiva");
  27. add(texto);
  28. add(negrita);
  29. add(cursiva);
  30. negrita.addItemListener(this);
  31. cursiva.addItemListener(this);
  32.  
  33. }
  34.  
  35.  
  36. public void itemStateChanged(ItemEvent e) {
  37. if(negrita.isSelected() && cursiva.isSelected()){
  38. //cambie el texto a negrita y cursiva
  39. fuente = new Font("Serief",Font.BOLD|Font.ITALIC,14);
  40. texto.setFont(fuente);
  41. }else if (cursiva.isSelected()){
  42. //Cambie el texto a cursiva
  43.             fuente = new Font("Serief",Font.ITALIC,14);
  44. texto.setFont(fuente);
  45. }else if (negrita.isSelected()){
  46.              fuente = new Font("Serief",Font.BOLD,14);
  47.              texto.setFont(fuente);
  48.  
  49. }else{
  50. fuente = new Font("Serief",Font.PLAIN,14);
  51. texto.setFont(fuente);
  52.  
  53. }
  54. }
  55. }
  56.  


Título: Re: (Aporte) Código fuente Pasar texto a negrita y cursiva o plana
Publicado por: 1mpuls0 en 22 Octubre 2012, 17:51 pm
Gracias.

Estaría genial que tu aplicación también se pueda seleccionar el tipo de letra.

Saludos.