So I have two files and I want to access a variable from my first file and use it in my second file which paint a pie chart.
import java.util.*;
import java.lang.*;
import java.io.*;
import javax.swing.*;
import java.awt.*;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
File file = new File(args[0]);
Scanner input = new Scanner(file);
//int i = 0;
ArrayList<Integer> slices = new ArrayList<Integer>();
ArrayList<String> names = new ArrayList<String>();
while (input.hasNextLine()) {
names.add(input.next());
slices.add(input.nextInt());
}
JFrame f = new JFrame("Pie chart");
f.setSize(600, 350);
f.setDefaultCloseOperation(
JFrame.EXIT_ON_CLOSE);
f.add(new PieChart());
f.setVisible(true);
}
}
here is my second file
import java.awt.*;
import javax.swing.*;
public class PieChart
extends JComponent {
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g.create();
Graphics2D g3 = (Graphics2D) g.create();
g3.setColor(Color.BLACK);
g2.setColor(Color.BLUE);
for (int i = 0; i < 4; i = i + 1) {
g2.fillRect(230, 20 * i + 50 , 20, 20);
g3.drawString(names.get(i), 255, 20 * i + 65);
g3.drawString("37.0%", 385, 20 * i + 65);
}
g2.fillArc(50, 50, 150, 150, 0, 360);
}
}
here's the error i'm getting...
I am trying to read from a text file into two separate arrays. I want one list to hold the names and then one to hold the values. I then want to be able to then access the values from the array from my second file.