Пример #1
0
  @Override
  public void keyReleased(
      KeyEvent e) { // listerner um in tablle selektierbe karte anzuzeuhen und hervor zu heben
    if (e.getSource().equals(pnlDelBlackcards.getTxtCardID())) {
      if (pnlDelBlackcards.getTxtCardID().getText().equals("") == false) {
        int tmp =
            positionOfBlackcardardID(Integer.parseInt(pnlDelBlackcards.getTxtCardID().getText()));

        pnlDelBlackcards.getTable().getTable().setRowSelectionInterval(tmp, tmp);
        pnlDelBlackcards
            .getTable()
            .getTable()
            .scrollRectToVisible(
                new Rectangle(
                    pnlDelBlackcards.getTable().getTable().getCellRect(tmp + 3, 0, false)));
      }
    } else if (e.getSource().equals(pnlDelWhitecards.getTxtCardID())) {
      if (pnlDelWhitecards.getTxtCardID().getText().equals("") == false) {
        int tmp =
            positionOfWhitecardardID(Integer.parseInt(pnlDelWhitecards.getTxtCardID().getText()));

        pnlDelWhitecards.getTable().getTable().setRowSelectionInterval(tmp, tmp);
        pnlDelWhitecards
            .getTable()
            .getTable()
            .scrollRectToVisible(
                new Rectangle(
                    pnlDelWhitecards.getTable().getTable().getCellRect(tmp + 3, 0, false)));
      }
    } else if (e.getSource().equals(pnlEditBlackcards.getTxtCardID())) {
      if (pnlEditBlackcards.getTxtCardID().getText().equals("") == false) {
        int tmp =
            positionOfBlackcardardID(Integer.parseInt(pnlEditBlackcards.getTxtCardID().getText()));

        pnlEditBlackcards.getTable().getTable().setRowSelectionInterval(tmp, tmp);
        pnlEditBlackcards
            .getTable()
            .getTable()
            .scrollRectToVisible(
                new Rectangle(
                    pnlEditBlackcards.getTable().getTable().getCellRect(tmp + 1, 0, false)));

        pnlEditBlackcards
            .getTxtFieldNewText()
            .setText(
                db.executeCommandArray(
                        "SELECT Text FROM Blackcards WHERE ID = "
                            + pnlEditBlackcards.getTxtCardID().getText())[0][0]);
        pnlEditBlackcards
            .getTxtCardsToSet()
            .setText(
                db.executeCommandArray(
                        "SELECT CardsToSet FROM Blackcards WHERE ID = "
                            + pnlEditBlackcards.getTxtCardID().getText())[0][0]);
        pnlEditBlackcards
            .getTxtChangeExpansion()
            .setText(
                db.executeCommandArray(
                        "SELECT Expansion FROM Blackcards WHERE ID = "
                            + pnlEditBlackcards.getTxtCardID().getText())[0][0]);
      }
    } else if (e.getSource().equals(pnlEditWhitecards.getTxtCardID())) {
      if (pnlEditWhitecards.getTxtCardID().getText().equals("") == false) {
        int tmp =
            positionOfWhitecardardID(Integer.parseInt(pnlEditWhitecards.getTxtCardID().getText()));

        pnlEditWhitecards.getTable().getTable().setRowSelectionInterval(tmp, tmp);
        pnlEditWhitecards
            .getTable()
            .getTable()
            .scrollRectToVisible(
                new Rectangle(
                    pnlEditWhitecards.getTable().getTable().getCellRect(tmp + 1, 0, false)));
        pnlEditWhitecards
            .getTxtFieldNewText()
            .setText(
                db.executeCommandArray(
                        "SELECT Text FROM Whitecards WHERE ID = "
                            + pnlEditWhitecards.getTxtCardID().getText())[0][0]);
        pnlEditWhitecards
            .getTxtChangeExpansion()
            .setText(
                db.executeCommandArray(
                        "SELECT Expansion FROM Whitecards WHERE ID = "
                            + pnlEditWhitecards.getTxtCardID().getText())[0][0]);
      }
    }
  }
Пример #2
0
  @Override
  public void mouseClicked(MouseEvent e) {
    if (e.getSource().equals(btnConfirm)) {
      try {
        int confirm =
            JOptionPane.showConfirmDialog(
                null,
                "WARNING: You can damage the GameDB!\nDo you want to continue? This can not be undone! ",
                "Confirm Changes to GameDB",
                JOptionPane
                    .YES_NO_OPTION); // bestätigungs dialog wenn änderungen gespeichernt werden
                                     // sollen
        if (confirm == JOptionPane.YES_OPTION) {
          db.getCon().commit(); //  änderungen in db spichern
        }

        dispose(); // fenster löscne
        new DBInterface(); // neues db interface öffnen

      } catch (SQLException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
      }
    } else if (e.getSource().equals(tglbtnCards)) { // tglbtn state ändern
      if (cardtypeFlag) {
        cardtypeFlag = false;
        tglbtnCards.setText("Blackcard");
      } else {
        cardtypeFlag = true;
        tglbtnCards.setText("Whitecard");
      }
      displayPanel(e);
    } else if (e.getSource().equals(rdbtnAdd)
        || e.getSource().equals(rdbtnEdit)
        || e.getSource()
            .equals(rdbtnDel)) { // wenn einer der dem rdbtn gedrückt pnl steuerung aufrufen
      displayPanel(e);
    } else if (e.getSource()
        .equals(
            pnlAddBlackcards
                .getBtnAdd())) { // prüfung auf btn in verschienden pnls und entprechenden befehle
                                 // ausfühen. änderungen erst nach commit dauerhaft gespeicert
      db.executeCommandNoReturn(
          "INSERT INTO Blackcards(Text , IsPlayable , CardsToSet, Expansion) VALUES ('"
              + pnlAddBlackcards.getTxtFieldText().getText()
              + "' ,  1 , "
              + pnlAddBlackcards.getTxtCardsToSet().getText()
              + ",'"
              + pnlAddBlackcards.getTxtExpansion().getText()
              + "'"
              + ");");
      //			System.out.println("pnlAddBlackcards.btnAdd");
    } else if (e.getSource().equals(pnlAddWhitecards.getBtnAdd())) {
      db.executeCommandNoReturn(
          "INSERT INTO Whitecards(Text , IsPlayable, Expansion) VALUES ('"
              + pnlAddWhitecards.getTxtFieldText().getText()
              + "' ,  1"
              + ",'"
              + pnlAddWhitecards.getTxtExpansion().getText()
              + "'"
              + ");");
      //			System.out.println("pnlAddWhitecards.btnAdd");
    } else if (e.getSource().equals(pnlDelBlackcards.getBtnDelete())) {
      db.executeCommandNoReturn(
          "DELETE FROM Blackcards WHERE ID = " + pnlDelBlackcards.getTxtCardID().getText());
      //			System.out.println("pnlDelBlackcards.btnDelete");
    } else if (e.getSource().equals(pnlDelWhitecards.getBtnDelete())) {
      db.executeCommandNoReturn(
          "DELETE FROM Whitecards WHERE ID = " + pnlDelWhitecards.getTxtCardID().getText());
      //			System.out.println("pnlDelWhitecards.btnDelete");
    } else if (e.getSource().equals(pnlEditBlackcards.getBtnChange())) {
      db.executeCommandNoReturn(
          "UPDATE Blackcards SET Text = '"
              + pnlEditBlackcards.getTxtFieldNewText().getText()
              + "', CardsToSet = "
              + pnlEditBlackcards.getTxtCardsToSet().getText()
              + ", Expansion = '"
              + pnlEditBlackcards.getTxtChangeExpansion().getText()
              + "' WHERE ID = "
              + pnlEditBlackcards.getTxtCardID().getText());
      //			System.out.println("pnlEditBlackcards.btnChange)");
    } else if (e.getSource().equals(pnlEditWhitecards.getBtnChange())) {
      db.executeCommandNoReturn(
          "UPDATE Whitecards SET Text = '"
              + pnlEditWhitecards.getTxtFieldNewText().getText()
              + "', Expansion = '"
              + pnlEditWhitecards.getTxtChangeExpansion().getText()
              + "' WHERE ID = "
              + pnlEditWhitecards.getTxtCardID().getText());
      //			System.out.println("pnlEditWhitecards.btnChange");
    }
  }