/**
* @(#)Text_Editor.java
*
*
* @author anant
* @version 1.00 2013/9/17
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class Text_Editor
{
public static void main(String []args)
{
myframe m=new myframe();
m.setTitle("Text Editor");
m.setSize(500,500);
m.setVisible(true);
m.setLocation(500,100);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
class myframe extends JFrame
{
mypanel p;
myframe()
{
p=new mypanel();
Container c=getContentPane();
c.add(p);
}
class mypanel extends JPanel implements ActionListener,ItemListener
{
JTextArea txta_show;
JComboBox cmb_font;
JLabel lbl_size;
JTextField txt_size;
JCheckBox cb_bold,cb_italic;
int i=0;
String font;
JButton btn_ok;
mypanel()
{
setLayout(null);
txta_show=new JTextArea();
JScrollPane pane=new JScrollPane(txta_show);
pane.setBounds(50,10,400,300);
add(pane);
cmb_font=new JComboBox();
cmb_font.addItem("Curlz MT");
cmb_font.addItem("Forte");
cmb_font.addItem("Freestyle Script");
cmb_font.addItem("French Script MT");
cmb_font.addItem("Gigi");
cmb_font.addItem("Harrington");
cmb_font.addItem("Informal Roman");
cmb_font.addItem("Jokerman");
cmb_font.setBounds(50,350,100,30);
cmb_font.addItemListener(this);
add(cmb_font);
lbl_size=new JLabel("Size");
lbl_size.setBounds(175,350,75,30);
add(lbl_size);
txt_size=new JTextField();
txt_size.setBounds(210,350,50,30);
add(txt_size);
cb_bold=new JCheckBox("Bold");
cb_bold.setBounds(275,350,75,30);
cb_bold.addActionListener(this);
add(cb_bold);
cb_italic=new JCheckBox("Italic");
cb_italic.setBounds(350,350,100,30);
cb_italic.addActionListener(this);
add(cb_italic);
btn_ok=new JButton("Ok");
btn_ok.setBounds(50,400,100,30);
btn_ok.addActionListener(this);
add(btn_ok);
}
public void itemStateChanged(ItemEvent ie)
{
if(ie.getSource()==cmb_font)
{
i=cmb_font.getSelectedIndex();
if(i==0)
font="Curlz MT";
else if(i==1)
font="Forte";
else if(i==2)
font="Freestyle Script";
else if(i==3)
font="French Script MT";
else if(i==4)
font="Gigi";
else if(i==5)
font="Harrington";
else if(i==6)
font="Informal Roman";
else if(i==7)
font="Jokerman";
}
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==btn_ok)
{
int size=Integer.parseInt(txt_size.getText());
if(cb_bold.isSelected()&&cb_italic.isSelected())
txta_show.setFont(new Font(font,Font.BOLD+Font.ITALIC,size));
else if(cb_bold.isSelected())
txta_show.setFont(new Font(font,Font.BOLD,size));
else if(cb_italic.isSelected())
txta_show.setFont(new Font(font,Font.ITALIC,size));
else
txta_show.setFont(new Font(font,Font.PLAIN,size));
}
}
}
}