-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewExpenses.java
More file actions
54 lines (46 loc) · 1.37 KB
/
ViewExpenses.java
File metadata and controls
54 lines (46 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.util.ArrayList;
public class ViewExpenses implements ActionListener {
JFrame frame = new JFrame("Expense Manager");
JPanel panel = new JPanel();
JButton addBtn = new JButton("Add New");
JTable expenseTable;
public ViewExpenses(){
frame.setSize(350,180);
frame.setLocation(500,280);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
panel.setLayout(null);
addBtn.setBounds(10,20,90,25);
panel.add(addBtn);
frame.getContentPane().add(panel);
addBtn.addActionListener(this);
}
public static void main(String[] args){
new ViewExpenses();
}
public void actionPerformed(ActionEvent e) {
if (e.getSource() == addBtn) {
new MyExpenses();
frame.dispose();
}
}
public void showExpenses(ArrayList<Expense> expenses){
String[] columns = new String[] {
"Description", "Amount"
};
DefaultTableModel tableModel = new DefaultTableModel(columns, 0);
for(Expense e : expenses){
Float amt = e.getAmount();
String dsc = e.getDescription();
Object[] data = { dsc, amt };
tableModel.add(data);
}
expenseTable = new JTable(tableModel);
panel.add(expenseTable);
frame.getContentPane().add(panel);
frame.setVisible(true);
}
}