ahoj,
použil som
setIconImage(Toolkit.getDefaultToolkit().getImage("src/pic/icon.ico"));
alebo
setIconImage(new ImageIcon("src/pic/icon.ico").getImage());
pre zmenu ikony JFramu, ikona sa zmenila a všetko funguje ok ale po skompilovaní a spustení programu sa ikona zmení na pôvodnú (java kava). Neviete mi niekto poradiť v čom je chyba ?
Ďakujem
Příspěvky odeslané z IP adresy 147.232.192.–
to je jedno ze je tam 4ka lebo excel ma bunky od A po Z a od 0 po 65635 cca....a ten kod vie nacitat aj prazdne bunky...to ci v tych bunkach nieco je alebo nieje na tom nezalezi...
tu je subor z ktoreho nacitava hodnoty http://leteckaposta.cz/389194909
Caute, neviete mi povedat preco mi pise tuto chybu ?
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 4
at jxl.read.biff.SheetImpl.getCell(SheetImpl.java:356)
at triedy.IS.XLS.read(XLS.java:38)
at triedy.IS.XLS.main(XLS.java:67)
Viem ze to znamena ze vychadzam z pola ale nechapem ako....mozte mi niekto pomoct? Dakujem.
package triedy.IS;
import java.io.File;
import java.io.IOException;
import jxl.Cell;
import jxl.CellType;
import jxl.Sheet;
import jxl.Workbook;
import jxl.read.biff.BiffException;
public class XLS {
private String inputFile;
int[][] pole = new int[50][50];
// Funkcia pre nacitanie buniek
public void setInputFile(String inputFile) {
this.inputFile = inputFile;
}
public void read() throws IOException {
File inputWorkbook = new File(inputFile);
Workbook w;
int[] hodnota = new int[100];
try {
w = Workbook.getWorkbook(inputWorkbook);
// Nacitavanie prveho harku
Sheet sheet = w.getSheet(0);
// Cyklus pre nacitanie buniek 2 stlpcov a 5 riadkov
Cell[][] cell = new Cell[50][50];
CellType[][] type = new CellType[50][50];
for (int i=4; i<5; i++){
for(int j=19; j<20; j++){
cell[i][j] = sheet.getCell(i,j);
type[i][j] = cell[i][j].getType();
if (cell[i][j].getType() == CellType.LABEL) {
System.out.println("pole "+i+j+" "
+ cell[i][j].getContents());
}
if (cell[i][j].getType() == CellType.NUMBER) {
hodnota[j] = Integer.parseInt(cell[i][j].getContents());
pole[i][j] = hodnota[j];
}
}
}
} catch (BiffException e) {
e.printStackTrace();
}
}
// Funkcia pre vratenie nacitanych hodnot
public int[][] getRead(){
return pole;
}
public static void main(String[] args) throws IOException {
XLS test = new XLS();
test.setInputFile("c:/temp/lars.xls");
test.read();
for (int i=4; i<5; i++){
for(int j=19; j<20; j++){
System.out.println("toto je koncova hodnota navratova " + test.getRead()[i][j]);
}
}
}
}
ahoj vedel by mi niekto pomoct ? robim program pre zobrazovanie grafu z tabulky pomocou JFreeChartu a nejak som sa zasekol. Zaciatok programu som zacal robit tak aby mi hned loadoval subor do tabulky a nasledne do grafu. Ale teraz to neviem dat na akciu tlacitka tak aby mi vedel nacitat stale novu tabulku a zobrazit ju. Vzdy mi ostane stara a novu nechce precitat.
Za akukolvek pomoc budem vdacny. Dakujem.
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.*;
import javax.swing.table.*;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYLineAndShapeRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
public class Main{
String[] vyberHD = {"-choose-"};
String hlavicka;
Vector<Vector<Object>> data;
Vector<Object> hldata;
int poc_riad;
JTable tabulka;
JComboBox volba1;
JComboBox volba2;
JButton add;
JLabel popis1;
JLabel popis2;
JLabel popis3;
JLabel x;
JLabel y;
JButton load;
JButton save;
JButton make;
JTextField zacInt;
JTextField konInt;
int zacIntNUM = 1000;
int konIntNUM = 1100;
JTextArea vyber;
JFrame ram;
JScrollPane scroller;
JScrollPane scroller2;
JFreeChart xygraf;
int pocetVyberov;
JPanel panel1;
JPanel panel2;
JTabbedPane taby;
DefaultTableModel dtm;
Vector getData() throws Exception{
Vector<Vector<Object>>Vdata = new Vector<Vector<Object>>();
JFileChooser chooser = new JFileChooser();
int retval = chooser.showOpenDialog(null);
if (retval == JFileChooser.APPROVE_OPTION){
File Sub = chooser.getSelectedFile();
BufferedReader vstup = new BufferedReader(new FileReader(Sub));
String riadok;
poc_riad=0;
hlavicka="#; "+vstup.readLine();
while ((riadok = vstup.readLine()) != null){
poc_riad=poc_riad+1;
Vector<Object> vriadok = new Vector<Object>(Arrays.asList(riadok.split(";")));
vriadok.insertElementAt(poc_riad,0);
Vdata.add(vriadok);
}
//System.out.println(poc_riad);
vstup.close();}
return Vdata;
}
public Object GetStlpec(JTable table_name, int row_index, int col_index){
return table_name.getValueAt(row_index, col_index);
}
public XYDataset createData(){
XYSeriesCollection dataset = new XYSeriesCollection();
for (int j=2;j<=10;j++){
XYSeries seria = new XYSeries(tabulka.getColumnName(j));
for (int i=zacIntNUM-1;i<=konIntNUM;i++){
Object obj1 = GetStlpec(tabulka,i,j);
String hodnotaSTR = obj1.toString();
double hodnotaNUM = Double.parseDouble(hodnotaSTR);
seria.add(i,hodnotaNUM);
}
dataset.addSeries(seria);
}
return dataset;
}
public void paintChart(){
createData();
XYDataset DataForChart = createData();
xygraf = ChartFactory.createXYLineChart(
null,//nadpis
"t/poradie vzoriek",//popis osy X
"hodnoty",//popis osy Y
DataForChart,//data pre graf
PlotOrientation.VERTICAL, //orientacia
true,//legenda
true,//tooltip
false);//URLs
XYPlot plot = (XYPlot) xygraf.getPlot();
XYLineAndShapeRenderer render = (XYLineAndShapeRenderer) plot.getRenderer();
render.setShapesVisible(true);
}
public void paintTable() throws Exception{
//vytvorenie a nastavenie tabulky
data = getData();
hldata = new Vector<Object>(Arrays.asList(hlavicka.split("; ")));
tabulka = new JTable(data,hldata){
public boolean isCellEditable(int row,int column){
if(column == 0) return false;
return true;}};
//tabulka.revalidate();
tabulka.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
//tabulka.setCellSelectionEnabled(true);
TableColumnModel bunkamodel = tabulka.getColumnModel();
for (int i=0; i<2; i++){
TableColumn bunka =bunkamodel.getColumn(i);
if(i<2) bunka.setPreferredWidth(125);
if(i<1) bunka.setPreferredWidth(50);
if(i<2) bunka.setResizable(false);
}
scroller = new JScrollPane(tabulka);
scroller.setBounds(10,105,770,410);
panel1.add(scroller);
}
class AkciaOpen implements ActionListener{
public void actionPerformed(ActionEvent e){
try {
paintTable();
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class AkciaMakeChart implements ActionListener{
public void actionPerformed(ActionEvent e){
try {
paintChart();
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
AkciaOpen posluchacOpen = new AkciaOpen();
AkciaMakeChart posluchacMake = new AkciaMakeChart();
public void init() throws Exception{
//hldata = new Vector<Object>(Arrays.asList(vyberHD));
ram = new JFrame("Vizualizationer");
//vytvorenie horneho menu1
JMenu zalozka1 = new JMenu("File");
JMenuItem otvorit = new JMenuItem("Open");
otvorit.addActionListener(posluchacOpen);
JMenuItem ulozit = new JMenuItem("Save");
JMenuItem ulozitako = new JMenuItem("Save As");
JMenuItem exit = new JMenuItem("Exit");
zalozka1.add(otvorit);
zalozka1.add(new JSeparator());
zalozka1.add(ulozit);
zalozka1.add(ulozitako);
zalozka1.add(new JSeparator());
zalozka1.add(exit);
//vytvorenie horneho menu2
JMenu zalozka2 = new JMenu("Edit");
JMenuItem copy = new JMenuItem("Copy");
JMenuItem cut = new JMenuItem("Cut");
JMenuItem paste = new JMenuItem("Paste");
zalozka2.add(copy);
zalozka2.add(cut);
zalozka2.add(paste);
//vytvorenie horneho menu3
JMenu zalozka3 = new JMenu("Help");
JMenuItem help = new JMenuItem("Help");
JMenuItem about = new JMenuItem("About");
zalozka3.add(help);
zalozka3.add(new JSeparator());
zalozka3.add(about);
//pridanie hornych menu do jedneho baru
JMenuBar menu = new JMenuBar();
menu.add(zalozka1);
menu.add(zalozka2);
menu.add(zalozka3);
taby = new JTabbedPane();
//vytvorenie Tabov
panel1 = new JPanel();
panel1.setLayout(null);
panel2 = new JPanel();
panel2.setLayout(null);
//vytvorenie objektov na Tabe1
load = new JButton("Load File");
load.addActionListener(posluchacOpen);
save = new JButton("Save File");
make = new JButton("Make Chart");
make.addActionListener(posluchacMake);
load.setBounds(10,10,100,25);
panel1.add(load);
save.setBounds(10,40,100,25);
panel1.add(save);
make.setBounds(10,70,100,25);
panel1.add(make);
x = new JLabel("axis X:");
x.setBounds(150,70,50,25);
panel1.add(x);
y = new JLabel("axis Y:");
y.setBounds(150,40,50,25);
panel1.add(y);
popis1 = new JLabel("Chose Columns:");
//priprava hlavicky pre ComboBox
volba1 = new JComboBox(vyberHD);;
volba1.setBounds(200,70,100,25);
volba1.setEnabled(false);
panel1.add(volba1);
popis1.setBounds(200,10,100,25);
panel1.add(popis1);
add = new JButton("Add Value Y");
add.setBounds(305,40,110,25);
panel1.add(add);
//napicatie obsahu JTextArey do pola
vyber = new JTextArea("2\n8");
pocetVyberov = 7;/*vyber.getRows();*/
//String test[] = vyber.getText().split("\n");
//System.out.println(pocetVyberov);
scroller2 = new JScrollPane(vyber);
scroller2.setBounds(420,10,100,90);
panel1.add(scroller2);
paintTable();
volba2 = new JComboBox(hldata);
volba2.setBounds(200,40,100,25);
panel1.add(volba2);
paintChart();
popis2 = new JLabel("Interval:");
popis2.setBounds(600,10,100,25);
panel1.add(popis2);
zacInt = new JTextField("1");
zacInt.setBounds(600,40,100,25);
panel1.add(zacInt);
konInt = new JTextField(Integer.toString(poc_riad));
konInt.setBounds(600,70,100,25);
panel1.add(konInt);
//vytvorenie objektov na Tabe2
//paintChart();
ChartPanel Chartpanel = new ChartPanel(xygraf);
Chartpanel.setBounds(10,10,770,470);
panel2.add(Chartpanel);
//pridanie tabov do ramu
taby.addTab("Data",null,panel1,"Data for chart");
taby.addTab("Chart",null,panel2,"Generated chart");
//nastavenie ramu
ram.setJMenuBar(menu);
ram.add(taby);
//ulozenie okna do stredu obrazovky
Toolkit kit = ram.getToolkit();
Dimension d = kit.getScreenSize();
ram.setLocation(d.width/2-400, d.height/2-300);
ram.setSize(800,600);
ram.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
ram.setResizable(false);
ram.setVisible(true);
}
public static void main(String[] args) throws Exception{
Main start = new Main();
start.init();
}
}
ahoj chcel by som si kupit knihu Java 5 od autora Ivora Hortona je to starsia kniha ale velmi dobra. Pise sa v nej podrobne jednoducho a s dobrymi prikladmi ale nikde v knihkupectvach na Slovensku ale ani v Cesku ju neviem najst. Zrejme sa uz tato kniha nepredava a ani sa nebude uz tlacit. Nechcete nieto tuto knihu predat alebo ak ju niekto poznate odporucit nieco podobne. Bol by som vdacny aj za pdf verziu ak existuje nieco take. Dakujem