Draw Char array in Java
Description
The following code shows how to draw Char array.
Example
import java.awt.Graphics;
// www. j a va2 s .co m
import javax.swing.JComponent;
import javax.swing.JFrame;
class MyCanvas extends JComponent {
public void paint(Graphics g) {
char[] c = { 'j', 'a', 'v', 'a', '2', 's', '.', 'c', 'o', 'm', ' ', '1', '2', '3' };
g.drawChars(c, 0, c.length, 10, 30);
}
}
public class Main {
public static void main(String[] a) {
JFrame window = new JFrame();
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.setBounds(30, 30, 450, 450);
window.getContentPane().add(new MyCanvas());
window.setVisible(true);
}
}
The code above generates the following result.