0

i want to print the contents of an array of strings inside an applet as a list, but nothing appears when the applet starts, only something appears and it seems to be the strings inside the array but they need a space between each other, here's the applet:

import java.applet.Applet;
import java.awt.*;
import java.net.*;
import java.io.*;
import javax.swing.JFrame;

public class FontApplet extends Applet{
String[] fonts;

public void init() {

fonts =GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();


}
public void update(Graphics g){paint(g);}
public void paint(Graphics g) {

for(String str:fonts)
     g.drawString(str, 100, 125);
   }
  }
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Eslam Hamdy
  • 7,126
  • 27
  • 105
  • 165
  • 1) It is the 3rd millennium, time to use `JApplet` & Swing in general. 2) Given this is related to fonts, see [`FontCellRenderer`](http://stackoverflow.com/a/6965149/418556) - use that in a `JComboBox` or `JList` for a nicely rendered (and spaced!) list of available fonts. I suspect those algorithms for padding (e.g. in the accepted answer) will go off-screen before about 'd' in the font list. ;) – Andrew Thompson Dec 19 '12 at 03:50

2 Answers2

2

Try this:

int x = 100;
for(String str:fonts)
 g.drawString(str, x, 125);
 x += 20;
}
Jj Tuibeo
  • 773
  • 4
  • 18
1

You are drawing them all at location (100, 125).

sdasdadas
  • 23,917
  • 20
  • 63
  • 148