fb55 fb55 - 5 months ago 58
Java Question

Paint a graph in Java using AWT

I'm searching a possibility to paint a graph in Java using AWT. My knowledge of Java is still basic, so this is mainly for getting used to AWT, even if it's already "old".


JFrame f = new JFrame();
JPanel p = new JPanel () {
     public void paint(Graphics g){
         Graphics2D g2d = printImg.createGraphics();
         g2d.drawString("123", 10, 10);        

Small example of how to paint in Swing components, the same in AWT. The paint method is the one where you can paint. To see what you can paint (Rectangles, circles, ...) you can look at the Java API of the "Graphics" or "Graphics2D" class.