- 论坛徽章:
- 0
|
java怎么做实时曲线?
先写了一部分:
import java.awt.Color;
import java.awt.Container;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window& references&Java&Code Generation&Code and Comments
*/
public class SineTest
{
public static void main(String args[])
{
SineFrame frame = new SineFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.show();
}
}
class SineFrame extends JFrame
{
public SineFrame()
{
setTitle("SineTest" ;
setSize(300,400);
p = new MyPanel();
Container t = getContentPane();
t.add(p);
}
private MyPanel p;
}
class MyPanel extends JPanel
{
public MyPanel()
{
setSize(1000,1000);
this.setBackground(Color.WHITE);
System.out.println(this.getWidth());
System.out.println(this.getHeight());
}
public void paint(Graphics g)
{
super.paint(g);
int x1 = 100, y1 = 0, x2 = 100, y2 = 0;
g.setColor(Color.RED);
int counter = 0;
while(counter <= 8192)
{
x1 = 100;
y1 = 0;
x2 = 100;
y2 = (int) (100*Math.sin(counter*Math.PI/8192));
g.drawLine(x1,y1,x2,y2);
y1 = y2;
counter++;
}
}
private Graphics gg;
}
完善了再都贴上来,一切讨论 |
|