cześć, mam do napisania projekt i mam problem.
temat: "wizualizacja danych demograficznych - zmienna w czasie"
mam użyć wykresow jfreechart i gui.
gui mam zrobione, wykres również mam. jak kliknę przycisk start program ma wczytywać dane z pliku txt na wykres(np. dane z roku 2000) i po sekundzie ma automatycznie wczytać dane z 2001 itd, żeby powstała taka animacja. nie umiem wczytać danych z pliku i animacji zrobić :/
mógłby ktoś przeanalizować kod i poprawić ewentualne błędy?
public class wykres extends JFrame implements ActionListener {
JPanel panelGuzikow;
JButton start, stop;
ArrayList<dane> lista = new ArrayList<dane>();
static double a;
static double b;
static double c;
static double d;
static double f;
static double g;
static double h;
static double i;
static double j;
static double k;
static double l;
static double m;
static double n;
static double o;
static double p;
static double r;
public wykres(String title) throws IOException {
super(title);
setSize(840,580);
setLayout(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
load(lista);
panelGuzikow =new JPanel();
panelGuzikow.setBounds(10,500,800,100);
add(panelGuzikow);
start = new JButton("Rozpocznij animację");
start.setBounds(100,500,150,30);
panelGuzikow.add(start);
stop = new JButton("Zatrzymaj animację");
start.setBounds(300,500,150,30);
panelGuzikow.add(stop);
KeyedValues2DDataset dataset = createDatasetLudnosc();
JFreeChart chart = ChartFactory.createStackedBarChart(
"Liczba ludności Polski", "Grupa wiekowa", "Ilość",
dataset, PlotOrientation.HORIZONTAL,
true, true, false);
CategoryPlot plot = chart.getCategoryPlot();
ChartPanel chartPanel = new ChartPanel(chart);
chartPanel.setBounds(10,10,800,470);
add(chartPanel);
}
static private KeyedValues2DDataset createDatasetLudnosc() {
DefaultKeyedValues2DDataset data = new DefaultKeyedValues2DDataset();
data.addValue( -a, "Mężczyźni", "70+");
data.addValue(-b, "Mężczyźni", "60-69");
data.addValue(-c, "Mężczyźni", "50-59");
data.addValue(-d, "Mężczyźni", "40-49");
data.addValue(-f, "Mężczyźni", "30-39");
data.addValue(-g, "Mężczyźni", "20-29");
data.addValue(-h, "Mężczyźni", "10-19");
data.addValue(-i, "Mężczyźni", "0-9");
data.addValue(j, "Kobiety", "70+");
data.addValue(k, "Kobiety", "60-69");
data.addValue(l, "Kobiety", "50-59");
data.addValue(m, "Kobiety", "40-49");
data.addValue(n, "Kobiety", "30-39");
data.addValue(o, "Kobiety", "20-29");
data.addValue(p, "Kobiety", "10-19");
data.addValue(r, "Kobiety", "0-9");
return data;
}
private static void load(ArrayList <dane> lista) throws IOException {
File plik = new File("dane.txt");
FileReader freader =null ;
try {
freader = new FileReader(plik);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedReader breader = new BufferedReader(freader);
lista.clear();
String line;
while ((line = breader.readLine()) != null) {
if (line.equals("rok")) {
String a = breader.readLine();
String b = breader.readLine();
String c = breader.readLine();
String d = breader.readLine();
String f = breader.readLine();
String g = breader.readLine();
String h = breader.readLine();
String i = breader.readLine();
String j = breader.readLine();
String k = breader.readLine();
String l = breader.readLine();
String m = breader.readLine();
String n = breader.readLine();
String o = breader.readLine();
String p = breader.readLine();
String r = breader.readLine();
}
}
breader.close();
}
@Override
public void actionPerformed(ActionEvent e) {
Object zrodlo = e.getSource();
if(zrodlo == lista){
for (int q = 0; q < lista.size(); q++){
a = Double.parseDouble(lista.get(q).geta());
b = Double.parseDouble(lista.get(q).getb());
c = Double.parseDouble(lista.get(q).getc());
d = Double.parseDouble(lista.get(q).getd());
f = Double.parseDouble(lista.get(q).getf());
g = Double.parseDouble(lista.get(q).getg());
h = Double.parseDouble(lista.get(q).geth());
i = Double.parseDouble(lista.get(q).geti());
j = Double.parseDouble(lista.get(q).getj());
k = Double.parseDouble(lista.get(q).getk());
l = Double.parseDouble(lista.get(q).getl());
m = Double.parseDouble(lista.get(q).getm());
}
}
}
public class dane {
String a,b,c,d,f,g,h,i,j,k,l,m,n,o,p,r;
private String rok;
public dane(String a,String b,String c,String d,String f,String g,String h,String i,String j,String k,String l,String m,String n,String o,String p,String r){
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.f = f;
this.g = g;
this.h = h;
this.i = i;
this.j = j;
this.k = k;
this.l = l;
this.m = m;
this.n = n;
this.o = o;
this.p = p;
this.r = r;
}
public void setrok(String rok) {
this.rok = rok;
}
public String getrok() {
return rok;
}
public void seta(String a) {
this.a = a;
}
public String geta() {
return a;
}
public void setb(String b) {
this.b = b;
}
public String getb() {
return b;
}
public void setc(String c) {
this.c = c;
}
public String getc() {
return c;
}
public void setd(String d) {
this.d = d;
}
public String getd() {
return d;
}
public void setf(String f) {
this.f = f;
}
public String getf() {
return f;
}
public void setg(String g) {
this.g = g;
}
public String getg() {
return g;
}
public void seth(String h) {
this.h = h;
}
public String geth() {
return h;
}
public void setj(String j) {
this.j = j;
}
public String getj() {
return j;
}
public void setk(String k) {
this.k = k;
}
public String getk() {
return k;
}
public void seti(String i) {
this.i = i;
}
public String geti() {
return i;
}
public void setl(String l) {
this.l = l;
}
public String getl() {
return l;
}
public void setm(String m) {
this.m = m;
}
public String getm() {
return m;
}
public void setn(String n) {
this.n = n;
}
public String getn() {
return n;
}
public void seto(String o) {
this.o = o;
}
public String geto() {
return o;
}
public void setp(String p) {
this.p = p;
}
public String getp() {
return p;
}
public void setr(String r) {
this.r = r;
}
public String getr() {
return r;
}
}
public class runner {
public static void main(String[] args) throws IOException {
wykres mojWykres = new wykres ("Wizualizacja danych demograficznych");
RefineryUtilities.centerFrameOnScreen(mojWykres);
mojWykres.setVisible(true);
}
}
będę bardzo wdzięczny.