-
Notifications
You must be signed in to change notification settings - Fork 0
/
ViewCart.java
97 lines (86 loc) · 2.2 KB
/
ViewCart.java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import javax.swing.table.*;
import javax.swing.*;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.*;
import java.util.*;
import java.io.*;
public class ViewCart extends JFrame implements ActionListener{
String[] data = new String[3];
String[] columnNames = { "ProductName", "Cost" };
JTable j;
JPanel panel1;
JScrollPane sp ;
JTextField tf;
JButton b;
JButton b1;
JPanel panel2;
JLabel lb;
DefaultTableModel dtm = new DefaultTableModel(null,columnNames);
ViewCart(){
super();
}
ViewCart(String S){
super(S);
try {
j = new JTable(dtm);
File file = new File("/home/gautham/Desktop/OopMaster/products.txt");
int price=0;
Scanner input = new Scanner(file);
while (input.hasNextLine()) {
data= input.nextLine().split(",");
dtm.addRow(data);
price+=Integer.parseInt(data[1]);
}
input.close();
tf = new JTextField(Integer.toString(price));
b=new JButton("CheckOut");
b1=new JButton("Go Back");
panel1=new JPanel(new BorderLayout(10,5));
panel2=new JPanel();
b.addActionListener(this);
b1.addActionListener(this);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addAll();
}
catch(Exception f){
JOptionPane.showMessageDialog(null, f);
}
}
private void addAll() {
j.setPreferredScrollableViewportSize(new Dimension(500, 150));
sp=new JScrollPane(j);
panel1.add(sp, BorderLayout.CENTER);
panel1.add(tf,BorderLayout.SOUTH);
b.setFont(new Font("Ariel",Font.ITALIC,18));
b.setBackground(Color.LIGHT_GRAY);
b.setForeground(Color.BLUE);
b1.setFont(new Font("Ariel",Font.ITALIC,18));
b1.setForeground(Color.BLUE);
b1.setBackground(Color.LIGHT_GRAY);
panel2.add(panel1);
panel2.add(b);
panel2.add(b1);
tf.setBackground(Color.WHITE);
tf.setEditable(false);
j.setEnabled(false);
getContentPane().add(panel2);
setVisible(true);
validate();
pack();
setSize(700,400);
setLocationRelativeTo(null);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource()==b1) {
this.dispose();
new Secondpage("Shop-E");
}
else if(e.getSource()==b){
dispose();
new order();
}
}
}