BillingSystemMAin
BillingSystemMAin
java
package billing;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.io.File;
// Sample login credentials (you can change or load them from a file/database)
private static final String USERNAME = "admin";
private static final String PASSWORD = "password";
public BillingSystemMain() {
setTitle("Enhanced Billing System");
setSize(600, 400);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(new BorderLayout());
// Input panel
JPanel inputPanel = new JPanel(new GridLayout(5, 2));
inputPanel.add(new JLabel("Quantity:"));
quantityField = new JTextField();
inputPanel.add(quantityField);
inputPanel.add(new JLabel("Price:"));
priceField = new JTextField();
inputPanel.add(priceField);
add(inputPanel, BorderLayout.NORTH);
// Table panel
tableModel = new DefaultTableModel(new Object[]{"Name", "Quantity", "Price", "Image Path"}, 0);
productTable = new JTable(tableModel);
// Total panel
JPanel totalPanel = new JPanel(new BorderLayout());
add(totalPanel, BorderLayout.SOUTH);
setVisible(true);
}
try {
int quantity = Integer.parseInt(quantityText);
double price = Double.parseDouble(priceText);
// Store the image path instead of JLabel
Icon icon = productImageLabel.getIcon();
String imagePath = ((ImageIcon) icon).getDescription(); // Store the file path
} catch (NumberFormatException e) {
JOptionPane.showMessageDialog(this, "Quantity and Price must be valid numbers!", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
billFrame.setVisible(true);
}
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
LoginPage.java
package billing;
import javax.swing.*;
loginPanel.add(new JLabel("Username:"));
loginPanel.add(usernameField);
loginPanel.add(new JLabel("Password:"));
loginPanel.add(passwordField);
loginPanel.add(loginButton);
return loginPanel;
}
TableImageRender.java
package billing;
import javax.swing.*;
import javax.swing.table.TableCellRenderer;
import java.awt.*;
import java.io.File;
public TableImageRenderer() {
label = new JLabel();
label.setHorizontalAlignment(JLabel.CENTER);
// Load the placeholder image (Make sure "placeholder.png" is in your project folder or provide the
full path)
placeholder = new ImageIcon(new ImageIcon("placeholder.png").getImage().getScaledInstance(50,
50, Image.SCALE_SMOOTH));
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) {
if (value instanceof String) {
String imagePath = (String) value;
File file = new File(imagePath);
if (file.exists() && !file.isDirectory()) {
try {
ImageIcon icon = new ImageIcon(new
ImageIcon(imagePath).getImage().getScaledInstance(50, 50, Image.SCALE_SMOOTH));
label.setIcon(icon);
label.setText(null); // Clear text if the image is loaded successfully
} catch (Exception e) {
label.setIcon(placeholder); // Fallback to placeholder on error
label.setText(null);
}
} else {
label.setIcon(placeholder); // Fallback to placeholder for missing/invalid paths
label.setText(null);
}
} else {
label.setIcon(placeholder); // Fallback to placeholder for null or non-string values
label.setText(null);
}
return label;
}
}