Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package ligakoszykowki;
- import java.sql.CallableStatement;
- import java.sql.ResultSet;
- import java.sql.SQLException;
- import java.sql.Statement;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- import javax.swing.table.DefaultTableModel;
- /**
- *
- * @author Mario
- */
- public class LigaKoszykowki extends javax.swing.JFrame {
- private ResultSet rs;
- private int status = 1;
- /**
- * Creates new form LigaKoszykowki
- */
- public LigaKoszykowki() {
- try {
- PolaczZBaza.polacz();
- initComponents();
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- } catch (ClassNotFoundException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- jPanel1 = new javax.swing.JPanel();
- jScrollPane1 = new javax.swing.JScrollPane();
- tabela = new javax.swing.JTable();
- jButton1 = new javax.swing.JButton();
- jButton2 = new javax.swing.JButton();
- jButton3 = new javax.swing.JButton();
- jButton4 = new javax.swing.JButton();
- jButton5 = new javax.swing.JButton();
- przyciskDodaj = new javax.swing.JButton();
- jButton7 = new javax.swing.JButton();
- przyciskEdytuj = new javax.swing.JButton();
- jButton9 = new javax.swing.JButton();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- tabela.setModel(new javax.swing.table.DefaultTableModel(
- new Object [][] {
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null},
- {null, null, null, null}
- },
- new String [] {
- "Title 1", "Title 2", "Title 3", "Title 4"
- }
- ));
- jScrollPane1.setViewportView(tabela);
- jButton1.setText("Drużyny");
- jButton1.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton1ActionPerformed(evt);
- }
- });
- jButton2.setText("Koszykarze");
- jButton2.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton2ActionPerformed(evt);
- }
- });
- jButton3.setText("Mecze");
- jButton3.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton3ActionPerformed(evt);
- }
- });
- jButton4.setText("Statystyki koszykarzy");
- jButton4.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton4ActionPerformed(evt);
- }
- });
- jButton5.setText("Statystyki meczu");
- jButton5.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton5ActionPerformed(evt);
- }
- });
- przyciskDodaj.setText("Dodaj");
- przyciskDodaj.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- przyciskDodajActionPerformed(evt);
- }
- });
- jButton7.setText("Usuń");
- jButton7.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton7ActionPerformed(evt);
- }
- });
- przyciskEdytuj.setText("Edytuj");
- przyciskEdytuj.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- przyciskEdytujActionPerformed(evt);
- }
- });
- jButton9.setText("Tabela Ligowa");
- jButton9.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- jButton9ActionPerformed(evt);
- }
- });
- javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
- jPanel1.setLayout(jPanel1Layout);
- jPanel1Layout.setHorizontalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jScrollPane1)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addComponent(jButton1)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton2)
- .addGap(2, 2, 2)
- .addComponent(jButton3)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton4)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton5)
- .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(33, 33, 33)
- .addComponent(przyciskDodaj)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(jButton7)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(przyciskEdytuj)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- .addComponent(jButton9)
- .addGap(95, 95, 95))
- );
- jPanel1Layout.setVerticalGroup(
- jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
- .addGap(49, 49, 49)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(jButton1)
- .addComponent(jButton3)
- .addComponent(jButton2)
- .addComponent(jButton4)
- .addComponent(jButton5))
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(18, 18, 18)
- .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
- .addComponent(przyciskDodaj)
- .addComponent(jButton7)
- .addComponent(przyciskEdytuj)))
- .addGroup(jPanel1Layout.createSequentialGroup()
- .addGap(33, 33, 33)
- .addComponent(jButton9)))
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 63, Short.MAX_VALUE)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 109, javax.swing.GroupLayout.PREFERRED_SIZE))
- );
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
- );
- pack();
- }// </editor-fold>
- private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
- przyciskEdytuj.setEnabled(false);
- ustawKoszykarze();
- }
- private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {
- przyciskEdytuj.setEnabled(false);
- ustawStatystykiMeczu();
- }
- private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
- przyciskEdytuj.setEnabled(true);
- ustawDruzyny();
- }
- private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
- przyciskEdytuj.setEnabled(false);
- ustawMecze();
- }
- private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
- przyciskEdytuj.setEnabled(false);
- ustawStatystykiKoszykarzy(); }
- private void przyciskDodajActionPerformed(java.awt.event.ActionEvent evt) {
- if (status == 1) {
- new Druzyny().setVisible(true);
- ustawDruzyny();
- }
- if (status == 2) {
- Koszykarze k = new Koszykarze();
- k.setVisible(true);
- ustawKoszykarze();
- }
- if (status == 3) {
- Mecze k = new Mecze();
- k.setVisible(true);
- ustawKoszykarze();
- }
- if (status == 4) {
- StatystykiKoszykarzy k = new StatystykiKoszykarzy();
- k.setVisible(true);
- ustawStatystykiKoszykarzy();
- }
- if (status == 5) {
- StatystykiMeczu k = new StatystykiMeczu();
- k.setVisible(true);
- ustawStatystykiMeczu();
- }
- }
- private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {
- if (status == 1) {
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- System.out.println(b);
- CallableStatement c = PolaczZBaza.connection.prepareCall("call usun_druzyna(?)");
- c.setInt(1, Integer.parseInt(b.toString()));
- c.execute();
- System.out.println("asdf");
- ustawDruzyny();
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if (status == 2) {
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- CallableStatement c = PolaczZBaza.connection.prepareCall("call usun_koszykarza(?)");
- c.setInt(1, Integer.parseInt(b.toString()));
- c.execute();
- ustawKoszykarze();
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if (status == 3) {
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- CallableStatement c = PolaczZBaza.connection.prepareCall("call usun_mecz(?)");
- c.setInt(1, Integer.parseInt(b.toString()));
- c.execute();
- ustawKoszykarze();
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if (status == 3) {
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- CallableStatement c = PolaczZBaza.connection.prepareCall("call usun_mecz(?)");
- c.setInt(1, Integer.parseInt(b.toString()));
- c.execute();
- ustawKoszykarze();
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if (status == 4) {
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- Object d = tabela.getValueAt(tabela.getSelectedRow(), 1);
- CallableStatement c = PolaczZBaza.connection.prepareCall("call usun_statystykikoszykarzy(?,?)");
- c.setInt(2, Integer.parseInt(b.toString()));
- c.setInt(1, Integer.parseInt(d.toString()));
- c.execute();
- ustawKoszykarze();
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- if (status == 5) {
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- CallableStatement c = PolaczZBaza.connection.prepareCall("call usun_statystykimecz(?)");
- c.setInt(1, Integer.parseInt(b.toString()));
- c.execute();
- ustawStatystykiMeczu();
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- private void przyciskEdytujActionPerformed(java.awt.event.ActionEvent evt) {
- if (status == 1) {
- System.out.println("1");
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- rs = PolaczZBaza.s.executeQuery("SELECT * FROM druzyny WHERE ID_druzyny="
- + Integer.parseInt(b.toString()));
- rs.next();
- Druzyny d = new Druzyny();
- d.przyciskZapisz.setEnabled(true);
- d.przyciskDodaj.setEnabled(false);
- d.poleId.setText(rs.getObject(1).toString());
- d.poleNazwa.setText(rs.getObject(2).toString());
- d.poleKraj.setText(rs.getObject(3).toString());
- d.setVisible(true);
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else if (status == 2) {
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- Statement ss = PolaczZBaza.connection.createStatement();
- String zapytanie = "SELECT * FROM KOSZYKARZE WHERE ID_KOSZYKARZA="
- + b.toString();
- ResultSet x = ss.executeQuery(zapytanie);
- System.out.println(zapytanie);
- Koszykarze d = new Koszykarze();
- d.przyciskZapisz.setEnabled(true);
- d.przyciskDodaj.setEnabled(false);
- d.poleId.setText(x.getObject(1).toString());
- d.poleDruzyna.setSelectedItem(x.getObject(2));
- d.poleImie.setText(x.getObject(3).toString());
- d.poleNazwisko.setText(x.getObject(4).toString());
- d.polePozycja.setSelectedItem(x.getObject(5));
- d.setVisible(true);
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- } else if (status == 3) {
- System.out.println("1");
- try {
- Object b = tabela.getValueAt(tabela.getSelectedRow(), 0);
- System.out.println("SELECT id_mecz,d1.nazwa,d2.nazwa,termin FROM MECZE "
- + " join druzyny d1 on d1.id_druzyny=id_goscie join druzyny d2 on d2.id_druzyny=id_gospodarze "
- + "WHERE ID_MECZ="
- + Integer.parseInt(b.toString()));
- rs = PolaczZBaza.s.executeQuery("SELECT id_mecz,d1.nazwa,d2.nazwa,termin FROM MECZE "
- + " join druzyny d1 on d1.id_druzyny=id_goscie join druzyny d2 on d2.id_druzyny=id_gospodarze "
- + "WHERE ID_MECZ="
- + Integer.parseInt(b.toString()));
- rs.next();
- Mecze d = new Mecze();
- d.przyciskZapisz.setEnabled(true);
- d.przyciskDodaj.setEnabled(false);
- d.poleGospodarze.setSelectedItem(rs.getObject(1).toString());
- d.poleGoscie.setSelectedItem(rs.getObject(2).toString());
- d.poleTermin.setText(rs.getObject(3).toString());
- d.setVisible(true);
- } catch (SQLException ex) {
- Logger.getLogger(LigaKoszykowki.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- }
- private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {
- status = -1;
- ustawTabele("select nazwa,liczba_punktow(id_druzyny) as punkty from druzyny order by punkty desc");
- }
- private int dajIdDruzyna(String s) {
- try {
- ResultSet r = PolaczZBaza.s.executeQuery("Select id_druzyny from druzyny where nazwa='"
- + s + "'");
- r.next();
- return Integer.parseInt(r.getObject(1).toString());
- } catch (SQLException ex) {
- Logger.getLogger(Mecze.class.getName()).log(Level.SEVERE, null, ex);
- }
- return -1;
- }
- private void ustawTabele(String zapytanie) {
- try {
- ResultSet rs = PolaczZBaza.s.executeQuery(zapytanie);
- java.sql.ResultSetMetaData rsmd = rs.getMetaData();
- int colNo = rsmd.getColumnCount();
- String[] columns = new String[colNo];
- for (int i = 0; i < colNo; i++) {
- columns[i] = rsmd.getColumnName(i + 1);
- }
- DefaultTableModel aModel = new DefaultTableModel();
- aModel.setColumnIdentifiers(columns);
- while (rs.next()) {
- Object[] objects = new Object[colNo];
- for (int i = 0; i < colNo; i++) {
- objects[i] = rs.getObject(i + 1);
- }
- aModel.addRow(objects);
- }
- tabela.setModel(aModel);
- } catch (SQLException ex) {
- System.out.println("Blad");
- }
- }
- private void ustawDruzyny() {
- ustawTabele("select * from druzyny");
- status = 1;
- }
- private void ustawKoszykarze() {
- ustawTabele("select id_koszykarza,nazwa,imie,nazwisko,pozycja from koszykarze "
- + "natural join druzyny order by id_koszykarza");
- status = 2;
- }
- private void ustawMecze() {
- ustawTabele("SELECT id_mecz,d1.nazwa as goscie,d2.nazwa as gospodarze,termin FROM MECZE "
- + " join druzyny d1 on d1.id_druzyny=id_goscie join druzyny d2 on d2.id_druzyny=id_gospodarze ");
- status = 3;
- }
- private void ustawStatystykiKoszykarzy() {
- ustawTabele("select * from statystykikoszykarzy");
- status = 4;
- }
- private void ustawStatystykiMeczu() {
- ustawTabele("select id_mecz,d1.nazwa||' '||d2.nazwa||' '||termin as mecz,gosciewynik,gospodarzewynik from statystykimeczu natural join mecze join druzyny d1 on d1.id_druzyny=id_goscie join druzyny d2 on d2.id_druzyny=id_gospodarze ");
- status = 5;
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(LigaKoszykowki.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(LigaKoszykowki.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(LigaKoszykowki.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(LigaKoszykowki.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new LigaKoszykowki().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JButton jButton1;
- private javax.swing.JButton jButton2;
- private javax.swing.JButton jButton3;
- private javax.swing.JButton jButton4;
- private javax.swing.JButton jButton5;
- private javax.swing.JButton jButton7;
- private javax.swing.JButton jButton9;
- private javax.swing.JPanel jPanel1;
- private javax.swing.JScrollPane jScrollPane1;
- private javax.swing.JButton przyciskDodaj;
- private javax.swing.JButton przyciskEdytuj;
- private javax.swing.JTable tabela;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement