Ejemplo n.º 1
0
  public DBModify() {
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    setBounds(100, 100, 440, 300);
    setVisible(true);
    setResizable(false);

    bg = new JPanel();
    setContentPane(bg);
    bg.setLayout(null);

    pnlOperation = new JPanel();
    pnlOperation.setBounds(10, 10, 415, 30);
    bg.add(pnlOperation);
    pnlOperation.setLayout(null);

    rdbtnAdd = new JRadioButton("ADD");
    rdbtnAdd.setBounds(5, 5, 55, 20);
    rdbtnAdd.addMouseListener(this);
    pnlOperation.add(rdbtnAdd);

    rdbtnDel = new JRadioButton("DEL");
    rdbtnDel.setBounds(200, 5, 55, 20);
    rdbtnDel.addMouseListener(this);
    pnlOperation.add(rdbtnDel);

    rdbtnEdit = new JRadioButton("EDIT");
    rdbtnEdit.setBounds(100, 5, 55, 20);
    rdbtnEdit.addMouseListener(this);
    pnlOperation.add(rdbtnEdit);

    tglbtnCards = new JToggleButton("Blackcard");
    tglbtnCards.setBounds(285, 5, 120, 25);
    tglbtnCards.addMouseListener(this);
    pnlOperation.add(tglbtnCards);

    btnConfirm = new JButton("Confirm Changes");
    btnConfirm.setBounds(10, 45, 415, 25);
    btnConfirm.addMouseListener(this);
    bg.add(btnConfirm);

    getContentPane().add(pnlAddWhitecards);
    pnlAddWhitecards.setVisible(false);
    getContentPane().add(pnlAddBlackcards);
    pnlAddBlackcards.setVisible(false);

    getContentPane().add(pnlEditWhitecards);
    pnlEditWhitecards.setVisible(false);
    getContentPane().add(pnlEditBlackcards);
    pnlEditBlackcards.setVisible(false);

    getContentPane().add(pnlDelWhitecards);
    pnlDelWhitecards.setVisible(false);
    getContentPane().add(pnlDelBlackcards);
    pnlDelBlackcards.setVisible(false);

    // listener auf objekte seteztebn
    pnlAddBlackcards.getBtnAdd().addMouseListener(this);
    pnlAddWhitecards.getBtnAdd().addMouseListener(this);
    pnlDelBlackcards.getBtnDelete().addMouseListener(this);
    pnlDelBlackcards.getTxtCardID().addKeyListener(this);
    pnlDelWhitecards.getBtnDelete().addMouseListener(this);
    pnlDelWhitecards.getTxtCardID().addKeyListener(this);
    pnlEditBlackcards.getBtnChange().addMouseListener(this);
    pnlEditBlackcards.getTxtCardID().addKeyListener(this);
    pnlEditWhitecards.getBtnChange().addMouseListener(this);
    pnlEditWhitecards.getTxtCardID().addKeyListener(this);
  }
Ejemplo n.º 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");
    }
  }