Java
/
I/O
- 1 Basics 9
-
Classes S
-
Objects S
-
Arrays S
-
Variables S
-
Loops S
-
Numbers S
-
Strings S
-
Exceptions S
-
Regexp S
- 2 OOP 9
-
Inheritance
-
Polymorphism
-
Static S
-
Abstract
-
Interfaces
-
Constructors S
-
Packages
-
Nested Classes
-
Final
- 3 Compiler 2
-
Sublime Text S
-
Apache Ant
- 4 Collections 8
-
Lists
-
Comparable S
-
Sets
-
Maps
-
Generics
-
Properties
-
Streams
-
Json
- 5 Threads 4
-
Create Thread S
-
Sleep
-
Lock
-
Scheduler
- 6 Design Patterns 4
-
Singleton
-
Observer
-
Strategy
-
Mediator
- 7 Swing 12
-
Frame
-
Panel
-
Listener
-
Combo Box
-
Label
-
Image
-
Menu
-
Table
-
Layout
-
Drawing
-
Timer
-
Designer
- 8 I/O 7
-
Streams IO
-
Socket
-
Watching Files
-
Mail
-
Logger
-
Clipboard
-
Encrypt S
- 9 Effective 7
-
Constructors S
-
Dependency Injection
-
Composition
-
Interfaces Default
-
Import Static S
-
Enums
-
Lambdas
- 10 Junit 5
-
About Junit S
-
Test Case
-
Suite Test
-
Annotations
-
Exceptions
- 11 Lambdas 7
-
Expressions S
-
Functional Interfaces
-
Streams
-
Common Operations
-
Default Methods
-
Static Methods S
-
Single Responsibility
- 12 JavaFX 6
-
Openjfx
-
Scene Builder
-
First App
-
Jar Archive
-
On Action
-
Change Listener
- 13 Maven 4
-
Demo
-
Spring Boot
-
Junit
-
Guava
- 14 Spring Boot 13
-
Quick start S
-
Rest service S
-
Consuming rest S
-
Templates S
-
Security auth S
-
Command line S
-
Scheduled task S
-
Ajax S
-
Jdbc mysql S
-
Encrypt password S
-
Https S
-
Jwt S
-
Post request S
R
Q
Clipboard
Use datatransfer package to copy/paste text in clipboard.
/**
* Clipboard app:
* Use Ctrl-C to copy text in clipboard
* The clipboard text will be displayed on runtime.
*/
package com.minte9.io.clipboard;
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.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
public class ClipboardApp {
public static void main(String[] args) throws InterruptedException {
StringSelection ss = new StringSelection("abc");
Clipboard cp = Toolkit.getDefaultToolkit().getSystemClipboard();
cp.setContents(ss, null);
while(true) {
String text = getFromClipboard();
System.out.println(text);
Thread.sleep(2000);
}
}
public static void copyToClipboard(String text) {
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(new StringSelection(text), null);
}
public static String getFromClipboard() {
Transferable t =
Toolkit.getDefaultToolkit().getSystemClipboard()
.getContents(null);
try {
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return t.getTransferData(DataFlavor.stringFlavor).toString();
}
} catch (UnsupportedFlavorException | IOException ex) {}
return null;
}
}
Bullets
Add bullets to every line (text from clipboard).
/**
* Add bullets:
* Get text from clipboard and add bullets to every line.
* Use Ctrl-C to copy text in clipboard
* The clipboard text will be displayed on runtime.
*/
package com.minte9.io.clipboard;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.StringSelection;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.IOException;
import java.util.List;
import java.util.stream.Collectors;
import static java.util.Arrays.asList;
public class BulletsApp {
public static void main(String[] args) throws InterruptedException {
CP.copyToClipboard(" abc \n def");
List<String> A;
String text;
while (true) {
text = CP.getFromClipboard();
A = asList(text.split("\n"));
text = A.stream()
.map(x -> "* " + x)
.collect(Collectors.joining("\n"));
System.out.println(text);
Thread.sleep(2000);
}
}
}
class CP {
public static void copyToClipboard(String text) {
Toolkit.getDefaultToolkit().getSystemClipboard()
.setContents(new StringSelection(text), null);
}
public static String getFromClipboard() {
Transferable t = Toolkit.getDefaultToolkit().getSystemClipboard()
.getContents(null);
try {
if (t.isDataFlavorSupported(DataFlavor.stringFlavor)) {
return t.getTransferData(DataFlavor.stringFlavor).toString();
}
} catch (UnsupportedFlavorException | IOException ex) {
}
return null;
}
}
➥ Questions