No nic, já na to seru. Pokud by někdo byl tak boží a našel v tom mou chybu, nabízím sestru a půl království. Nejsem si úplně jistej, co je přesně to "e" u tableChanged, možná v tom tkví chyba.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;
import logika.EvidenceZamestnancu;
import logika.Zamestnanec;
/**
*
* @author Ondra
*/
public class TableZamestnanec extends AbstractTableModel implements TableModelListener {
private EvidenceZamestnancu evidence;
String[] zahlaviSloupcu = {"ID", "Jmeno", "Prijmeni", "Práce", "Rodné číslo", "Telefon", "Adresa"};
public TableZamestnanec(EvidenceZamestnancu evidence) {
this.evidence = evidence;
}
@Override
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
@Override
public String getColumnName(int col) {
return zahlaviSloupcu[col];
}
public int getRowCount() {
return evidence.pocet();
}
public int getColumnCount() {
return 7;
}
public Object getValueAt(int row, int col) {
// naplneni seznamu
Zamestnanec polozka = (Zamestnanec) evidence.getPolozka(row);
switch (col) {
case 0:
return (polozka.getID());
case 1:
return (polozka.getJmeno());
case 2:
return (polozka.getPrijmeni());
case 3:
return (polozka.getPrace());
case 4:
return (polozka.getRodneCislo());
case 5:
return (polozka.getTelefon());
case 6:
return (polozka.getAdresa());
default:
return null;
}
}
public void tableChanged(TableModelEvent e) {
evidence.nactiSeznam();
fireTableChanged(e);
}
}
----------------------------------------------------------------
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package gui;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.event.TableModelListener;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import logika.EvidenceZamestnancu;
import logika.Zamestnanec;
/**
*
* @author Ondra
*/
public class OknoZamestnanec {
private JFrame OknoZamestnanecFrame;
private JPanel westPanel;
private JPanel centerPanel;
private JButton newButton;
private JButton editButton;
private JButton deleteButton;
private JButton backButton;
private JPanel mistoPanel;
private JTextField zobrazTextField;
private Menu menu;
private NewZamestnanec newZamestnanec;
private TableModel TableZamestnanec;
private JTable evidenceTable;
private int vybranyRadek;
public OknoZamestnanec(TableModel model) {
this.TableZamestnanec = model;
init();
setVisible(true);
}
private class VyberRadku implements ListSelectionListener {
public void valueChanged(ListSelectionEvent e) {
ListSelectionModel lsm = (ListSelectionModel) e.getSource();
if (!lsm.isSelectionEmpty()) {
vybranyRadek = lsm.getMinSelectionIndex();
}
zobrazTextField.setText((String) TableZamestnanec.getValueAt(vybranyRadek, 1));
}
}
/**
* Metoda inicializuje a propojuje jednotlivé komponenty GUI
*/
private void init() {
OknoZamestnanecFrame = new JFrame();
menu = new Menu();
OknoZamestnanecFrame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
OknoZamestnanecFrame.setTitle("Evidence Zaměstnanců");
OknoZamestnanecFrame.setSize(700, 400);
OknoZamestnanecFrame.setLocation(200, 200);
OknoZamestnanecFrame.setJMenuBar(menu);
OknoZamestnanecFrame.setResizable(false);
westPanel = new JPanel();
westPanel.setLayout(new FlowLayout());
westPanel.setPreferredSize(new Dimension(140, 400));
newButton = new JButton("Nový");
newButton.addActionListener(new NewZamestnanecActionListener());
editButton = new JButton("Edit");
deleteButton = new JButton("Smaž");
deleteButton.addActionListener(new DeleteZamestnanecActionListener());
backButton = new JButton("Zpět");
backButton.addActionListener(new BackActionListener());
newButton.setPreferredSize(new Dimension(120, 25));
editButton.setPreferredSize(new Dimension(120, 25));
deleteButton.setPreferredSize(new Dimension(120, 25));
backButton.setPreferredSize(new Dimension(120, 25));
mistoPanel = new JPanel();
mistoPanel.setPreferredSize(new Dimension(140, 210));
westPanel.add(newButton);
westPanel.add(editButton);
westPanel.add(deleteButton);
westPanel.add(mistoPanel);
westPanel.add(backButton);
evidenceTable = new JTable(TableZamestnanec);
evidenceTable.setPreferredScrollableViewportSize(new Dimension(540, 400));
evidenceTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
ListSelectionModel modelVyberu = evidenceTable.getSelectionModel();
modelVyberu.addListSelectionListener(new VyberRadku());
JScrollPane scpRoluj = new JScrollPane(evidenceTable);
OknoZamestnanecFrame.add(scpRoluj, BorderLayout.CENTER);
zobrazTextField = new JTextField(30);
// OknoZamestnanecFrame.add(zobrazTextField, BorderLayout.SOUTH);
OknoZamestnanecFrame.add(westPanel, BorderLayout.WEST);
}
class BackActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
setVisible(false);
}
}
class DeleteZamestnanecActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
EvidenceZamestnancu temp = new EvidenceZamestnancu();
TableZamestnanec.addTableModelListener(evidenceTable);
temp.nactiSeznam();
temp.deletePolozka(temp.getPolozka(vybranyRadek));
temp.ulozSeznam();
}
}
class NewZamestnanecActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
NewZamestnanec newZamestnanec = new NewZamestnanec();
newZamestnanec.setVisible(true);
}
}
/**
* Metoda, která zviditelňuje GUI
* @param viditelnost GUI
*/
public void setVisible(boolean viditelnost) {
OknoZamestnanecFrame.setVisible(viditelnost);
}
}
|