import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.FlavorMap;
import java.util.HashMap;
import java.util.Map;
public class FlavorMapExample implements FlavorMap {
@Override
public Map<DataFlavor, String> getNativesForFlavors(DataFlavor[] flavors) {
Map<DataFlavor, String> nativesMap = new HashMap<DataFlavor, String>();
DataFlavor dataFlavor = new DataFlavor(java.awt.TextField.class,
"AWT TextField");
nativesMap.put(dataFlavor, "dataFlavor");
return nativesMap;
}
@Override
public Map<String, DataFlavor> getFlavorsForNatives(String[] natives) {
Map<String, DataFlavor> nativesMap = new HashMap<String, DataFlavor>();
DataFlavor dataFlavor = new DataFlavor("text/plain; charset=ASCII", "Plain ASCII text");
nativesMap.put("dataFlavor",dataFlavor);
return nativesMap;
}
}
執行有成功但沒有main
output
Error: Main method not found in class FlavorMapExample, please define the main method as:
public static void main(String[] args)
or a JavaFX application class must extend javafx.application.Application
Process completed.
都噴 error 了,這樣執行算成功嗎?
沒有 main 方法可以自己寫一個 main 方法測試。
public void static main(string[] args) {
FlavorMapExample testf = new FlavorMapExample();
// do something
}
或者透過 junit 寫單元測試也行。