Merge branch 'master' of https://git.gaminggeneration.de/PaulK/IDB-Projekt-Hue
# Conflicts: # out/production/IDB-Hue-Projekt/Menu.class
This commit is contained in:
commit
4fca90af4b
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 8.7 KiB |
270
src/Einzelansicht.java
Normal file
270
src/Einzelansicht.java
Normal file
@ -0,0 +1,270 @@
|
|||||||
|
import javax.swing.*;
|
||||||
|
import javax.swing.event.*;
|
||||||
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.*;
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class Einzelansicht extends JFrame implements TableModelListener {
|
||||||
|
|
||||||
|
JScrollPane sc = null;
|
||||||
|
JButton a = null;
|
||||||
|
JButton einf = null;
|
||||||
|
JButton del = null;
|
||||||
|
static JButton zur = null;
|
||||||
|
static JButton vor = null;
|
||||||
|
static ResultSetMetaData rm = null;
|
||||||
|
static DefaultTableModel t = new DefaultTableModel();
|
||||||
|
static JTable table = new JTable(t);
|
||||||
|
static ResultSet r = null;
|
||||||
|
static String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
||||||
|
|
||||||
|
JTextField s = null;
|
||||||
|
String tab = null;
|
||||||
|
|
||||||
|
JLabel such = null;
|
||||||
|
|
||||||
|
Font font = new Font("Arial", Font.PLAIN, 12);
|
||||||
|
String sql = null;
|
||||||
|
String sq = "";
|
||||||
|
static int i = 0;
|
||||||
|
|
||||||
|
public Einzelansicht(String ta) {
|
||||||
|
this.setSize(500, 400);
|
||||||
|
this.setResizable(false);
|
||||||
|
this.setLayout(null);
|
||||||
|
tab = ta;
|
||||||
|
|
||||||
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
r = s.executeQuery("Select * FROM " + tab);
|
||||||
|
rm = r.getMetaData();
|
||||||
|
sql = "Select * From " + tab + " Where " + rm.getColumnName(1) + " =" + 1;
|
||||||
|
einfügen(tab, sql);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
vor = new JButton("Weiter");
|
||||||
|
vor.setBounds(300, 150, 90, 50);
|
||||||
|
vor.setFont(font);
|
||||||
|
vor.setBackground(Color.white);
|
||||||
|
vor.setForeground(Color.black);
|
||||||
|
vor.addActionListener(e -> {
|
||||||
|
i++;
|
||||||
|
try {
|
||||||
|
sql = "Select * From " + tab + " Where " + rm.getColumnName(1) + " =" + i;
|
||||||
|
einfügen(tab, sql);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.add(vor);
|
||||||
|
|
||||||
|
zur = new JButton("Letzte");
|
||||||
|
zur.setBounds(150, 150, 90, 50);
|
||||||
|
zur.setFont(font);
|
||||||
|
zur.setBackground(Color.white);
|
||||||
|
zur.setForeground(Color.black);
|
||||||
|
zur.addActionListener(e -> {
|
||||||
|
if(i>1){
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sql = "Select * From " + tab + " Where " + rm.getColumnName(1) + " =" + i;
|
||||||
|
einfügen(tab, sql);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.add(zur);
|
||||||
|
|
||||||
|
|
||||||
|
sc = new JScrollPane(Einzelansicht.table);
|
||||||
|
sc.setBounds(50, 100, 400, 50);
|
||||||
|
sc.getHorizontalScrollBar();
|
||||||
|
this.add(sc);
|
||||||
|
|
||||||
|
a = new JButton("Zurück");
|
||||||
|
a.setBounds(50, 30, 70, 50);
|
||||||
|
a.setForeground(Color.BLACK);
|
||||||
|
a.setBackground(Color.white);
|
||||||
|
a.setFont(font);
|
||||||
|
a.addActionListener(e -> {
|
||||||
|
this.dispose();
|
||||||
|
Menu m = new Menu();
|
||||||
|
m.setVisible(true);
|
||||||
|
});
|
||||||
|
this.add(a);
|
||||||
|
|
||||||
|
einf = new JButton("Einfügen");
|
||||||
|
einf.setBounds(150, 280, 100, 50);
|
||||||
|
einf.setForeground(Color.BLACK);
|
||||||
|
einf.setBackground(Color.white);
|
||||||
|
einf.setFont(font);
|
||||||
|
einf.addActionListener(e -> {
|
||||||
|
Hinzufügen d = new Hinzufügen(r, tab);
|
||||||
|
d.setVisible(true);
|
||||||
|
this.setFocusable(false);
|
||||||
|
|
||||||
|
});
|
||||||
|
this.add(einf);
|
||||||
|
|
||||||
|
|
||||||
|
del = new JButton("Löschen");
|
||||||
|
del.setBounds(300, 280, 100, 50);
|
||||||
|
del.setForeground(Color.BLACK);
|
||||||
|
del.setBackground(Color.white);
|
||||||
|
del.setFont(font);
|
||||||
|
del.addActionListener(e -> {
|
||||||
|
System.out.println(t.getValueAt(0,0));
|
||||||
|
String wh = t.getValueAt(0, 0).toString();
|
||||||
|
int response = JOptionPane.showConfirmDialog(null, "Wollen Sie den Eintrag löschen?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
if (response == 0) {
|
||||||
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
ResultSet r = s.executeQuery("DELETE From " + tab + " WHERE " + t.getColumnName(0) + "=" + wh);
|
||||||
|
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
Tabellen.einfügen(tab);
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
Einzelansicht.table.clearSelection();
|
||||||
|
table.clearSelection();
|
||||||
|
t.removeRow(0);
|
||||||
|
t.fireTableDataChanged();
|
||||||
|
|
||||||
|
});
|
||||||
|
this.add(del);
|
||||||
|
|
||||||
|
such = new JLabel("Suchen");
|
||||||
|
such.setBounds(300, 10, 50, 20);
|
||||||
|
this.add(such);
|
||||||
|
|
||||||
|
s = new JTextField();
|
||||||
|
s.setBounds(300, 30, 150, 40);
|
||||||
|
this.add(s);
|
||||||
|
suchen();
|
||||||
|
|
||||||
|
t.addTableModelListener(this);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void einfügen(String tab, String sql) {
|
||||||
|
String[][] temp = {{""}};
|
||||||
|
|
||||||
|
|
||||||
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
r = s.executeQuery(sql);
|
||||||
|
rm = r.getMetaData();
|
||||||
|
rm.getColumnCount();
|
||||||
|
String column[] = new String[rm.getColumnCount()];
|
||||||
|
|
||||||
|
|
||||||
|
for (int i = 1; i <= rm.getColumnCount(); i++) {
|
||||||
|
column[i - 1] = rm.getColumnName(i);
|
||||||
|
t.addColumn(column[i - 1]);
|
||||||
|
}
|
||||||
|
t.setDataVector(temp, column);
|
||||||
|
t.removeRow(0);
|
||||||
|
|
||||||
|
Object rows[] = new Object[rm.getColumnCount()];
|
||||||
|
while (r.next()) {
|
||||||
|
for (int i = 1; i <= rm.getColumnCount(); i++) {
|
||||||
|
rows[i - 1] = r.getString(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
t.addRow(rows);
|
||||||
|
t.fireTableDataChanged();
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public void suchen() {
|
||||||
|
s.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
@Override
|
||||||
|
public void insertUpdate(DocumentEvent e) {
|
||||||
|
search(s.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
search(s.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changedUpdate(DocumentEvent e) {
|
||||||
|
search(s.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void search(String st) {
|
||||||
|
if (st.length() == 0) {
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
for (int j = 1; j <= rm.getColumnCount(); j++) {
|
||||||
|
System.out.println(sq);
|
||||||
|
if (j == rm.getColumnCount()) {
|
||||||
|
sq = sq + rm.getColumnName(j) + " LIKE '%" + st + "%'";
|
||||||
|
} else {
|
||||||
|
sq = sq + rm.getColumnName(j) + " LIKE '%" + st + "%' or ";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sql="Select * FROm "+tab+ " Where "+sq;
|
||||||
|
System.out.println(sql);
|
||||||
|
einfügen(tab,sql);
|
||||||
|
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void tableChanged(TableModelEvent e) {
|
||||||
|
int zeile = table.getSelectedRow();
|
||||||
|
int spalte = table.getSelectedColumn();
|
||||||
|
if (spalte > 0 && zeile > 0) {
|
||||||
|
int response = 0;
|
||||||
|
try {
|
||||||
|
response = JOptionPane.showConfirmDialog(null, "Wollen Sie dein Eintrag in Zeile " + (zeile + 1) + ", Spalte :" + (rm.getColumnName(spalte + 1)) + " ändern?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
if (response == 0) {
|
||||||
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
System.out.println(t.getColumnName(spalte) + "\n" + rm.getColumnTypeName(spalte + 1));
|
||||||
|
if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Varchar")) {
|
||||||
|
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
||||||
|
|
||||||
|
} else if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Date")) {
|
||||||
|
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= " + t.getValueAt(zeile, spalte).toString() + " WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
||||||
|
|
||||||
|
}
|
||||||
|
table.clearSelection();
|
||||||
|
} catch (SQLException f) {
|
||||||
|
throw new RuntimeException(f);
|
||||||
|
}
|
||||||
|
t.fireTableDataChanged();
|
||||||
|
} else {
|
||||||
|
table.clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import javax.swing.table.DefaultTableModel;
|
||||||
|
import java.awt.*;
|
||||||
import java.awt.event.*;
|
import java.awt.event.*;
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
@ -17,6 +18,7 @@ public class Hinzufügen extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
String spalten = "";
|
String spalten = "";
|
||||||
String sname = "";
|
String sname = "";
|
||||||
|
Font font = new Font("Arial",Font.PLAIN,12);
|
||||||
|
|
||||||
public Hinzufügen(ResultSet r, String tab) {
|
public Hinzufügen(ResultSet r, String tab) {
|
||||||
this.setSize(500, 600);
|
this.setSize(500, 600);
|
||||||
@ -26,6 +28,9 @@ public class Hinzufügen extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
a = new JButton("Zurück");
|
a = new JButton("Zurück");
|
||||||
a.setBounds(50, 30, 80, 50);
|
a.setBounds(50, 30, 80, 50);
|
||||||
|
a.setFont(font);
|
||||||
|
a.setBackground(Color.white);
|
||||||
|
a.setForeground(Color.black);
|
||||||
a.addActionListener(e -> {
|
a.addActionListener(e -> {
|
||||||
this.dispose();
|
this.dispose();
|
||||||
});
|
});
|
||||||
@ -53,6 +58,9 @@ public class Hinzufügen extends JFrame implements ActionListener {
|
|||||||
}
|
}
|
||||||
einf = new JButton("Einfügen");
|
einf = new JButton("Einfügen");
|
||||||
einf.setBounds(50, 480, 100, 50);
|
einf.setBounds(50, 480, 100, 50);
|
||||||
|
einf.setFont(font);
|
||||||
|
einf.setForeground(Color.black);
|
||||||
|
einf.setBackground(Color.white);
|
||||||
einf.addActionListener(e -> {
|
einf.addActionListener(e -> {
|
||||||
for (int i = 1; i < z; i++) {
|
for (int i = 1; i < z; i++) {
|
||||||
try {
|
try {
|
||||||
|
@ -6,48 +6,77 @@ import java.sql.*;
|
|||||||
public class Menu extends JFrame implements ActionListener {
|
public class Menu extends JFrame implements ActionListener {
|
||||||
JScrollPane sc = null;
|
JScrollPane sc = null;
|
||||||
JButton a = null;
|
JButton a = null;
|
||||||
|
JButton v = null;
|
||||||
JLabel i = null;
|
|
||||||
JList list = null;
|
JList list = null;
|
||||||
ImageIcon img = null;
|
|
||||||
|
|
||||||
String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
||||||
|
String table = null;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Menu m = new Menu();
|
Menu m = new Menu();
|
||||||
m.setVisible(true);
|
m.setVisible(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Menu() {
|
public Menu() {
|
||||||
this.setSize(500, 600);
|
this.setSize(500, 600);
|
||||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
this.setBackground(Color.WHITE);
|
this.setBackground(Color.WHITE);
|
||||||
|
|
||||||
|
JLabel lbl = new JLabel("");
|
||||||
|
ImageIcon img = new ImageIcon(new ImageIcon(Menu.class.getResource("/image/Bundesiga.jfif")).getImage());
|
||||||
|
lbl.setIcon(img);
|
||||||
|
lbl.setBounds(150, 50, 200,202);
|
||||||
|
this.getContentPane().add(lbl);
|
||||||
|
this.add(lbl);
|
||||||
|
|
||||||
|
v = new JButton("Einzelansicht");
|
||||||
|
v.setBounds(200, 420, 100, 60);
|
||||||
|
v.setFont(new Font("Arial", Font.PLAIN, 11));
|
||||||
|
v.setForeground(Color.black);
|
||||||
|
v.setBackground(Color.white);
|
||||||
|
v.addActionListener(e -> {
|
||||||
|
table = list.getSelectedValue().toString();
|
||||||
|
Einzelansicht a = new Einzelansicht(table);
|
||||||
|
a.setVisible(true);
|
||||||
|
this.dispose();
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
a = new JButton("Anzeigen");
|
a = new JButton("Anzeigen");
|
||||||
a.setBounds(200, 200, 150, 70);
|
a.setBounds(200, 350, 90, 60);
|
||||||
a.setFont(new Font("Arial",Font.PLAIN,15));
|
a.setFont(new Font("Arial", Font.PLAIN, 12));
|
||||||
|
a.setForeground(Color.black);
|
||||||
|
a.setBackground(Color.white);
|
||||||
a.addActionListener(e -> {
|
a.addActionListener(e -> {
|
||||||
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
String table = list.getSelectedValue().toString();
|
if (list.isSelectionEmpty()) {
|
||||||
|
JOptionPane.showMessageDialog(null, "Wählen sie eine Tabelle aus!");
|
||||||
|
} else {
|
||||||
|
table = list.getSelectedValue().toString();
|
||||||
Tabellen t = new Tabellen(url, table);
|
Tabellen t = new Tabellen(url, table);
|
||||||
t.setVisible(true);
|
t.setVisible(true);
|
||||||
t.setTitle(list.getSelectedValue().toString());
|
t.setTitle(list.getSelectedValue().toString());
|
||||||
|
this.dispose();
|
||||||
|
}
|
||||||
} catch (SQLException ex) {
|
} catch (SQLException ex) {
|
||||||
throw new RuntimeException(ex);
|
throw new RuntimeException(ex);
|
||||||
}
|
}
|
||||||
this.dispose();
|
|
||||||
});
|
});
|
||||||
this.add(a);
|
this.add(a);
|
||||||
|
|
||||||
|
|
||||||
DefaultListModel liste = new DefaultListModel();
|
DefaultListModel liste = new DefaultListModel();
|
||||||
list = new JList(liste);
|
list = new JList(liste);
|
||||||
|
list.addListSelectionListener(e -> {
|
||||||
|
if (list.getSelectedValue().toString().equalsIgnoreCase("Verein") || list.getSelectedValue().toString().equalsIgnoreCase("test")) {
|
||||||
|
this.add(v);
|
||||||
|
|
||||||
|
} else
|
||||||
|
this.remove(v);
|
||||||
|
});
|
||||||
sc = new JScrollPane();
|
sc = new JScrollPane();
|
||||||
sc.setViewportView(list);
|
sc.setViewportView(list);
|
||||||
sc.setBounds(30, 150, 150, 200);
|
sc.setBounds(30, 300, 150, 200);
|
||||||
this.add(sc);
|
this.add(sc);
|
||||||
|
|
||||||
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
@ -64,10 +93,7 @@ public class Menu extends JFrame implements ActionListener {
|
|||||||
|
|
||||||
public void paint(Graphics g) {
|
public void paint(Graphics g) {
|
||||||
super.paint(g);
|
super.paint(g);
|
||||||
img = new ImageIcon("src/image/Bundesliga.jpg");
|
|
||||||
i = new JLabel(img);
|
|
||||||
i.setBounds(150, 280, 200, 100);
|
|
||||||
this.add(i);
|
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,7 @@
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.TableModelEvent;
|
import javax.swing.event.*;
|
||||||
import javax.swing.event.TableModelListener;
|
import javax.swing.table.*;
|
||||||
import javax.swing.table.DefaultTableModel;
|
import java.awt.*;
|
||||||
import javax.swing.table.JTableHeader;
|
|
||||||
import java.awt.event.*;
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
|
|
||||||
public class Tabellen extends JFrame implements TableModelListener {
|
public class Tabellen extends JFrame implements TableModelListener {
|
||||||
@ -16,23 +14,36 @@ public class Tabellen extends JFrame implements TableModelListener {
|
|||||||
static JTable table = new JTable(t);
|
static JTable table = new JTable(t);
|
||||||
static ResultSet r = null;
|
static ResultSet r = null;
|
||||||
static String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
static String url = "jdbc:mariadb://127.0.0.1:3306/bundesliga";
|
||||||
|
TableRowSorter sorter = null;
|
||||||
|
|
||||||
|
JTextField s = null;
|
||||||
|
String tab = null;
|
||||||
|
|
||||||
|
JLabel such = null;
|
||||||
|
|
||||||
|
Font font = new Font("Arial",Font.PLAIN,12);
|
||||||
|
|
||||||
|
|
||||||
public Tabellen(String url, String tab) {
|
public Tabellen(String url, String ta) {
|
||||||
this.setSize(500, 600);
|
this.setSize(500, 600);
|
||||||
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
|
||||||
this.setLayout(null);
|
this.setLayout(null);
|
||||||
|
tab = ta;
|
||||||
|
|
||||||
|
|
||||||
einfügen(tab);
|
einfügen(tab);
|
||||||
|
|
||||||
|
|
||||||
sc = new JScrollPane(table);
|
sc = new JScrollPane(table);
|
||||||
sc.setBounds(50, 100, 400, 350);
|
sc.setBounds(50, 100, 400, 350);
|
||||||
sc.getHorizontalScrollBar();
|
sc.getHorizontalScrollBar();
|
||||||
this.add(sc);
|
this.add(sc);
|
||||||
|
|
||||||
a = new JButton("Zurück");
|
a = new JButton("Zurück");
|
||||||
a.setBounds(50, 30, 80, 50);
|
a.setBounds(50, 30, 70, 50);
|
||||||
|
a.setForeground(Color.BLACK);
|
||||||
|
a.setBackground(Color.white);
|
||||||
|
a.setFont(font);
|
||||||
a.addActionListener(e -> {
|
a.addActionListener(e -> {
|
||||||
this.dispose();
|
this.dispose();
|
||||||
Menu m = new Menu();
|
Menu m = new Menu();
|
||||||
@ -42,6 +53,9 @@ public class Tabellen extends JFrame implements TableModelListener {
|
|||||||
|
|
||||||
einf = new JButton("Einfügen");
|
einf = new JButton("Einfügen");
|
||||||
einf.setBounds(50, 480, 100, 50);
|
einf.setBounds(50, 480, 100, 50);
|
||||||
|
einf.setForeground(Color.BLACK);
|
||||||
|
einf.setBackground(Color.white);
|
||||||
|
einf.setFont(font);
|
||||||
einf.addActionListener(e -> {
|
einf.addActionListener(e -> {
|
||||||
Hinzufügen d = new Hinzufügen(r, tab);
|
Hinzufügen d = new Hinzufügen(r, tab);
|
||||||
d.setVisible(true);
|
d.setVisible(true);
|
||||||
@ -53,6 +67,9 @@ public class Tabellen extends JFrame implements TableModelListener {
|
|||||||
|
|
||||||
del = new JButton("Löschen");
|
del = new JButton("Löschen");
|
||||||
del.setBounds(180, 480, 100, 50);
|
del.setBounds(180, 480, 100, 50);
|
||||||
|
del.setForeground(Color.BLACK);
|
||||||
|
del.setBackground(Color.white);
|
||||||
|
del.setFont(font);
|
||||||
del.addActionListener(e -> {
|
del.addActionListener(e -> {
|
||||||
Löschen l = new Löschen(tab, t, table);
|
Löschen l = new Löschen(tab, t, table);
|
||||||
table.clearSelection();
|
table.clearSelection();
|
||||||
@ -60,43 +77,18 @@ public class Tabellen extends JFrame implements TableModelListener {
|
|||||||
});
|
});
|
||||||
this.add(del);
|
this.add(del);
|
||||||
|
|
||||||
t.addTableModelListener(e -> {
|
such = new JLabel("Suchen");
|
||||||
int zeile = table.getSelectedRow();
|
such.setBounds(300, 10, 50, 20);
|
||||||
int spalte = table.getSelectedColumn();
|
this.add(such);
|
||||||
if (spalte > 0 && zeile > 0) {
|
|
||||||
int response = 0;
|
|
||||||
try {
|
|
||||||
response = JOptionPane.showConfirmDialog(null, "Wollen Sie dein Eintrag in Zeile " + (zeile + 1) + ", Spalte :" + (rm.getColumnName(spalte + 1)) + " ändern?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
|
||||||
} catch (SQLException ex) {
|
|
||||||
throw new RuntimeException(ex);
|
|
||||||
}
|
|
||||||
if (response == 0) {
|
|
||||||
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
|
||||||
Statement s = conn.createStatement();
|
|
||||||
System.out.println(t.getColumnName(spalte) + "\n" + rm.getColumnTypeName(spalte + 1));
|
|
||||||
if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Varchar")) {
|
|
||||||
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
|
||||||
|
|
||||||
} else if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Date")) {
|
s = new JTextField();
|
||||||
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
s.setBounds(300, 30, 150, 40);
|
||||||
|
this.add(s);
|
||||||
|
suchen();
|
||||||
|
|
||||||
} else {
|
t.addTableModelListener(this);
|
||||||
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= " + t.getValueAt(zeile, spalte).toString() + " WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
table.clearSelection();
|
|
||||||
} catch (SQLException f) {
|
|
||||||
throw new RuntimeException(f);
|
|
||||||
}
|
|
||||||
t.fireTableDataChanged();
|
|
||||||
} else {
|
|
||||||
table.clearSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void einfügen(String tab) {
|
public static void einfügen(String tab) {
|
||||||
String[][] temp = {{""}};
|
String[][] temp = {{""}};
|
||||||
@ -133,10 +125,72 @@ public class Tabellen extends JFrame implements TableModelListener {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void suchen() {
|
||||||
|
sorter = new TableRowSorter(t);
|
||||||
|
table.setRowSorter(sorter);
|
||||||
|
s.getDocument().addDocumentListener(new DocumentListener() {
|
||||||
|
@Override
|
||||||
|
public void insertUpdate(DocumentEvent e) {
|
||||||
|
search(s.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeUpdate(DocumentEvent e) {
|
||||||
|
search(s.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void changedUpdate(DocumentEvent e) {
|
||||||
|
search(s.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void search(String st) {
|
||||||
|
if (st.length() == 0) {
|
||||||
|
sorter.setRowFilter(null);
|
||||||
|
} else {
|
||||||
|
sorter.setRowFilter(RowFilter.regexFilter(st));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void tableChanged(TableModelEvent e) {
|
public void tableChanged(TableModelEvent e) {
|
||||||
System.out.println(table.getSelectedRow() + "" + table.getSelectedColumn());
|
int zeile = table.getSelectedRow();
|
||||||
|
int spalte = table.getSelectedColumn();
|
||||||
|
if (spalte > 0 && zeile > 0) {
|
||||||
|
int response = 0;
|
||||||
|
try {
|
||||||
|
response = JOptionPane.showConfirmDialog(null, "Wollen Sie dein Eintrag in Zeile " + (zeile + 1) + ", Spalte :" + (rm.getColumnName(spalte + 1)) + " ändern?", "Bestätigen", JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
|
||||||
|
} catch (SQLException ex) {
|
||||||
|
throw new RuntimeException(ex);
|
||||||
|
}
|
||||||
|
if (response == 0) {
|
||||||
|
try (Connection conn = DriverManager.getConnection(url, "root", "")) {
|
||||||
|
Statement s = conn.createStatement();
|
||||||
|
System.out.println(t.getColumnName(spalte) + "\n" + rm.getColumnTypeName(spalte + 1));
|
||||||
|
if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Varchar")) {
|
||||||
|
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
||||||
|
|
||||||
|
} else if (rm.getColumnTypeName(spalte + 1).equalsIgnoreCase("Date")) {
|
||||||
|
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= '" + t.getValueAt(zeile, spalte).toString() + "' WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ResultSet r = s.executeQuery("Update " + tab + " set " + t.getColumnName(spalte) + "= " + t.getValueAt(zeile, spalte).toString() + " WHERE " + t.getColumnName(0) + " = " + t.getValueAt(zeile, 0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
table.clearSelection();
|
||||||
|
} catch (SQLException f) {
|
||||||
|
throw new RuntimeException(f);
|
||||||
}
|
}
|
||||||
|
t.fireTableDataChanged();
|
||||||
|
} else {
|
||||||
|
table.clearSelection();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
BIN
src/image/Bundesiga.jfif
Normal file
BIN
src/image/Bundesiga.jfif
Normal file
Binary file not shown.
After Width: | Height: | Size: 15 KiB |
Binary file not shown.
Before Width: | Height: | Size: 8.7 KiB |
BIN
src/image/Download.jfif
Normal file
BIN
src/image/Download.jfif
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.4 KiB |
Loading…
x
Reference in New Issue
Block a user