9, ఏప్రిల్ 2012, సోమవారం

A SAMPLE APPLICATION BY USING JAVA.DATATRANSFER PACKAGE MY CLASS ROOM PRACTICE EXAMPLE ON MAR.2002


/*STRING SELECTION THIS CLASS PROVIDES THE FACILITIES TO TRANSFER THE DATA TRANSFERABLE THIS CLASS PROVIDES FACILITIES FOR THE DATA TRANSFER DATA FLAVOR CLASS PROVIDES THE FEATURES OF THE DATA ENCAPSULATION */
NOTE :-   In this program I have used some deprecated methods and one package java.datatransfer it may give u some trouble in the case  the package is not available this an exercise to my class students so i deliberately kept in this some bugs if you read the program and this  link theory u will be able to run this program successfully this program will sharpen u r brain and enrich u r thinking in java  see for theory http://happy.cs.vt.edu/~manuel/courses/cs5774-F08/slides/java/8-Clipboard/Clipboard.pdf  i am framing the  some of practical code over here

import java.awt.*;
import java.awt.event.*;
import java.datatransfer.*;
class w extends WindowAdapter
{
public void windowClosing(WindowEvent we)
{
System.exit(0);
}}
class Cp extends Frame
{
MenuBar mb;
Menu edit;
MenuItem cut,copy,paste;
TextArea ta;
Clipboard cb;
Cp()
{
addWindowListener(new w());
setLayout(null);
mb=new MenuBar();
setMenuBar(mb);
edit =new Menu("edit");
mb.add(edit);
cut=new MenuItem("cut");
copy=new MenuItem("copy");
paste=new MenuItem("paste");
edit.add(cut);
edit.add(copy);
edit.add(paste);
ta=new TextArea(10,20);
ta.setBounds(100,100,500,200);
add(ta);
cb=getToolKit().getSystemClipboard();
cut.addActionListener(new MyCut());
copy.addActionListener(new MyCopy());
paste.addActionListener(new MyPaste());
}

class MyCopy implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
String s=ta.getSelectedText();
StringSelection ss=new StringSelection(s);
cb.setContents(ss,ss);
}
}

class MyCut implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
String s=ta.getSelectedText();
stringselection ss=new stringselection(s);
cb.setContents(ss,ss);
ta.repalceRange("",ta.getSelectionStart(),ta.getSelectionEnd());
}}

class Mypaste implements ActionListener
{
public void actionPerformed(ActionEvent ae)
{
Transferable t=cb.getContents(this);
try
{
String s=(String)t.getTransferData(DataFlavor.stringFlavor);
ta.replaceRange(s,ta.getSelectionStart(),getSelectionEnd());
}
catch(Exception e)
{}
}}
//write u r own code to bring completeness to this program study the above theory u will what is lagging in this don't try to execute directly this

cp1.setVisible(true);
cp1.setBounds(0,0,800,600);
}}

కామెంట్‌లు లేవు:

కామెంట్‌ను పోస్ట్ చేయండి