你的points是什么?没有定义啊。应该是
Point[] points = new Point[10];
吧。
Point[] points = new Point[10];
吧。
解决方案 »
- 请问谁能给我个好点的table border的样式和输入框的样式么?
- 关与抽象类的问题
- 急,在线等待。100 分求java日期时间格式问题
- 求教:我通过URLConnection来获取网页信息,怎么自动识别页面的编码格式?
- 来看看我写的java计算器代码 出什么问题了
- 求助java中取得当前计算机日期的方法!!
- 一个数据库操作等待比较长的时间,想弄个等待窗口,不知怎么用多线程实现,麻烦给个例子
- 主线程创建的子线程怎么样引用主线程,调用主线程的方法?
- javaBean中的property="*"代表什么意思?
- Java中,Inner class可不可以使用final修饰符?
- 请问J++中,需要输入命令行吗?
- 用JAVA写UVA的题目!帮我看看错在那儿?提交Wrong Answer
我不懂在point类中的字段,在DrawLine中不可以直接调用马?
刚学不久,不懂呢
你先试试这个程序!可以运行拉!
import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.util.Random;
import java.awt.event.*;
import java.lang.Double.*;
/*
<applet code=DrawLine width=600 height=500>
</applet>
*/
class Line
{
public static double getLineY(int n, double inputT, double inputTc){
double t0 = (n - 5.0 / 4.0) * inputTc;
double t1 = (n - 3.0 / 4.0) * inputTc;
double t2 = (n - 1.0 / 4.0) * inputTc;
if((inputT >= t0) && (inputT < t1)){
uc = 1.0 - (inputT - t0) * 4.0 / inputTc;
}
if((inputT >= t1) && (inputT < t2)){
uc = -1.0 + (inputT - t1) * 4.0 / inputTc;
}
return uc;
}
static double uc;
} class Point{
public Point(double xVal, double yVal){
x = xVal;
y = yVal;
}
public double getX(){
return x;
}
public double getY(){
return y;
}
public void setX(double inputX){
x = inputX;
}
public void setY(double inputY){
y = inputY;
}
public String toString(){
return Double.toString(x);
}
public double x;
public double y;
}
public class DrawLine extends JFrame{
final int origX = 50;
final int origY = 350;
Point[] points = new Point[10];
InputStreamReader reader;
BufferedReader input ;
String s; double tc,b,tr,a; public DrawLine(){
JFrame jf=new JFrame();
jf.setTitle("SPWM(自然采样法)");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.setSize(500, 400);
jf.setVisible(true);
jf.show();
reader = new InputStreamReader(System.in);
input = new BufferedReader(reader);
}
public static void main(String[] args)throws IOException{
DrawLine t=new DrawLine(); t.initGUI();
t.paintt();
//Point[] points = new Point[10];
} public void initGUI() throws IOException{
System.out.println("请输入三角波的周期(tc):");
s = input.readLine();
tc = new Double(s).doubleValue();
System.out.println("请输入三角波的峰值(b):");
s = input.readLine();
b = new Double(s).doubleValue();
System.out.println("请输入正炫波的周期(tr):");
s = input.readLine();
tr = new Double(s).doubleValue();
System.out.println("请输入正炫波的调制度(a):");
s = input.readLine();
a = new Double(s).doubleValue();
for(int i = 0 ; i <10 ; i++){
points[i] = new Point(0.0, 0.0);
}
int j = 0;
for(int n = 1; n <= 5; n ++ ){
for(double t=(n-5.0/4.0)*tc; t < (n-1.0/4.0)*tc; t += 0.0001){
double sinVolume = a * Math.sin((2.0 * t * Math.PI)/tr);
double lineVolume = Line.getLineY(n, t, tc);
double sub = sinVolume - lineVolume;
if(Math.abs(sub)<=0.001){
points[j].setX(t);
j++;
}
}
} for(int k = 0 ; k < points.length; k += 2){
System.out.println("The time is " + points[k] + "-------" + points[k+1]);
} } public void paintt(){
//super.paint(g);
Graphics g =this.getGraphics(); g.drawLine(this.origX - 25, this.origY, this.getWidth() - 100, this.origY);
g.drawLine(this.origX, 50, this.origX, this.getHeight() - 25); for(int i = 1; i < 10; i++){
g.drawLine(origX + i * 30, this.origY - 10, origX + i * 30, this.origY);
g.drawString(Double.toString(i/100.0), origX + i*30, this.origY + 20);
g.drawLine(this.origX, this.origY - i * 30, this.origX + 10, this.origY - i*30);
g.drawString(Integer.toString(i * 30), this.origX - 20, this.origY - i * 30);
}
//Double b; for(int j = 0; j < 5;j++){
g.drawLine(origX + (new Double(points[2*j].getX())).intValue(), 230, origX +(new Double(points[2*j+1].getX())).intValue(), 230);
}
}
}