Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import java.awt.FlowLayout;
  2. import java.awt.Font;
  3. import java.awt.event.ItemListener;
  4. import java.awt.event.ItemEvent;
  5. import javax.swing.JFrame;
  6. import javax.swing.JTextField;
  7. import javax.swing.JCheckBox;
  8.  
  9. public class CheckBoxFrame extends JFrame{
  10.  
  11. private JTextField textField;
  12. private JCheckBox boldJCheckBox;
  13. private JCheckBox italicJCheckBox;
  14.  
  15. public CheckBoxFrame(){
  16.  
  17. super("Testando CheckBox");
  18. setLayout(new FlowLayout());
  19.  
  20. textField = new JTextField("Assista a mudança de estilo de fonte", 20);
  21. textField.setFont(new Font("Serif", Font.PLAIN, 14));
  22. add(textField);
  23.  
  24. boldJCheckBox = new JCheckBox("Negrito");
  25. italicJCheckBox = new JCheckBox("Itálico");
  26. add(boldJCheckBox);
  27. add(italicJCheckBox);
  28.  
  29. CheckBoxHandler handler = new CheckBoxHandler();
  30. boldJCheckBox.addItemListener(handler);
  31. italicJCheckBox.addItemListener(handler);
  32.  
  33. }
  34.  
  35. private class CheckBoxHandler implements ItemListener{
  36.  
  37. public void itemStateChanged(ItemEvent event){
  38.  
  39. Font font = null;
  40. if(boldJCheckBox.isSelected() && italicJCheckBox.isSelected()){
  41.  
  42. font = new Font("Serif", Font.BOLD + Font.ITALIC,14);
  43.  
  44. }else if(boldJCheckBox.isSelected()){
  45.  
  46. font = new Font("Serif", Font.BOLD,14);
  47.  
  48. }else if(italicJCheckBox.isSelected()){
  49.  
  50. font = new Font("Serif", Font.ITALIC,14);
  51.  
  52. }else{
  53.  
  54. font = new Font("Serif", Font.PLAIN, 14);
  55. }
  56.  
  57. textField.setFont(font);
  58.  
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement