iT邦幫忙

0

如何執行網上別人沒有main的java程式[how to use the java code]

  • 分享至 

  • xImage

原始文章網址:https://www.javaexamples.org/java/java.awt.datatransfer/implementing-flavormap-interface.html

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.

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

0
Darwin Watterson
iT邦好手 1 級 ‧ 2022-11-29 09:47:22

都噴 error 了,這樣執行算成功嗎?/images/emoticon/emoticon19.gif
沒有 main 方法可以自己寫一個 main 方法測試。

public void static main(string[] args) {
  FlavorMapExample testf = new FlavorMapExample();
  // do something
}

或者透過 junit 寫單元測試也行。

x19729601 iT邦新手 5 級 ‧ 2022-12-04 22:00:40 檢舉

恩....先感謝回答..=V="
上面的程式碼你能演示一下嗎= =
不太懂它的作用= ="
FlavorMap 能做些什麼?

我要發表回答

立即登入回答