Text Transfer Test : Clip « 2D Graphics GUI « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Class
8. Collections Data Structure
9. Data Type
10. Database SQL JDBC
11. Design Pattern
12. Development Class
13. EJB3
14. Email
15. Event
16. File Input Output
17. Game
18. Generics
19. GWT
20. Hibernate
21. I18N
22. J2EE
23. J2ME
24. JDK 6
25. JNDI LDAP
26. JPA
27. JSP
28. JSTL
29. Language Basics
30. Network Protocol
31. PDF RTF
32. Reflection
33. Regular Expressions
34. Scripting
35. Security
36. Servlets
37. Spring
38. Swing Components
39. Swing JFC
40. SWT JFace Eclipse
41. Threads
42. Tiny Application
43. Velocity
44. Web Services SOA
45. XML
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java » 2D Graphics GUI » ClipScreenshots 
Text Transfer Test
Text Transfer Test
   
/**
 @version 1.10 1999-09-16
 @author Cay Horstmann
 */

import java.awt.Container;
import java.awt.Toolkit;
import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class TextTransferTest {
  public static void main(String[] args) {
    JFrame frame = new TextTransferFrame();
    frame.show();
  }
}

class TextTransferFrame extends JFrame implements ActionListener {
  public TextTransferFrame() {
    setTitle("TextTransferTest");
    setSize(300300);
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    });

    Container contentPane = getContentPane();

    textArea = new JTextArea();
    contentPane.add(new JScrollPane(textArea)"Center");
    JPanel panel = new JPanel();
    copyButton = new JButton("Copy");
    panel.add(copyButton);
    copyButton.addActionListener(this);
    pasteButton = new JButton("Paste");
    panel.add(pasteButton);
    pasteButton.addActionListener(this);
    contentPane.add(panel, "South");
    sysClipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
  }

  public void actionPerformed(ActionEvent event) {
    Object source = event.getSource();
    if (source == copyButton)
      copy();
    else if (source == pasteButton)
      paste();
  }

  private void copy() {
    String text = textArea.getSelectedText();
    if (text.equals(""))
      text = textArea.getText();
    StringSelection selection = new StringSelection(text);
    sysClipboard.setContents(selection, null);
  }

  private void paste() {
    String text;
    Transferable contents = sysClipboard.getContents(this);
    if (contents == null)
      return;
    try {
      text = (String) (contents.getTransferData(DataFlavor.stringFlavor));
      textArea.replaceSelection(text);
    catch (Exception e) {
      textArea.append("Error: " + e);
    }
  }

  private JTextArea textArea;

  private JButton copyButton;

  private JButton pasteButton;

  private Clipboard sysClipboard;
}

           
         
    
    
  
Related examples in the same category
1. Clip the areaClip the area
2. Clip ImageClip Image
3. Clip another areaClip another area
4. Clip TestClip Test
5. Setting the Clipping Area with a Shape
6. Copy Area Performance
7. Clipping is restricting of drawing to a certain area.Clipping is restricting of drawing to a certain area.
8. set Clip and get Clip
9. Represents a clipping rectangle in a prefuse DisplayRepresents a clipping rectangle in a prefuse Display
10. Clips the specified line to the given rectangle.
www___.__ja___v___a__2_s_.co___m___ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.