I am going to work on a TDM-DeMux project, in which I have to plot spectrum from the generated signals. Even before that, I was asked to to plot spectrum for sine and cosine waves, first. Are there any libraries(or articles/tutorials) in Java that can help me in plotting spectrum.
Currently, I am working with the latest versions of JDK and Eclipse.
Thanks in advance!
(Updated)
Anyways, I have decided to create a graph first by myself. So I drew x&y axes, created a scale from an algorithm (given to me). The code is here:
public class Graph extends JPanel{
int[] data = { 30, 60, 75, 90 };
final int PAD = 200;
protected void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
int h = getHeight();
int w = getWidth();
System.out.println("h = " + h + "\tw = " + w);
g2.setColor(Color.GREEN);
g2.drawLine(300, 0, 300, h+300);
g2.drawLine(0, 300, w+300, 300);
double xScale = (w-2*PAD)/(data.length+1);
double maxValue = 100.0;
double yScale = (h-2*PAD)/maxValue;
System.out.println("xScale= " + xScale + "\tyScale = " + yScale);
int x0 = 300;
int y0 = h-300;
System.out.println("x0 = " + x0 + "\ty0 = " + y0);
g2.setPaint(Color.red);
int x = x0 + data[0];
int y = y0 + data[1];
System.out.println("x = " + x);
System.out.println("y = " + y);
g2.drawOval(x, y, 30, 30);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame f = new JFrame("JGraph");
f.setBackground(Color.BLACK);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(new Graph());
f.setSize(600, 600);
f.setLocation(100, 100);
f.setVisible(true);
}
});
}
}
The problem is although x & y co-ordinates are positive relative to the origin. The circle which I drew is not
in the first quadrant. Why is this happening? Also I want to change the background color of my graph into black.
Thanks once again!