Last active
August 29, 2015 14:09
-
-
Save st98/77561b936ef524d7cdea to your computer and use it in GitHub Desktop.
getFonts, Flash で実装しているのを見て Java アプレットでもやってみたいなーと思った。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// applet/GetFonts.java | |
package applet; | |
import java.applet.Applet; | |
import java.awt.Font; | |
import java.awt.GraphicsEnvironment; | |
public class GetFonts extends Applet { | |
public String s = "getFonts"; | |
public String getFonts() { | |
GraphicsEnvironment g = GraphicsEnvironment.getLocalGraphicsEnvironment(); | |
Font fonts[] = g.getAllFonts(); | |
StringBuilder s = new StringBuilder(); | |
for (int i = 0; i < fonts.length; i++) { | |
s.append(fonts[i].getName()); | |
s.append(";"); | |
} | |
return new String(s); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html lang="ja"> | |
<head> | |
<meta charset="utf-8"> | |
<title>getfonts</title> | |
</head> | |
<body> | |
<embed code="applet/GetFonts.class" id="applet" type="application/x-java-applet" width="0" height="0"></embed> | |
<script> | |
var t = setInterval(main, 1000); | |
function main() { | |
var fonts, ul, li, i; | |
try { | |
fonts = document.getElementById('applet').getFonts(); | |
fonts = fonts.split(';').slice(0, -1); | |
ul = document.createElement('ul'); | |
console.log(fonts); | |
for (i = 0; i < fonts.length; i++) { | |
li = document.createElement('li'); | |
li.textContent = fonts[i]; | |
ul.appendChild(li); | |
} | |
document.body.appendChild(ul); | |
clearInterval(t); | |
} catch(e) { | |
console.error('fail'); | |
} | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment