import java.awt.*;
import java.awt.event.*;
import java.sql.ResultSet;
import java.util.ArrayList;
import javax.swing.*;
public class WohnungAnzeigen extends JFrame {
Verbindung vb = new Verbindung();
WohnungErsteller wohnung = new WohnungErsteller(); //Klasse der Arraylist
//ArrayList<Wohnung> list = new ArrayList<Wohnung>();
int counter = 0;
private JTextField textField1;
private JTextField textField2;
private JTextField textField3;
private JButton next;
private JButton back;
private JButton loeschen;
private JButton aendern;
public WohnungAnzeigen() {
super("Anzeige");
this.setLayout(new GridLayout(3, 1));
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setBounds(0, 0, 300, 200);
this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
this.setLocationRelativeTo(null);
textField1 = new JTextField();
textField2 = new JTextField();
textField3 = new JTextField();
next = new JButton("Next");
next.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showNext();
}
});
back = new JButton("Back");
back.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
showLast();
}
});
aendern = new JButton("edit");
aendern.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
}
});
loeschen = new JButton("delete");
loeschen.addActionListener(new ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
deleteCurrent();
}
});
this.getContentPane().add(textField1);
this.getContentPane().add(textField2);
this.getContentPane().add(textField3);
//this.getContentPane().add(transferButton);
this.getContentPane().add(back);
this.getContentPane().add(next);
this.getContentPane().add(aendern);
this.getContentPane().add(loeschen);
}
public void showNext() {
counter++;
if (counter>=wohnung.list.size()) counter = 0;
textField1.setText(wohnung.list.get(counter).getName());
textField2.setText(wohnung.list.get(counter).getMieterName());
textField3.setText(wohnung.list.get(counter).getID());
}
public void deleteCurrent(){
String d;
String s;
d = (wohnung.list.get(counter).getID());
vb.verbinden();
s = "DELETE FROM `mkb`.`vermieter` WHERE `vermieter`.`ID` =" + d;
}
public void showLast() {
counter--;
if (counter>=wohnung.list.size()) counter = 0;
textField1.setText(wohnung.list.get(counter).getName());
textField2.setText(wohnung.list.get(counter).getMieterName());
}
public static void main(String[] args) {
new WohnungAnzeigen().setVisible(true);
}
}