Check out the API for the Graphics class. You will find methods to draw lines and text (hint)
For your requirement, essentially what you need to do is
1) Subclass a container like JPanel
2) Override the paintComponent
3) Inside this overridden method, use the Graphics instance to do all the drawing and painting you require. Just don't forget to invoke super.paintComponent() in the first line of your overridden method.
If you run into any problem, show us your code and we can help point you in the right direction
Apple Khoa wrote: I do not want Java Applets.
Huh? What had applets got to do with your requirement?
Maneesh Godbole wrote:Check out the API for the Graphics class. You will find methods to draw lines and text (hint)
1) Subclass a container like JPanel
Hi Maneesh Godbole,
Thanks for your prompt reply.
I am aware that Java Graphics class has a drawLine function which allows users to draw a straight line. But from what I understand, it doesn't show the axis values even if I draw the x-axis as a straight line.
You mentioned about JPanel. Can that be implemented into servlets? My ultimate objective is to insert the code into my servlet which will then generate the inequality number line as a pdf file for output.
I learnt from the Internet about JGraphT. May I ask if that is applicable for my case (since JGraphT produces postscript, can that be implemented into servlets?)
Apple Khoa wrote:You mentioned about JPanel. Can that be implemented into servlets? My ultimate objective is to insert the code into my servlet which will then generate the inequality number line as a pdf file for output.
If you need to do this in an application without a GUI, then you'll not be using JPanel. If you're going to do the drawing yourself (not using some chart or graph library), then you can create a BufferedImage and call getGraphics on it, which will give you a Graphics2D object that you can use to draw on the image (just like you would draw on a JPanel). You can use the ImageIO class to save the image to a png, jpeg or other graphics format file.
May I know what do you mean by "do the drawing yourself"?
Actually, I intend to write the mathematical logic for the topic Inequalities, and the inequality should be shown on the number line as the final answer. Hence, the 'chart' should change according to the inequality. All these will be included in servlets, which will output pdf file.
In my case, is BufferedImage and getGraphics still applicable?
Maneesh and you were talking about libraries, such as JFreeChart. Those libraries are specifically for creating charts and graphs. You just pass the data to the library, tell it what kind of chart to draw, and it will produce an image for you with the chart.
You could try to use such a library, or not. If you don't, then you'll have to draw all the lines, numbers etc. yourself. If you are doing it in an application that doesn't have a GUI (such as a servlet), then you could create a BufferedImage, which is just an image in the computer's memory. You can draw lines, numbers, etc. on a BufferedImage in the same way as you would draw on a JPanel (using a Graphics2D object). When you're done drawing, you can save the BufferedImage in a file using the ImageIO class.
Thank you so much for your clear explanation. This is my first time attempting graphs/charts with Java, so pardon me if I ask a lot of questions.
From what I understand in your explanation, the libraries and BufferedImage (with getGraphics) draw graphics that are 'permanent' in the sense that the graphics cannot change according to the Inequalities which will vary (e.g, sometimes X>2, sometimes x<25 etc). Kindly correct me if I am wrong.
My program will set questions and solve the inequalities, and then display it on the number line.
E.g
x - 3 > 5
x > 8
(display x >8 on number line)
Post by:autobot
I just had the craziest dream. This tiny ad was in it.
a bit of art, as a gift, that will fit in a stocking