elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: Arreglado, de nuevo, el registro del warzone (wargame) de EHN


+  Foro de elhacker.net
|-+  Programación
| |-+  Programación General
| | |-+  Java
| | | |-+  (Aporte) Código fuente Pasar texto a negrita y cursiva o plana
0 Usuarios y 1 Visitante están viendo este tema.
Páginas: [1] Ir Abajo Respuesta Imprimir
Autor Tema: (Aporte) Código fuente Pasar texto a negrita y cursiva o plana  (Leído 24,026 veces)
Senior++


Desconectado Desconectado

Mensajes: 957

Ama y haz lo que te de la gana


Ver Perfil
(Aporte) Código fuente Pasar texto a negrita y cursiva o plana
« 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.  


En línea

Vendo cuenta de LEAGUE OF LEGENDS lvl 30, EU west, muy barata
1mpuls0


Desconectado Desconectado

Mensajes: 1.186


Ver Perfil
Re: (Aporte) Código fuente Pasar texto a negrita y cursiva o plana
« Respuesta #1 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.


En línea

abc
Páginas: [1] Ir Arriba Respuesta Imprimir 

Ir a:  

WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines