Advertisement
daixso

Error on line 26,30, and 47

Jun 19th, 2012
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.19 KB | None | 0 0
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4. public class check_tut extends JFrame{
  5.     /**
  6.      * Author: Zachary Williams
  7.      */
  8.     private static final long serialVersionUID = 1L;
  9.     private JTextField tf;
  10.     private JCheckBox bold;
  11.     private JCheckBox italics;
  12.    
  13.     public check_tut(){
  14.         super("Check Box Tut");
  15.         setLayout(new FlowLayout());
  16.        
  17.         tf = new JTextField("This is a sentence", 20);
  18.         tf.setFont(new Font("Serif", Font.PLAIN, 14));
  19.         add(tf);
  20.        
  21.         bold = new JCheckBox("Bold");
  22.         italics = new JCheckBox("italics");
  23.         add(bold);
  24.         add(italics);
  25.        
  26.         HandlerClass handler = new HandlerClass();
  27.         bold.addItemListener(handler);
  28.         italics.addItemListener(handler);
  29.     }
  30.     private HandlerClass implements ItemListener{
  31.         private Font font;
  32.         public void itemStateChanged(ItemEvent event){
  33.            
  34.            
  35.             if(bold.isSelected() && italics.isSelected()){
  36.                 font = new Font("Serif", Font.BOLD + Font.ITALIC, 14);
  37.             }else if(bold.isSelected()){
  38.                 font = new Font("Serif", Font.BOLD, 14);
  39.             }else if(italics.isSelected()){
  40.                 font = new Font("Serif", Font.ITALIC, 14);
  41.             }else{
  42.                 font = new Font("Serif", Font.PLAIN, 14);
  43.             }
  44.             tf.setFont(font);
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement