import java.io.*;
import java.applet.Applet;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;


public class  radio_control extends JApplet implements ActionListener,ItemListener
{
  
  JPanel inputPanel;
  JButton b;
  JTextField t;
  JRadioButton plain,bold,italic,bolditalic;
  ButtonGroup gurup;
  int kirmizi,yesil,mavi;
  int bold_font,italic_font;
  public Color col;
  String s;
  public void init()
  {    
	s="Change style of this writing control characters :   alt N Plain alt K Bold  alt t italic  alt a bold-italic";
	col=Color.blue;
    inputPanel=new JPanel();
    setLayout(new BorderLayout());
    inputPanel.setLayout(new GridLayout(1,4));
    b=new JButton("push the button to change the color");
    t=new JTextField(s);    
    italic_font=Font.PLAIN;
	bold_font=Font.PLAIN;
	JPanel  Check=new JPanel();
    Check.setLayout(new GridLayout(4,0));
    gurup=new ButtonGroup();
    plain=new JRadioButton("Plain");
    plain.setMnemonic('N');
    plain.setSelected(true);
    plain.addItemListener(this);
    gurup.add(plain);
    inputPanel.add(plain);
    bold=new JRadioButton("Bold");
    bold.setMnemonic('K');
    bold.setSelected(false);
    bold.addItemListener(this);
    gurup.add(bold);
    inputPanel.add(bold);

   italic=new JRadioButton("Italic");
   italic.setMnemonic('t');
   italic.setSelected(false);
   italic.addItemListener(this);
   gurup.add(italic);
   inputPanel.add(italic);

   bolditalic=new JRadioButton("Bold-Italic");
   bolditalic.setMnemonic('a');
   bolditalic.setSelected(false);
   bolditalic.addItemListener(this);
   gurup.add(bolditalic);
   inputPanel.add(bolditalic);
   
	t.setFont(new Font("TimesRoman",bold_font+italic_font,14));
    inputPanel.add(t);
      
    add(b,BorderLayout.NORTH);
    add(t,BorderLayout.CENTER);
    add(inputPanel,BorderLayout.SOUTH);
    b.addActionListener(this);
  }

public void itemStateChanged(ItemEvent e)
{    Object kutu=e.getItemSelectable();
 if(kutu==plain)
   {
   bold_font=Font.PLAIN;
   italic_font=Font.PLAIN;
   }
   else if(kutu==bold)
   {
   bold_font=Font.BOLD;
   italic_font=Font.PLAIN;
   }
 else if(kutu==italic)
   {
   bold_font=Font.PLAIN;
   italic_font=Font.ITALIC;
   }
 else if(kutu==bolditalic)
   {
   bold_font=Font.BOLD;
   italic_font=Font.ITALIC;
   }
   t.setFont(new Font("TimesRoman",bold_font+italic_font,14));
   repaint();
}


public void actionPerformed( ActionEvent e)
{
//tesadüfi col belirle düğmeye her basılışta rengi değiştir.	
kirmizi=(int)(255.0*Math.random());
yesil  =(int)(255.0*Math.random());
mavi   =(int)(255.0*Math.random());
col=new Color(kirmizi,yesil,mavi);
//input panelin rengini değiştiriyoruz
inputPanel.setBackground(col);
//ana panelin rengini değiştiriyoruz
setBackground(col);
//yazı kutusunun rengini değiştiriyoruz
t.setBackground(col);
plain.setBackground(col);
bold.setBackground(col);
italic.setBackground(col);
bolditalic.setBackground(col);
repaint();
}

    public static void main(String s[])
    {
        JFrame f = new JFrame("list graphic controller");
        f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        JApplet applet = new radio_control();
        f.getContentPane().add("Center", applet);
        applet.init();
        f.setSize(800,500);
        f.setVisible(true); 
    }
}
