I tried to input some Numbers in Java from "input1.txt" File, save them in 3 Arrays and make a Vertex for a Graph with those Numbers, but it doesn't work . It returns error "Compute launch button tooltip" . Can you help me,please ?
class GraphPanel extends JFrame {
private static final long serialVersionUID = 1L;
UGraph x;
Constructor for Graphic
public GraphPanel(UGraph x) {
setTitle("Graph");
setSize(1500,1500);
setResizable(true);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.x=x;
}
Building Graph
public void paint(Graphics graphic) {
int knots=x.KnotenList.size() , kants=x.KantenList.size();
graphic.setColor(Color.RED);
for(int i=0;i<knots;++i) {//malen der Knoten
graphic.fillOval(x.KnotenList.get(i).x, x.KnotenList.get(i).y, 8, 8);
}
graphic.setColor(Color.BLACK);
int fromID,toID;
GKnote from,to;
for(int i=0;i<kants;++i) {//malen der Kanten
fromID= x.KantenList.get(i).fromID;
toID = x.KantenList.get(i).toID;
from=x.getKnote(fromID);
to=x.getKnote(toID);
graphic.drawLine(from.x+4, from.y+4, to.x+4, to.y+4);
}
}
Main Function
public static void main(String[] args) throws IOException {
FileReader in = null;
//UGraph g=new UGraph();
int [] idlist= new int [100];
int [] xlist= new int [100];
int [] ylist= new int [100];
int insgesamtpunkte=0;
File Input and the Place where Error occurs
try {
in = new FileReader("input1.txt");
int tmp=0,satind=1,spaceanzahl=0,gfid=0,gfx=0,gfy=0;
char c;
while ((c = (char) in.read()) != ';') {
if(c>='0' && c<='9') {//constructs a Number
tmp+=c-'0';
tmp*=10;
}
else if(c==' ') {
tmp/=10;
switch(satind++) {
case 1: gfid=tmp;
case 2: gfx=tmp;
case 3: gfy=tmp;
}
tmp=0;
if(++spaceanzahl==3) {
//System.out.println(gfid+"|"+gfx+"|"+gfy);
//Saving Ints in Arrays
idlist[insgesamtpunkte]=gfid;
xlist[insgesamtpunkte]=gfx;
ylist[insgesamtpunkte++]=gfy;
spaceanzahl=0;
satind=1;
tmp=0;
while ((c = (char) in.read()) == ' ') if(c==';') break;
if(c>='0' && c<='9') {//constructs a Number
tmp+=c-'0';
tmp*=10;
}
}
}
}
}
finally {
if (in != null) {
in.close();
}
}
Adding Vertex from Arrays
for(int i=0;i<insgesamtpunkte;++i)
g.addKnote(idlist[i],xlist[i],ylist[i]);
Adding Vertexes and Edges manually
g.addKnote(32,223,341);
g.addKante(2, 14, 12);
g.addKante(3, 14, 32);
Making Graphic
new GraphPanel(g);
}
}
File Content is
14 321 544 12 443 234 ;
You can nicely read the input from file using java 8+ as bellow:
int numbers[] = Files.lines(Paths.get("input1.txt"))
.map(line -> line.split(" "))
.flatMap(Arrays::stream)
.mapToInt(Integer::parseInt)
.toArray();
Now numbers
array contains all the integers from the input file. You can use it to create 3 arrays required by you.