In: Computer Science
how can i label drawn circle with number inside the canvas drawn using java gui. Lets say if i draw circle and click on canvas it should show circle and 1. USE JAVA
If you have any problem with the code feel free to comment.
Program
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import javax.swing.JFrame;
public class Test extends JFrame {
public void paint(Graphics g) {
//setting circle
g.setColor(Color.YELLOW);
g.fillOval(100, 100, 100, 100);
//setting number
String num = "1";
g.setColor(Color.GREEN);
//setting font
g.setFont(new Font("Arial", Font.BOLD, 30));
g.drawString(num, 145, 160);
}
public static void main(String args[]) {
Test frame = new Test();
//setting JFrame
frame.setSize(300, 300);
frame.setTitle("Circle on canvas");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Output