Draw byte array in Java
Description
The following code shows how to draw byte array.
Example
import java.awt.Graphics;
//from ww w . j a v a 2s . c om
import javax.swing.JComponent;
import javax.swing.JFrame;
class MyCanvas extends JComponent {
public void paint(Graphics g) {
byte[] b = { 0x65, (byte) 'B', 0x66 };
g.drawBytes(b, 0, b.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.