Veri Tra Tr n a sf s e f ri Kes ve Yapışt ş ır 1

Similar documents
16.1 DataFlavor DataFlavor Methods. Variables

CS 335 Lecture 06 Java Programming GUI and Swing

java.awt.datatransfer Reference

INTRODUCTION TO COMPUTER PROGRAMMING. Richard Pierse. Class 7: Object-Oriented Programming. Introduction

Tutorial Reference Manual. Java WireFusion 4.1

Advanced Network Programming Lab using Java. Angelos Stavrou

5.17 GUI. Xiaoyi Jiang Informatik I Grundlagen der Programmierung

public class Craps extends JFrame implements ActionListener { final int WON = 0,LOST =1, CONTINUE = 2;

Homework/Program #5 Solutions

core 2 Handling Mouse and Keyboard Events

file://c:\dokumente und Einstellungen\Marco Favorito\Desktop\ScanCmds.html

java.applet Reference

Schueler-Organisiertes Lernen am Beispiel von Grafischen Benutzer-Schnittstellen in Java Tag der Offenen Tür - GTS 2008

The following four software tools are needed to learn to program in Java:

Here's the code for our first Applet which will display 'I love Java' as a message in a Web page

// Correntista. //Conta Corrente. package Banco; public class Correntista { String nome, sobrenome; int cpf;

Creating a Simple, Multithreaded Chat System with Java

Remote Method Invocation

public class Application extends JFrame implements ChangeListener, WindowListener, MouseListener, MouseMotionListener {

Assignment No.3. /*-- Program for addition of two numbers using C++ --*/

Analysis Of Source Lines Of Code(SLOC) Metric

Graphical User Interfaces

Event-Driven Programming

Using A Frame for Output

Programming with Java GUI components

CSS 543 Program 3: Online Tic-Tac-Toe Game Professor: Munehiro Fukuda Due date: see the syllabus

Essentials of the Java(TM) Programming Language, Part 1

11. Applets, normal window applications, packaging and sharing your work

Dreamweaver and Fireworks MX Integration Brian Hogan


Providing Information (Accessors)

First Java Programs. V. Paúl Pauca. CSC 111D Fall, Department of Computer Science Wake Forest University. Introduction to Computer Science

The Abstract Windowing Toolkit. Java Foundation Classes. Swing. In April 1997, JavaSoft announced the Java Foundation Classes (JFC).

How to develop your own app

GUI Event-Driven Programming

How To Write A Program For The Web In Java (Java)

Fondamenti di Java. Introduzione alla costruzione di GUI (graphic user interface)

WEB DESIGN COURSE CONTENT

Chapter 2 Introduction to Java programming

GUIs with Swing. Principles of Software Construction: Objects, Design, and Concurrency. Jonathan Aldrich and Charlie Garrod Fall 2012

Fireworks 3 Animation and Rollovers

Essentials of the Java Programming Language

How To Use The Command Pattern In Java.Com (Programming) To Create A Program That Is Atomic And Is Not A Command Pattern (Programmer)

Visual Basic Programming. An Introduction

Lösningsförslag till tentamen

HTML Form Widgets. Review: HTML Forms. Review: CGI Programs

Java Appletek II. Applet GUI

Chulalongkorn University International School of Engineering Department of Computer Engineering Computer Programming Lab.

A10 Writing Your First Application

LAB4 Making Classes and Objects

Importance of the Java Inet Address and Public String Hosting System

Hypercosm. Studio.

The Basic Java Applet and JApplet

Draw pie charts in Excel

The first program: Little Crab

Extending Desktop Applications to the Web

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Handout 3 cs180 - Programming Fundamentals Spring 15 Page 1 of 6. Handout 3. Strings and String Class. Input/Output with JOptionPane.

Documentation revised 08/25/15 by S. Collins, UDit. Credit to T. Greaney, A&S Computing for assisting with content in sections 2 and 3.

2 The first program: Little Crab

Licensed for viewing only. Printing is prohibited. For hard copies, please purchase from

JIDE Action Framework Developer Guide

Hotspot Image Connector Page Guide

The Snake Game Java Case Study

public class demo1swing extends JFrame implements ActionListener{

Chapter 1 Java Program Design and Development

Working with the Ektron Content Management System

Web Development and Core Java Lab Manual V th Semester

Credit Scores in Online Banking

Appendix B Task 2: questionnaire and artefacts

LAB 6: Code Generation with Visual Paradigm for UML and JDBC Integration

Callbacks. Callbacks Copyright 2007 by Ken Slonneger 1

Creating Fill-able Forms using Acrobat 8.0: Part 1

Barcode Support. Table of Contents

A TOOL FOR DATA STRUCTURE VISUALIZATION AND USER-DEFINED ALGORITHM ANIMATION

Creating and Using Forms in SharePoint

Animations with Booleans

Flash MX Image Animation

Dev Articles 05/25/07 11:07:33

Triggers & Actions 10

Swing. A Quick Tutorial on Programming Swing Applications

LAB 1. Familiarization of Rational Rose Environment And UML for small Java Application Development

LESSON 7: IMPORTING AND VECTORIZING A BITMAP IMAGE

Introduction to pop-ups

How to Setup and Connect to an FTP Server Using FileZilla. Part I: Setting up the server

Creating Comic Life Images Using Microsoft Word, Clipart, and Irfanview.

ADF Code Corner. 66. How-to color-highlight the bar in a graph that represents the current row in the collection. Abstract: twitter.

JiST Graphical User Interface Event Viewer. Mark Fong

ADOBE ACROBAT 7.0 CREATING FORMS

CSE 1223: Introduction to Computer Programming in Java Chapter 7 File I/O

With a single download, the ADT Bundle includes everything you need to begin developing apps:

Tips for clear websites

Crash Course in Java

USING MYWEBSQL FIGURE 1: FIRST AUTHENTICATION LAYER (ENTER YOUR REGULAR SIMMONS USERNAME AND PASSWORD)

How to create buttons and navigation bars

Application Monitor Application (APPMON)

Event processing in Java: what happens when you click?

Praat Tutorial. Pauline Welby and Kiwako Ito The Ohio State University. January 13, 2002

Computing Concepts with Java Essentials

1 Hour, Closed Notes, Browser open to Java API docs is OK

Transcription:

Veri Transferi Kes ve Yapıştır ş 1

import java.awt.*; import java.awt.datatransfer.*; import java.awt.event.*; /** * This program demonstrates how to add string cut andpaste capabilities * to an application. i **/ public class StringCutAndPaste extends Frame implements ActionListener { public static void main(string[] args) { Frame f = new StringCutAndPaste(); f.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent i d e) { System.exit(0); ); f.pack(); f.show(); 2

TextField field; public StringCutAndPaste() { this.setfont(new Font("SansSerif", Font.PLAIN, 14)); // Use a nice font // Set up the Cut button Button cut = new Button("Cut"); cut.addactionlistener(this); cut.setactioncommand("cut"); this.add(cut, "West"); // Set up the Paste button Button paste = new Button("Paste"); paste.addactionlistener(this); paste.setactioncommand("paste"); this.add(paste, "East"); // Set up the text field that they both operate on field = new TextField(); this.add(field, "North"); 3

public void actionperformed(actionevent e) { String cmd = e.getactioncommand(); if (cmd.equals("cut")) ( cut(); else if (cmd.equals("paste")) paste(); public void cut() { String s = field.gettext(); StringSelection ss = new StringSelection(s); this.gettoolkit().getsystemclipboard().setcontents(ss, ss); 4

public void paste() { Clipboard c = this.gettoolkit().getsystemclipboard(); Transferable t = c.getcontents(this); try { String s = (String) t.gettransferdata(dataflavor.stringflavor); field.settext(s); catch (Exception e) { this.gettoolkit().beep(); return; 5

6

ScribbleCutAndPaste.java import java.awt.*; import java.awt.event.*; import java.awt.datatransfer.*; // Clipboard, Transferable, DataFlavor, etc. import java.util.vector; // To store the scribble in public class ScribbleCutAndPaste extends Frame { public static void main(string[] args) { new ScribbleCutAndPaste(); protected static int num_windows = 0; public ScribbleCutAndPaste() { super("scribblecutandpaste"); // Create the window num_windows++; // Count it ScribblePanel scribble = new ScribblePanel(this, 400, 300); this.add(scribble, "Center"); MenuBar menubar = new MenuBar(); // Create menubar this.setmenubar(menubar); // Add it to the frame Menu file = new Menu("File"); // Create a File menu menubar.add(file); // Add to menubar MenuItem n, c, q; 7

file.add(n = new MenuItem("New Window", new MenuShortcut(KeyEvent.VK_N))); file.add(c = new MenuItem("Close Window",new MenuShortcut(KeyEvent.VK_W))); file.addseparator(); file.add(q = new MenuItem("Quit", new MenuShortcut(KeyEvent.VK_Q))); n.addactionlistener(new ActionListener() { // Open a new window public void actionperformed(actionevent e) { new ScribbleCutAndPaste(); ); c.addactionlistener(new ActionListener() { // Close this window public void actionperformed(actionevent e) { close(); ); q.addactionlistener(new ActionListener() { // Quit the program public void actionperformed(actionevent e) { System.exit(0); ); this.addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent e) { close(); ); this.pack(); this.show(); 8

void close() { if ( num_windows == 0) System.exit(0); else this.dispose(); static class ScribblePanel extends Canvas implements ActionListener { protected short last_x, last_y; // Coordinates of last click protected Vector lines = new Vector(256,256); // Store the scribbles protected int width, height; // The preferred size protected PopupMenu popup; // The popup menu protected Frame frame; // The frame we are within ihi public ScribblePanel(Frame frame, int width, int height) { this.frame = frame; this.width id h = width; this.height = height; this.enableevents(awtevent.mouse_event_mask); this.enableevents(awtevent.mouse_motion_event_mask); MOTION EVENT MASK) String[] labels = new String[] { "Clear", "Cut", "Copy", "Paste" ; String[] commands = new String[] { "clear", "cut", "copy", "paste" ; 9

popup = new PopupMenu(); // Create the menu for(int i = 0; i < labels.length; length; i++) { MenuItem mi = new MenuItem(labels[i]); // Create a menu item mi.setactioncommand(commands[i]); // Set its action command mi.addactionlistener(this); // And its action listener popup.add(mi); // Add item to the popup menu this.add(popup); public Dimension getpreferredsize() {return new Dimension(width, height); public void actionperformed(actionevent event) { String command = event.getactioncommand(); if (command.equals("clear")) clear(); else if (command.equals("cut")) cut(); else if (command.equals( equals("copy")) copy)) copy(); else if (command.equals("paste")) paste(); 10

public void paint(graphics g) { for(int i = 0; i < lines.size(); i++) { Line l = (Line)lines.elementAt(i); g.drawline(l.x1, l.y1, l.x2, l.y2); public void processmouseevent(mouseevent e) { if (e.ispopuptrigger()) // If popup trigger, popup.show(this, e.getx(), e.gety()); // Pop up the menu else if (e.getid() == MouseEvent.MOUSE_PRESSED) { // Otherwise last_x = (short)e.getx(); last_y = (short)e.gety(); // Save position else super.processmouseevent(e); // Pass other event types on public void processmousemotionevent(mouseevent e) { if (e.getid() == MouseEvent.MOUSE_DRAGGED) { Graphics g = getgraphics(); // Object to draw with g.drawline(last_x, last_y, e.getx(), e.gety()); // Draw this line lines.addelement(new Line(last_x, last_y, // And save it, too. (short) e.getx(), (short)e.gety())); last_x = (short) e.getx(); // Remember current mouse coordinates last_y = (short) e.gety(); else super.processmousemotionevent(e); // Important! 11

void clear() { lines.removeallelements(); // Throw out the saved scribble repaint(); // And redraw everything. public static final DataFlavor dataflavor = new DataFlavor(Vector.class, "ScribbleVectorOfLines"); public void copy() { Clipboard c = this.gettoolkit().getsystemclipboard(); SimpleSelection s = new SimpleSelection(lines.clone(), dataflavor); c.setcontents(s, s); public void cut() { copy(); clear(); 12

public void paste() (){ Clipboard c = this.gettoolkit().getsystemclipboard(); // Get clipboard Transferable t = c.getcontents(this); // Get its contents if (t == null) { // If there is nothing to paste, beep this.gettoolkit().beep(); return; try { // Ask for clipboard contents to be converted to our data flavor. // This will throw an exception if our flavor is not supported. Vector newlines = (Vector) t.gettransferdata(dataflavor); // Add all those pasted lines to our scribble. for(int i = 0; i < newlines.size(); i++) lines.addelement(newlines.elementat(i)); // And redraw the whole thing repaint(); catch (UnsupportedFlavorException e) { this.gettoolkit().beep(); // If clipboard has some other type of data catch (Exception e) { this.gettoolkit().beep(); // Or if anything else goes wrong... 13

static class SimpleSelection implements Transferable, ClipboardOwner { protected Object selection; // The data to be transferred protected DataFlavor flavor; // The one data flavor supported public SimpleSelection(Object selection, DataFlavor flavor) { this.selection = selection; // Specify data this.flavor = flavor; // Specify flavor public DataFlavor[] gettransferdataflavors() { return new DataFlavor[] { flavor ; public boolean isdataflavorsupported(dataflavor f) { return f.equals(flavor); public Object gettransferdata(dataflavor f) throws UnsupportedFlavorException { if (f.equals(flavor)) return selection; else throw new UnsupportedFlavorException(f); public void lostownership(clipboard c, Transferable t) { selection = null; static class Line { public short x1, y1, x2, y2; publicline(shortx1, short y1, short x2, short y2) { this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; 14

15