private void displayPanel(MouseEvent e) { // steruunt anzeige der panles hidePanels(); // alle pnl ausblenen disselectRdbtn(); // alle rbtn zurücksetzen if (cardtypeFlag) { // true = Whitecard false = Blackcard if (e.getSource().equals(rdbtnAdd)) { pnlAddWhitecards.setVisible(true); rdbtnAdd.setSelected(true); setBounds(100, 100, 440, 300); } else if (e.getSource().equals(rdbtnEdit)) { pnlEditWhitecards.setVisible(true); rdbtnEdit.setSelected(true); setBounds(100, 100, 440, 600); } else if (e.getSource().equals(rdbtnDel)) { pnlDelWhitecards.setVisible(true); rdbtnDel.setSelected(true); setBounds(100, 100, 440, 600); } } else { if (e.getSource().equals(rdbtnAdd)) { pnlAddBlackcards.setVisible(true); rdbtnAdd.setSelected(true); setBounds(100, 100, 440, 300); } else if (e.getSource().equals(rdbtnEdit)) { pnlEditBlackcards.setVisible(true); rdbtnEdit.setSelected(true); setBounds(100, 100, 440, 600); } else if (e.getSource().equals(rdbtnDel)) { pnlDelBlackcards.setVisible(true); rdbtnDel.setSelected(true); setBounds(100, 100, 440, 600); } } }
private void hidePanels() { // alle pnls ausblenen pnlAddWhitecards.setVisible(false); pnlAddBlackcards.setVisible(false); pnlEditWhitecards.setVisible(false); pnlEditBlackcards.setVisible(false); pnlDelWhitecards.setVisible(false); pnlDelBlackcards.setVisible(false); }
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); }
@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]); } } }
@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"); } }