import javax.swing.*;
import java.awt.Graphics;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import java.io.*;
import java.util.*;
public class  writeP2 extends JPanel implements ActionListener,ItemListener
{ 
  JLabel label1;
  JTextField sentencebox;
  JPanel inputPanel;
  JTextArea t;
  String sentence;
  JCheckBox bold,italic;
  int normal_font,bold_font,italic_font;
  public writeP2()
  {    	
	label1=new JLabel("enter your sentence : ");
	t=new JTextArea(" ");
	t.setFont(new Font("Serif",Font.BOLD,24));
	sentencebox=new JTextField("Java exam third problem check box control                                          ");	
    setLayout(new BorderLayout());
    inputPanel=new JPanel();
    inputPanel.add(label1);
    inputPanel.add(sentencebox);

    

    bold=new JCheckBox("Bold");
    italic=new JCheckBox("Italic");    
    inputPanel.add(t);
    inputPanel.add(bold,BorderLayout.CENTER);
    inputPanel.add(italic,BorderLayout.SOUTH); 
    add(inputPanel,BorderLayout.NORTH);
    add(t,BorderLayout.CENTER);
    italic.addItemListener(this);
    bold.addItemListener(this);
    sentencebox.addActionListener(this);
  }
  
public static String enterString(String s)
{        
 StringTokenizer token=new StringTokenizer(s);
 int n=token.countTokens()-1;
 int m=n+1;
 String a="";
 int j=0;           
 while(token.hasMoreTokens())
 {a+=token.nextToken()+"\n";}
  return a;
}
  
  public void actionPerformed( ActionEvent e)
  {
	 if(e.getSource()==sentencebox)
        {   sentence=sentencebox.getText();
	        t.setText(enterString(sentence)); }
     repaint();
  }
public void itemStateChanged(ItemEvent e)
{   if(e.getSource()==bold)
    { if(e.getStateChange()==ItemEvent.SELECTED)
        {bold_font=Font.BOLD;}
      else
        {bold_font=Font.PLAIN;}
    }
    else if(e.getSource()==italic)
    { if(e.getStateChange()==ItemEvent.SELECTED)
        {italic_font=Font.ITALIC;}
      else
        {italic_font=Font.PLAIN;}
    }
    t.setFont(new Font("TimesRoman",bold_font+italic_font,24));
    repaint();
}
}
