|
|
@ -30,165 +30,228 @@ import javax.swing.border.MatteBorder; |
|
|
|
import javax.swing.border.BevelBorder; |
|
|
|
import javax.swing.border.TitledBorder; |
|
|
|
import javax.swing.UIManager; |
|
|
|
import static javax.swing.JOptionPane.showMessageDialog; |
|
|
|
|
|
|
|
public class MeinGui extends JFrame implements ActionListener, KeyListener { |
|
|
|
|
|
|
|
//Variablen Initialisierung |
|
|
|
private JPanel contentPane; |
|
|
|
public static JTextField text1; |
|
|
|
public static JTextField text2; |
|
|
|
JLabel labelBudgetImage; |
|
|
|
JLabel labelExpensesImage; |
|
|
|
JLabel labelBalancetImage; |
|
|
|
JLabel labelSavingsImage; |
|
|
|
JLabel labelHauptImage; |
|
|
|
JButton senden; |
|
|
|
JButton berechne; |
|
|
|
JLabel leeren; |
|
|
|
JButton loeschen; |
|
|
|
JButton exit; |
|
|
|
JButton hinzufuegen; |
|
|
|
JButton erspartesLoeschen; |
|
|
|
public static JLabel budgetDispaly; |
|
|
|
public static JLabel expensesDisplay; |
|
|
|
public static JLabel balanceDisplay; |
|
|
|
public static JLabel savingsDisplay; |
|
|
|
public static double budget; |
|
|
|
public static double expenses; |
|
|
|
public static double balance; |
|
|
|
public static double erspartes; |
|
|
|
public static JTextField textExpensesName; |
|
|
|
public static JLabel ausgabenName; |
|
|
|
private static JLabel ausgabenBetrag; |
|
|
|
private static JLabel budgetBetrag; |
|
|
|
private static JTable myTable; |
|
|
|
|
|
|
|
|
|
|
|
public MeinGui() { |
|
|
|
|
|
|
|
//Erstellen der GUI |
|
|
|
setTitle("Budget"); |
|
|
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); |
|
|
|
setBounds(100, 100, 654, 368); |
|
|
|
setBounds(100, 100, 900, 368); |
|
|
|
contentPane = new JPanel(); |
|
|
|
contentPane.setBackground(Color.orange); |
|
|
|
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); |
|
|
|
setContentPane(contentPane); |
|
|
|
contentPane.setLayout(null); |
|
|
|
|
|
|
|
//"Berechne" Button wird erstellt und hinzugefügt |
|
|
|
this.berechne = new JButton("Berechne"); |
|
|
|
berechne.setBounds(78, 281, 110, 23); |
|
|
|
berechne.setToolTipText(""); |
|
|
|
contentPane.add(berechne); |
|
|
|
|
|
|
|
//"Senden" Button wird erstellt und hinzugefügt |
|
|
|
this.senden = new JButton("Senden"); |
|
|
|
senden.setBounds(78, 126, 110, 23); |
|
|
|
contentPane.add(senden); |
|
|
|
|
|
|
|
|
|
|
|
//Textfeld für das Budget wird erstellt und hinzugefügt |
|
|
|
text1 = new JTextField(); |
|
|
|
text1.setBounds(60, 97, 128, 20); |
|
|
|
contentPane.add(text1); |
|
|
|
text1.setColumns(10); |
|
|
|
|
|
|
|
//Textfeld für die Ausgaben wird erstellt und hinzugefügt |
|
|
|
text2 = new JTextField(); |
|
|
|
text2.setBounds(60, 250, 128, 20); |
|
|
|
contentPane.add(text2); |
|
|
|
text2.setColumns(10); |
|
|
|
|
|
|
|
//Logo der Applikation wird hinzugefügt |
|
|
|
labelHauptImage = new JLabel(""); |
|
|
|
labelHauptImage.setBounds(10, 0, 86, 61); |
|
|
|
Image image0 = new ImageIcon(this.getClass().getResource("/budgetapp.png")).getImage(); |
|
|
|
labelHauptImage.setIcon(new ImageIcon(image0)); |
|
|
|
|
|
|
|
labelHauptImage.setFont(new Font("Tahoma", Font.BOLD, 13)); |
|
|
|
contentPane.add(labelHauptImage); |
|
|
|
|
|
|
|
//Einfügen der Textbeschreibung für das Eingabefeld "Budget" |
|
|
|
JLabel budgetEingeben = new JLabel("Budget eingeben"); |
|
|
|
budgetEingeben.setBounds(10, 72, 110, 20); |
|
|
|
budgetEingeben.setBounds(10, 72, 130, 20); |
|
|
|
budgetEingeben.setFont(new Font("Estrangelo Edessa", Font.BOLD, 14)); |
|
|
|
contentPane.add(budgetEingeben); |
|
|
|
|
|
|
|
//Einfügen der "Budget" Überschrift für die Berechnungstabelle |
|
|
|
JLabel labelBudget = new JLabel("Budget"); |
|
|
|
labelBudget.setBounds(255, 8, 46, 14); |
|
|
|
contentPane.add(labelBudget); |
|
|
|
|
|
|
|
//Einfügen der "Ausgaben" Überschrift für die Berechnungstabelle |
|
|
|
JLabel labelExpenses = new JLabel("Expenses"); |
|
|
|
labelExpenses.setBounds(390, 8, 56, 14); |
|
|
|
contentPane.add(labelExpenses); |
|
|
|
|
|
|
|
//Einfügen der "Restbudget" Überschrift für die Berechnungstabelle |
|
|
|
JLabel labelBalance = new JLabel("Balance"); |
|
|
|
labelBalance.setBounds(543, 8, 46, 14); |
|
|
|
labelBalance.setBounds(525, 8, 46, 14); |
|
|
|
contentPane.add(labelBalance); |
|
|
|
|
|
|
|
//Einfügen der "Erspartes" Überschrift für die Berechnungstabelle |
|
|
|
JLabel labelSavings = new JLabel("Savings"); |
|
|
|
labelSavings.setBounds(660, 8, 46, 14); |
|
|
|
contentPane.add(labelSavings); |
|
|
|
|
|
|
|
//Einfügen des Images für "Budget" in der Tabelle |
|
|
|
labelBudgetImage = new JLabel(""); |
|
|
|
labelBudgetImage.setBounds(255, 22, 46, 55); |
|
|
|
Image image1 = new ImageIcon(this.getClass().getResource("/money.png")).getImage(); |
|
|
|
labelBudgetImage.setIcon(new ImageIcon(image1)); |
|
|
|
contentPane.add(labelBudgetImage); |
|
|
|
|
|
|
|
//Einfügen des Images für "Ausgaben" in der Tabelle |
|
|
|
labelExpensesImage = new JLabel(""); |
|
|
|
labelExpensesImage.setBounds(400, 22, 46, 55); |
|
|
|
Image image2 = new ImageIcon(this.getClass().getResource("/wings-icon.png")).getImage(); |
|
|
|
labelExpensesImage.setIcon(new ImageIcon(image2)); |
|
|
|
contentPane.add(labelExpensesImage); |
|
|
|
|
|
|
|
|
|
|
|
//Einfügen des Images für "Restbudget" in der Tabelle |
|
|
|
labelBalancetImage = new JLabel("New labelBalance"); |
|
|
|
labelBalancetImage.setBounds(543, 22, 34, 55); |
|
|
|
Image image3 = new ImageIcon(this.getClass().getResource("/Money-icon.png")).getImage(); |
|
|
|
labelBalancetImage.setIcon(new ImageIcon(image3)); |
|
|
|
contentPane.add(labelBalancetImage); |
|
|
|
|
|
|
|
|
|
|
|
//Einfügen des Images für "Erspartes" in der Tabelle |
|
|
|
labelSavingsImage = new JLabel(""); |
|
|
|
labelSavingsImage.setBounds(660, 22, 46, 55); |
|
|
|
Image image4 = new ImageIcon(this.getClass().getResource("/savings-icon.png")).getImage(); |
|
|
|
labelSavingsImage.setIcon(new ImageIcon(image4)); |
|
|
|
contentPane.add(labelSavingsImage); |
|
|
|
|
|
|
|
//Einfügen der Überschrift "Ausgaben" für das Textfeld Ausgaben |
|
|
|
JLabel budgetAusgeben = new JLabel("Ausgaben"); |
|
|
|
budgetAusgeben.setBounds(10, 185, 63, 14); |
|
|
|
budgetAusgeben.setBounds(10, 185, 80, 20); |
|
|
|
budgetAusgeben.setFont(new Font("Estrangelo Edessa", Font.BOLD, 14)); |
|
|
|
contentPane.add(budgetAusgeben); |
|
|
|
|
|
|
|
//Einfügen der Überschrift "Leeren" für den löschen Button |
|
|
|
this.leeren = new JLabel("Leeren"); |
|
|
|
leeren.setBounds(317, 253, 115, 14); |
|
|
|
leeren.setFont(new Font("Estrangelo Edessa", Font.BOLD, 14)); |
|
|
|
contentPane.add(leeren); |
|
|
|
|
|
|
|
//Einfügen und hinzufügen des "Löschen" Buttons |
|
|
|
this.loeschen = new JButton("L\u00F6schen"); |
|
|
|
loeschen.setBounds(301, 281, 89, 23); |
|
|
|
contentPane.add(loeschen); |
|
|
|
|
|
|
|
//Einfügen und hinzufügen des "Exit" Buttons |
|
|
|
this.exit = new JButton("Exit\r\n"); |
|
|
|
exit.setBounds(477, 281, 95, 23); |
|
|
|
contentPane.add(exit); |
|
|
|
|
|
|
|
JLabel beendne = new JLabel("Beenden"); |
|
|
|
beendne.setBounds(491, 253, 81, 14); |
|
|
|
beendne.setFont(new Font("Estrangelo Edessa", Font.BOLD, 14)); |
|
|
|
contentPane.add(beendne); |
|
|
|
//Einfügen der Überschrift "Beenden" über dem "exit" Button |
|
|
|
JLabel beenden = new JLabel("Beenden"); |
|
|
|
beenden.setBounds(491, 253, 81, 14); |
|
|
|
beenden.setFont(new Font("Estrangelo Edessa", Font.BOLD, 14)); |
|
|
|
contentPane.add(beenden); |
|
|
|
|
|
|
|
//Einfügen des Platzhalters für die Budget Summe |
|
|
|
budgetDispaly = new JLabel("0.0 \u20AC"); |
|
|
|
budgetDispaly.setBounds(255, 82, 86, 14); |
|
|
|
budgetDispaly.setFont(new Font("Tahoma", Font.BOLD, 12)); |
|
|
|
contentPane.add(budgetDispaly); |
|
|
|
|
|
|
|
//Einfügen des Platzhalters für die Asugaben Summe |
|
|
|
expensesDisplay = new JLabel("0.0 \u20AC"); |
|
|
|
expensesDisplay.setBounds(390, 82, 110, 14); |
|
|
|
expensesDisplay.setFont(new Font("Tahoma", Font.BOLD, 12)); |
|
|
|
contentPane.add(expensesDisplay); |
|
|
|
|
|
|
|
//Einfügen des Platzhalters für die Restbudget Differenz |
|
|
|
balanceDisplay = new JLabel("0.0 \u20AC"); |
|
|
|
balanceDisplay.setBounds(543, 82, 85, 14); |
|
|
|
balanceDisplay.setFont(new Font("Tahoma", Font.BOLD, 12)); |
|
|
|
contentPane.add(balanceDisplay); |
|
|
|
|
|
|
|
|
|
|
|
//Einfügen des Platzhalters für die Erspartes Summe |
|
|
|
savingsDisplay = new JLabel("0.0 \u20AC"); |
|
|
|
savingsDisplay.setBounds(660, 82, 85, 14); |
|
|
|
savingsDisplay.setFont(new Font("Tahoma", Font.BOLD, 12)); |
|
|
|
contentPane.add(savingsDisplay); |
|
|
|
|
|
|
|
//Einfügen und hinzufügen des "Hinzufügen" Buttons |
|
|
|
this.hinzufuegen = new JButton("Hinzuf\u00fcgen"); |
|
|
|
hinzufuegen.setBounds(660, 126, 100, 23); |
|
|
|
contentPane.add(hinzufuegen); |
|
|
|
|
|
|
|
//Einfügen und hinzufügen des "Erspartes löschen" Buttons |
|
|
|
this.erspartesLoeschen = new JButton("Erspartes L\u00F6schen"); |
|
|
|
erspartesLoeschen.setBounds(660, 160, 150, 23); |
|
|
|
contentPane.add(erspartesLoeschen); |
|
|
|
|
|
|
|
//Einfügen des Textfeldes für die Beschreibung der Ausgabe |
|
|
|
textExpensesName = new JTextField(); |
|
|
|
textExpensesName.setBounds(60, 221, 128, 20); |
|
|
|
textExpensesName.setToolTipText(""); |
|
|
|
contentPane.add(textExpensesName); |
|
|
|
textExpensesName.setColumns(10); |
|
|
|
|
|
|
|
//Einfügen der Überschrifft für das Textfeld der Ausgaben Beschreibung |
|
|
|
ausgabenName = new JLabel(" Name"); |
|
|
|
ausgabenName.setBounds(10, 224, 46, 14); |
|
|
|
contentPane.add(ausgabenName); |
|
|
|
|
|
|
|
//Einfügen der Überschrift für das Textfeld des Ausgabenbetrages |
|
|
|
ausgabenBetrag = new JLabel(" Betrag"); |
|
|
|
ausgabenBetrag.setBounds(10, 253, 46, 14); |
|
|
|
contentPane.add(ausgabenBetrag); |
|
|
|
|
|
|
|
//Einfügen der Überschrift für das Textfeld des Budgetbetrages |
|
|
|
budgetBetrag = new JLabel(" Betrag"); |
|
|
|
budgetBetrag.setBounds(10, 100, 46, 14); |
|
|
|
contentPane.add(budgetBetrag); |
|
|
|
|
|
|
|
//Einfügen einer Scrollleiste |
|
|
|
JScrollPane scrollPane_1 = new JScrollPane(); |
|
|
|
scrollPane_1.setBounds(347, 126, 136, 88); |
|
|
|
contentPane.add(scrollPane_1); |
|
|
|
|
|
|
|
//Einfügen der Tabelle für die Ausgaben |
|
|
|
myTable = new JTable(); |
|
|
|
myTable.setColumnSelectionAllowed(true); |
|
|
|
myTable.setCellSelectionEnabled(true); |
|
|
@ -209,6 +272,7 @@ public class MeinGui extends JFrame implements ActionListener, KeyListener { |
|
|
|
}); |
|
|
|
scrollPane_1.setViewportView(myTable); |
|
|
|
|
|
|
|
//Einfügen der Actionlistener für die verschiedenen Buttons und Textfelder |
|
|
|
text1.addActionListener(this); |
|
|
|
text1.addKeyListener(this); |
|
|
|
text2.addActionListener(this); |
|
|
@ -220,36 +284,84 @@ public class MeinGui extends JFrame implements ActionListener, KeyListener { |
|
|
|
loeschen.addActionListener(this); |
|
|
|
loeschen.addKeyListener(this); |
|
|
|
exit.addActionListener(this); |
|
|
|
<<<<<<< HEAD |
|
|
|
exit.addKeyListener(this); |
|
|
|
======= |
|
|
|
hinzufuegen.addActionListener(this); |
|
|
|
erspartesLoeschen.addActionListener(this); |
|
|
|
>>>>>>> e9471140ef0f8da1cd53473243a925d48bd272c1 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public void actionPerformed(ActionEvent ae) { |
|
|
|
|
|
|
|
|
|
|
|
if (ae.getSource() == this.exit) { |
|
|
|
exitButton(); |
|
|
|
} |
|
|
|
if (ae.getSource() == this.loeschen) { |
|
|
|
|
|
|
|
else if (ae.getSource() == this.loeschen) { |
|
|
|
leeren(); |
|
|
|
} |
|
|
|
|
|
|
|
else if(ae.getSource() == this.erspartesLoeschen) { |
|
|
|
loescheErspartes(); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
budget = Double.parseDouble(text1.getText()); |
|
|
|
if (ae.getSource() == this.senden && (text1 != null && text2 != null)) { |
|
|
|
|
|
|
|
else if (ae.getSource() == this.senden && (text1 != null && text2 != null)) { |
|
|
|
try { |
|
|
|
budget = Double.parseDouble(text1.getText()); |
|
|
|
} |
|
|
|
catch (Exception e) { |
|
|
|
showMessageDialog(null, "Sie müssen ihr Budget eingeben!"); |
|
|
|
} |
|
|
|
budgetDispaly.setText(setBudgetView()); |
|
|
|
} |
|
|
|
|
|
|
|
if (ae.getSource() == this.berechne && (text1 != null && text2 != null)) { |
|
|
|
DefaultTableModel tab = (DefaultTableModel) myTable.getModel(); |
|
|
|
tab.addRow(new Object[] { (textExpensesName.getText()), Double.parseDouble(text2.getText()) }); |
|
|
|
else if (ae.getSource() == this.berechne && (text1 != null && text2 != null)) { |
|
|
|
try { |
|
|
|
DefaultTableModel tab = (DefaultTableModel) myTable.getModel(); |
|
|
|
tab.addRow(new Object[] { (textExpensesName.getText()), Double.parseDouble(text2.getText()) }); |
|
|
|
|
|
|
|
balance -= Double.parseDouble(text2.getText()); |
|
|
|
expenses += Double.parseDouble(text2.getText()); |
|
|
|
expensesDisplay.setText(setExpensesView()); |
|
|
|
balanceDisplay.setText(setBalanceView()); |
|
|
|
} |
|
|
|
catch (Exception e) { |
|
|
|
showMessageDialog(null, "Sie müssen ihre Ausgabe eingeben!"); |
|
|
|
} |
|
|
|
|
|
|
|
balance -= Double.parseDouble(text2.getText()); |
|
|
|
expenses += Double.parseDouble(text2.getText()); |
|
|
|
expensesDisplay.setText(setExpensesView()); |
|
|
|
balanceDisplay.setText(setBalanceView()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (ae.getSource() == this.hinzufuegen) { |
|
|
|
erspartesHinzufuegen(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void loescheErspartes() { |
|
|
|
erspartes = 0.0; |
|
|
|
savingsDisplay.setText("0.0 \u20AC"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
private void erspartesHinzufuegen() { |
|
|
|
erspartes += (budget - expenses); |
|
|
|
budget = 0.0; |
|
|
|
expenses = 0.0; |
|
|
|
balance = 0.0; |
|
|
|
text1.setText(null); |
|
|
|
text2.setText(null); |
|
|
|
budgetDispaly.setText("0.0 \u20AC"); |
|
|
|
expensesDisplay.setText("0.0 \u20AC"); |
|
|
|
balanceDisplay.setText("0.0 \u20AC"); |
|
|
|
savingsDisplay.setText(Double.toString(erspartes) + " \u20AC"); |
|
|
|
textExpensesName.setText(null); |
|
|
|
((DefaultTableModel) myTable.getModel()).setRowCount(0); |
|
|
|
} |
|
|
|
|
|
|
|
public static void exitButton() { |
|
|
@ -257,27 +369,39 @@ public class MeinGui extends JFrame implements ActionListener, KeyListener { |
|
|
|
} |
|
|
|
|
|
|
|
public static void leeren() { |
|
|
|
<<<<<<< HEAD |
|
|
|
text1.setText(""); |
|
|
|
text2.setText(""); |
|
|
|
budgetDispaly.setText("0.0 €"); |
|
|
|
expensesDisplay.setText("0.0 €"); |
|
|
|
balanceDisplay.setText("0.0 €"); |
|
|
|
textExpensesName.setText(""); |
|
|
|
======= |
|
|
|
budget = 0.0; |
|
|
|
expenses = 0.0; |
|
|
|
balance = 0.0; |
|
|
|
text1.setText(null); |
|
|
|
text2.setText(null); |
|
|
|
budgetDispaly.setText("0.0 \u20AC"); |
|
|
|
expensesDisplay.setText("0.0 \u20AC"); |
|
|
|
balanceDisplay.setText("0.0 \u20AC"); |
|
|
|
textExpensesName.setText(null); |
|
|
|
>>>>>>> e9471140ef0f8da1cd53473243a925d48bd272c1 |
|
|
|
((DefaultTableModel) myTable.getModel()).setRowCount(0); |
|
|
|
} |
|
|
|
|
|
|
|
public static String setBudgetView() { |
|
|
|
String result = budget + " €"; |
|
|
|
String result = budget + " �"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static String setBalanceView() { |
|
|
|
String result = budget - expenses + " €"; |
|
|
|
String result = budget - expenses + " �"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|
public static String setExpensesView() { |
|
|
|
String result = "-" + expenses + " €"; |
|
|
|
String result = "-" + expenses + " �"; |
|
|
|
return result; |
|
|
|
} |
|
|
|
|
|
|
|