テキストファイルを読み込んでベクトルに内容を追加し、これらの点をグラフのウインドウを使って画面に出力するJavaコードがあります。Javaは新しいものではなく、古い入力ファイルを読み込んでいます
私は3つのpointdata.txtファイル、pointdata1.txt、pointdata2.txt、およびpointdata3.txtを持っています。
私が抱えている問題は、ドライバの入力ファイルをpointdata1またはpointdata2に変更しても、それでもpointdata3のために実行されるということです。私はコード内にpointdata3がどこにも存在しないことを保証しました。それは二度しか現れないが、私はそれが同じであることを確かめた。 私はファイル自体をチェックしましたが、それらは異なっています。チェックされ、チェックされ、パス名がチェックされ、彼らは異なる!
コード全体でSystem.out.println()
をすべてコメントしても、それでもすべてが印刷されます。
コードがもはやテキストファイルを参照していない、または実行中であっても、以前はビューポートに追加されていたものを印刷し続けます。ここで
は私の運転手からのコードです:
import java.util.*;
public class PointDriver {
private PointField pointfield;
// testing
public void doAllTests() throws Exception{
this.test1();
this.test2();
}
// Display all points in the file
public void test1() throws Exception{
SimpleIO sIO = new SimpleIO();
System.out.println("Contents of Point File: ");
sIO.displayFile("pointdata1.txt");
//sIO.displayFile("pointdata2.txt");
//sIO.displayFile("pointdata3.txt");
System.out.println();
}
// Load points from a file into a vector and echo them back to the screen
// This uses the StringTokenizer to split the lines into two Strings, then
// uses the Point class to assign the two Strings to x,y double variables
// which form Points. Within the same loop, the points are also displayed
// in a window using the Graph Window class. Maximum x and y values are used
// to determine the dimensions of the GraphWindow, adding 10 units to each
// value to provide a border.
public void test2() throws Exception{
System.out.println("Contents of Point File: ");
System.out.println();
System.out.println("Points are Displayed in a Graph Window");
System.out.println();
Vector lines;
lines = pointfield.getlines("pointdata1.txt");
//lines = pointfield.getlines("pointdata2.txt");
//lines = pointfield.getlines("pointdata3.txt");
Iterator IT;
IT = lines.iterator();
Vector v;
v = new Vector();
double maxX, maxY;
PointField pointfield;
pointfield = new PointField();
GraphWindow gw;
gw = new GraphWindow();
while (IT.hasNext()) {
StringTokenizer st;
String ID = (String)IT.next();
st = new StringTokenizer(ID);
double x = Double.parseDouble(st.nextToken());
double y = Double.parseDouble(st.nextToken());
Point p;
p = new Point(x,y);
v.addElement(p);
int i = v.size();
System.out.println("Point ID: " +i+ " X: "+x+", Y: "+y);
gw.plotPoint(x, y);
}
this.pointfield = new PointField(v);
maxX = this.pointfield.findMaxXPoint();
maxY = this.pointfield.findMaxYPoint();
int width = (int)maxX + 10;
int height = (int)maxY + 10;
gw.setMap(width, height);
}
// Short main method to kick of all tests sequence in doAllTests method
public static void main(String[] args) throws Exception {
PointFieldDriver pfd;
pfd = new PointFieldDriver();
pfd.doAllTests();
}
}
正確に知るには、コードを確認する必要があります。私はあなたがそれでデバッガを実行することをお勧めします。また、あなたのプロジェクトはコンパイルされていますか? JARファイルをビルドして、それを実行すると何が起こるかを見てみることができます。 –
私のドライバからコードを追加すると便利ですか? – alice
あなたが私たちに与えることができるものはすべて参考になります。 –