ギリシャ文字と英語のアプレット
// guie3.java ギリシャ文字(小文字/大文字)のボタンを押すと、そのまま表示する(配列)、コンパイル時の警告をなくす import java.awt.*; import java.awt.event.*; import java.applet.Applet; public class guie3 extends Applet implements ActionListener, ItemListener { final short n = 24; String X = "", Y = ""; // Xを表示用の文字列とする Font f; // 見やすいフォントにする Font f2; int fn; int flen; int i; Choice choicebtn; Panel pspace; // できるだけ表示ボタンをグループ化する String w0[] = {"α", "β", "γ", "δ", "ε", "ζ", "η", "θ", "ι", "κ", "λ", "μ", "ν", "ξ", "ο", "π", "ρ", "σ", "τ", "υ", "φ", "χ", "ψ", "ω"}; String w1[] = {"alpha", "beta", "gamma", "delta", "epsilon", "zeta", "eta", "theta", "iota", "kappa", "lambda", "mu", "nu", "xi", "omicron", "pi", "rho", "sigma", "tau", "upsilon", "phi", "chi", "psi", "omega"}; String W0[] = {"Α", "Β", "Γ", "Δ", "Ε", "Ζ", "Η", "Θ", "Ι", "Κ", "Λ", "Μ", "Ν", "Ξ", "Ο", "Π", "Ρ", "Σ", "Τ", "Υ", "Φ", "Χ", "Ψ", "Ω"}; String W1[] = {"ALPHA", "BETA", "GAMMA", "DELTA", "EPSILON", "ZETA", "ETA", "THETA", "IOTA", "KAPPA", "LAMBDA", "MU", "NU", "XI", "OMICRON", "PI", "RHO", "SIGMA", "TAU", "UPSILON", "PHI", "CHI", "PSI", "OMEGA"}; Button clear; // 表示文字を全消去 Button wb[]; Button Wb[]; Button space, comma, period; public void init() { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String allFonts[] = ge.getAvailableFontFamilyNames(); flen = allFonts.length; choicebtn = new Choice(); for(i=0; iactionPerformedに変更 */ public void actionPerformed(ActionEvent event) { if (event.getSource() == clear ) { System.out.println("You pushed clear"); X = "";Y = "";repaint(); } else if (event.getSource() == space ) { System.out.println("You pushed space"); X = X + " "; repaint(); } else if (event.getSource() == comma ) { System.out.println("You pushed comma"); X = X + ","; repaint(); } else if (event.getSource() == period) { System.out.println("You pushed period"); X = X + "."; repaint(); } else for( int i = 0; i < n; i++ ) { if (event.getSource() == wb[i]) { X = X + w0[i]; Y = ""; repaint(); Y = w1[i]; repaint(); } } for( int i = 0; i < n; i++ ) { if (event.getSource() == Wb[i]) { X = X + W0[i]; Y = ""; repaint(); Y = W1[i]; repaint(); } } } public void itemStateChanged(ItemEvent ie) { GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); String allFonts[] = ge.getAvailableFontFamilyNames(); Choice c = (Choice)ie.getItemSelectable(); fn = c.getSelectedIndex(); f = new Font(allFonts[fn], Font.PLAIN, 50); f2 = new Font(allFonts[fn], Font.PLAIN, 20); repaint(); System.out.println(allFonts[fn]); } }
戻る