import java.applet.*;
import java.awt.*;
import java.awt.event.*;
class TextDemo extends Frame implements ActionListener,KeyListener,WindowListener
{
TextField tSrc,tDst;
Button bCpy,bMov,bSel,bClr;
TextDemo()
{
setTitle("TextDemo");
setSize(550,350);
setBackground(new Color(150,150,150));
tSrc=new TextField();
tSrc.setFont(new Font("lucida console",Font.PLAIN,18));
tDst=new TextField();
tDst.setFont(new Font("lucida console",Font.PLAIN,18));
tDst.setEditable(false);
bCpy=new Button("Copy");
bCpy.setFont(new Font("lucida console",Font.PLAIN,18));
bCpy.setBackground(new Color(255,190,190));
bCpy.setEnabled(false);
bMov=new Button("Move");
bMov.setFont(new Font("lucida console",Font.PLAIN,18));
bMov.setBackground(new Color(255,190,190));
bMov.setEnabled(false);
bSel=new Button("Copy Selected");
bSel.setFont(new Font("lucida console",Font.PLAIN,18));
bSel.setBackground(new Color(255,190,190));
bSel.setEnabled(false);
bClr=new Button("Clear");
bClr.setFont(new Font("lucida console",Font.PLAIN,18));
bClr.setBackground(new Color(190,255,190));
Label l1=new Label("Source");
l1.setFont(new Font("lucida console",Font.PLAIN,18));
Label l2=new Label("Destination");
l2.setFont(new Font("lucida console",Font.PLAIN,18));
setLayout(new GridLayout(4,1,10,10));
Panel p1=new Panel();
p1.setLayout(new BorderLayout(43,10));
p1.add(l1,BorderLayout.WEST);
p1.add(tSrc,BorderLayout.CENTER);
Panel p2=new Panel();
p2.setLayout(new BorderLayout(10,10));
p2.add(l2,BorderLayout.WEST);
p2.add(tDst,BorderLayout.CENTER);
Panel p3=new Panel();
p3.setLayout(new GridLayout(1,4,5,10));
p3.add(bCpy);
p3.add(bMov);
p3.add(bSel);
p3.add(bClr);
add(p1);
add(p2);
add(new Label());
add(p3);
bCpy.addActionListener(this);
bMov.addActionListener(this);
bSel.addActionListener(this);
bClr.addActionListener(this);
tSrc.addKeyListener(this);
addWindowListener(new MyWndAdapter(this));
}
public Insets getInsets()
{
return new Insets(50,20,20,20);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bClr)
{
tSrc.setText("");
tDst.setText("");
bCpy.setEnabled(false);
bMov.setEnabled(false);
bSel.setEnabled(false);
}
else
if(ae.getSource()==bCpy)
tDst.setText(tSrc.getText());
else
if(ae.getSource()==bMov)
{
tDst.setText(tSrc.getText());
tSrc.setText("");
bCpy.setEnabled(false);
bMov.setEnabled(false);
bSel.setEnabled(false);
}
else
if(ae.getSource()==bSel)
{
tDst.setText(tSrc.getSelectedText());
}
}
public void keyTyped(KeyEvent ke){}
public void keyPressed(KeyEvent ke){}
public void keyReleased(KeyEvent ke)
{
if(tSrc.getText().length()==0)
{
bCpy.setEnabled(false);
bMov.setEnabled(false);
bSel.setEnabled(false);
}
else
{
bCpy.setEnabled(true);
bMov.setEnabled(true);
bSel.setEnabled(true);
}
}
@Override
public void windowOpened(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowClosing(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowClosed(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowIconified(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowDeiconified(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowActivated(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowDeactivated(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class MyWndAdapter extends WindowAdapter
{
TextDemo td;
MyWndAdapter(TextDemo td)
{
this.td=td;
}
public void windowClosing(WindowEvent we)
{
td.dispose();
System.exit(0);
}
}
class Text
{
public static void main(String arg[])
{
TextDemo td;
td=new TextDemo();
td.setVisible(true);
}
}
----------------------------------------------------------------------------------------------------------
steps to run the Demo program of Text
step1: save the file as textdemo.java file in the bin and refresh it.
step2: after that open ur command prompt and write the path of ur jdk
like my jdk path is
C:\java\jdk1.7.0_10\bin
step3: if u not know how to make path then follow the steps below
step4: after that to execute the program do the following
if there is no error then proceed to step5 otherwise correct the error
step5:after success of step4 perform the following
after this a window appear like this
enjoy!! ;)
if u have any queries then message me on
rawlot007bhati@gmail.com
import java.awt.*;
import java.awt.event.*;
class TextDemo extends Frame implements ActionListener,KeyListener,WindowListener
{
TextField tSrc,tDst;
Button bCpy,bMov,bSel,bClr;
TextDemo()
{
setTitle("TextDemo");
setSize(550,350);
setBackground(new Color(150,150,150));
tSrc=new TextField();
tSrc.setFont(new Font("lucida console",Font.PLAIN,18));
tDst=new TextField();
tDst.setFont(new Font("lucida console",Font.PLAIN,18));
tDst.setEditable(false);
bCpy=new Button("Copy");
bCpy.setFont(new Font("lucida console",Font.PLAIN,18));
bCpy.setBackground(new Color(255,190,190));
bCpy.setEnabled(false);
bMov=new Button("Move");
bMov.setFont(new Font("lucida console",Font.PLAIN,18));
bMov.setBackground(new Color(255,190,190));
bMov.setEnabled(false);
bSel=new Button("Copy Selected");
bSel.setFont(new Font("lucida console",Font.PLAIN,18));
bSel.setBackground(new Color(255,190,190));
bSel.setEnabled(false);
bClr=new Button("Clear");
bClr.setFont(new Font("lucida console",Font.PLAIN,18));
bClr.setBackground(new Color(190,255,190));
Label l1=new Label("Source");
l1.setFont(new Font("lucida console",Font.PLAIN,18));
Label l2=new Label("Destination");
l2.setFont(new Font("lucida console",Font.PLAIN,18));
setLayout(new GridLayout(4,1,10,10));
Panel p1=new Panel();
p1.setLayout(new BorderLayout(43,10));
p1.add(l1,BorderLayout.WEST);
p1.add(tSrc,BorderLayout.CENTER);
Panel p2=new Panel();
p2.setLayout(new BorderLayout(10,10));
p2.add(l2,BorderLayout.WEST);
p2.add(tDst,BorderLayout.CENTER);
Panel p3=new Panel();
p3.setLayout(new GridLayout(1,4,5,10));
p3.add(bCpy);
p3.add(bMov);
p3.add(bSel);
p3.add(bClr);
add(p1);
add(p2);
add(new Label());
add(p3);
bCpy.addActionListener(this);
bMov.addActionListener(this);
bSel.addActionListener(this);
bClr.addActionListener(this);
tSrc.addKeyListener(this);
addWindowListener(new MyWndAdapter(this));
}
public Insets getInsets()
{
return new Insets(50,20,20,20);
}
public void actionPerformed(ActionEvent ae)
{
if(ae.getSource()==bClr)
{
tSrc.setText("");
tDst.setText("");
bCpy.setEnabled(false);
bMov.setEnabled(false);
bSel.setEnabled(false);
}
else
if(ae.getSource()==bCpy)
tDst.setText(tSrc.getText());
else
if(ae.getSource()==bMov)
{
tDst.setText(tSrc.getText());
tSrc.setText("");
bCpy.setEnabled(false);
bMov.setEnabled(false);
bSel.setEnabled(false);
}
else
if(ae.getSource()==bSel)
{
tDst.setText(tSrc.getSelectedText());
}
}
public void keyTyped(KeyEvent ke){}
public void keyPressed(KeyEvent ke){}
public void keyReleased(KeyEvent ke)
{
if(tSrc.getText().length()==0)
{
bCpy.setEnabled(false);
bMov.setEnabled(false);
bSel.setEnabled(false);
}
else
{
bCpy.setEnabled(true);
bMov.setEnabled(true);
bSel.setEnabled(true);
}
}
@Override
public void windowOpened(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowClosing(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowClosed(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowIconified(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowDeiconified(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowActivated(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
@Override
public void windowDeactivated(WindowEvent e) {
throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}
}
class MyWndAdapter extends WindowAdapter
{
TextDemo td;
MyWndAdapter(TextDemo td)
{
this.td=td;
}
public void windowClosing(WindowEvent we)
{
td.dispose();
System.exit(0);
}
}
class Text
{
public static void main(String arg[])
{
TextDemo td;
td=new TextDemo();
td.setVisible(true);
}
}
----------------------------------------------------------------------------------------------------------
steps to run the Demo program of Text
step1: save the file as textdemo.java file in the bin and refresh it.
step2: after that open ur command prompt and write the path of ur jdk
like my jdk path is
C:\java\jdk1.7.0_10\bin
step3: if u not know how to make path then follow the steps below
step4: after that to execute the program do the following
if there is no error then proceed to step5 otherwise correct the error
step5:after success of step4 perform the following
after this a window appear like this
enjoy!! ;)
if u have any queries then message me on
rawlot007bhati@gmail.com




No comments:
Post a Comment