Untitled
unknown
java
a year ago
14 kB
6
Indexable
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package itpf.cs;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.border.TitledBorder;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
public class ITPFCS {
private static JFrame frame;
private static JTextField maintenanceCostField;
private static DefaultListModel<String> historyListModel;
public static void main(String[] args) {
showStartMenu();
}
private static void showStartMenu() {
// Create the frame for the Start Menu
frame = new JFrame("CALAMANSI FARM SYSTEM");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800, 600); // Increased the size of the frame
frame.setLayout(new BorderLayout());
// Welcome panel
JPanel welcomePanel = new JPanel();
welcomePanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(10, 0, 10, 0);
JLabel welcomeLabel = new JLabel("Welcome", SwingConstants.CENTER);
welcomeLabel.setFont(new Font("Arial", Font.BOLD, 20));
welcomePanel.add(welcomeLabel, gbc);
gbc.gridy++;
JLabel toLabel = new JLabel("to", SwingConstants.CENTER);
toLabel.setFont(new Font("Arial", Font.BOLD, 20));
welcomePanel.add(toLabel, gbc);
gbc.gridy++;
JLabel systemLabel = new JLabel("Calamansi Farm System", SwingConstants.CENTER);
systemLabel.setFont(new Font("Arial", Font.BOLD, 20));
welcomePanel.add(systemLabel, gbc);
frame.add(welcomePanel, BorderLayout.CENTER);
// Main Menu Panel
JPanel mainMenuPanel = new JPanel();
JButton startButton = new JButton("Start");
JButton exitButton = new JButton("Exit");
startButton.setPreferredSize(new Dimension(250, 50));
exitButton.setPreferredSize(new Dimension(250, 50));
mainMenuPanel.add(startButton);
mainMenuPanel.add(exitButton);
frame.add(mainMenuPanel, BorderLayout.SOUTH);
// Start button action
startButton.addActionListener(e -> showCalamansiFarm());
// Exit button action
exitButton.addActionListener(e -> System.exit(0));
frame.setVisible(true);
}
private static void showCalamansiFarm() {
frame.getContentPane().removeAll();
frame.setLayout(new BorderLayout());
// Welcome panel
JPanel welcomePanel = new JPanel();
welcomePanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 0;
gbc.insets = new Insets(10, 0, 10, 0);
JLabel welcomeLabel = new JLabel("Welcome", SwingConstants.CENTER);
welcomeLabel.setFont(new Font("Arial", Font.BOLD, 20));
welcomePanel.add(welcomeLabel, gbc);
gbc.gridy++;
JLabel toLabel = new JLabel("to", SwingConstants.CENTER);
toLabel.setFont(new Font("Arial", Font.BOLD, 20));
welcomePanel.add(toLabel, gbc);
gbc.gridy++;
JLabel systemLabel = new JLabel("Calamansi Farm System", SwingConstants.CENTER);
systemLabel.setFont(new Font("Arial", Font.BOLD, 20));
welcomePanel.add(systemLabel, gbc);
frame.add(welcomePanel, BorderLayout.CENTER);
// Main Menu Panel
JPanel mainMenuPanel = new JPanel();
JButton exitButton = new JButton("Exit");
exitButton.setPreferredSize(new Dimension(250, 50));
mainMenuPanel.add(exitButton);
frame.add(mainMenuPanel, BorderLayout.SOUTH);
// Tabbed Pane for Maintenance, Harvest, and History sections
JTabbedPane tabbedPane = new JTabbedPane();
frame.add(tabbedPane, BorderLayout.CENTER);
// Centering the panels
GridBagConstraints gbcTab = new GridBagConstraints();
gbcTab.gridx = 0;
gbcTab.gridy = 0;
gbcTab.weightx = 1;
gbcTab.weighty = 1;
gbcTab.anchor = GridBagConstraints.CENTER;
gbcTab.fill = GridBagConstraints.NONE;
// Maintenance Tab
JPanel maintenanceContainer = createSectionContainer("Maintenance", new Color(255, 240, 220));
JPanel maintenancePanel = createMaintenancePanel();
maintenanceContainer.setPreferredSize(new Dimension(600, 400)); // Increased the size of the container
maintenanceContainer.add(maintenancePanel);
JPanel maintenanceWrapper = new JPanel(new GridBagLayout());
maintenanceWrapper.add(maintenanceContainer, gbcTab);
tabbedPane.addTab("MAINTENANCE", maintenanceWrapper);
// Harvest Tab
JPanel harvestContainer = createSectionContainer("Harvest", new Color(220, 255, 220));
JPanel harvestPanel = createHarvestPanel();
harvestContainer.setPreferredSize(new Dimension(600, 400)); // Increased the size of the container
harvestContainer.add(harvestPanel);
JPanel harvestWrapper = new JPanel(new GridBagLayout());
harvestWrapper.add(harvestContainer, gbcTab);
tabbedPane.addTab("HARVEST", harvestWrapper);
// History Tab
JPanel historyContainer = createSectionContainer("History", new Color(220, 220, 255));
JPanel historyPanel = createHistoryPanel();
historyContainer.setPreferredSize(new Dimension(600, 400)); // Increased the size of the container
historyContainer.add(historyPanel);
JPanel historyWrapper = new JPanel(new GridBagLayout());
historyWrapper.add(historyContainer, gbcTab);
tabbedPane.addTab("HISTORY", historyWrapper);
// Exit button action
exitButton.addActionListener(e -> System.exit(0));
frame.revalidate();
frame.repaint();
}
private static JPanel createMaintenancePanel() {
JPanel maintenancePanel = new JPanel();
maintenancePanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(5, 5, 5, 5);
// Fields and labels
String[] labels = {"Date:", "Irrigation Cost:", "Fertilizer:", "Pesticide:", "Gas:", "Grass Cutting:"};
JTextField[] fields = {new JTextField(10), new JTextField(6), new JTextField(6), new JTextField(6), new JTextField(6), new JTextField(6)};
for (int i = 0; i < labels.length; i++) {
JLabel label = new JLabel(labels[i]);
label.setFont(new Font("Arial", Font.PLAIN, 16));
fields[i].setFont(new Font("Arial", Font.PLAIN, 16));
gbc.gridx = 0;
gbc.gridy = i;
maintenancePanel.add(createFieldPanel(label, fields[i]), gbc);
}
// Add Compute and Reset buttons
JPanel buttonPanel = new JPanel();
JButton computeButton = new JButton("Compute");
JButton resetButton = new JButton("Reset");
buttonPanel.add(computeButton);
buttonPanel.add(resetButton);
gbc.gridy++;
gbc.anchor = GridBagConstraints.CENTER;
maintenancePanel.add(buttonPanel, gbc);
// Compute button action
computeButton.addActionListener(e -> {
String date = fields[0].getText();
double irrigationCost = Double.parseDouble(fields[1].getText());
double fertilizerCost = Double.parseDouble(fields[2].getText());
double pesticideCost = Double.parseDouble(fields[3].getText());
double gasCost = Double.parseDouble(fields[4].getText());
double grassCuttingCost = Double.parseDouble(fields[5].getText());
double totalMaintenanceCost = irrigationCost + fertilizerCost + pesticideCost + gasCost + grassCuttingCost;
maintenanceCostField.setText(String.valueOf(totalMaintenanceCost));
String receipt = "Maintenance Receipt:\n" +
"---------------------------------\n" +
"Date: " + date + "\n" +
"Irrigation Cost: " + irrigationCost + "\n" +
"Fertilizer Cost: " + fertilizerCost + "\n" +
"Pesticide Cost: " + pesticideCost + "\n" +
"Gas Cost: " + gasCost + "\n" +
"Grass Cutting Cost: " + grassCuttingCost + "\n" +
"---------------------------------\n" +
"Total Maintenance Cost: " + totalMaintenanceCost + "\n" +
"---------------------------------";
JOptionPane.showMessageDialog(null, receipt);
// Save to history
historyListModel.addElement("Maintenance - Date: " + date + ", Total Maintenance Cost: " + totalMaintenanceCost);
});
// Reset button action
resetButton.addActionListener(e -> {
for (JTextField field : fields) {
field.setText("");
}
});
return maintenancePanel;
}
private static JPanel createHarvestPanel() {
JPanel harvestPanel = new JPanel();
harvestPanel.setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.anchor = GridBagConstraints.LINE_END;
gbc.insets = new Insets(5, 5, 5, 5);
// Fields and labels
String[] labels = {"Date:", "Price of Good Calamansi:", "Price of Reject Calamansi:", "Quantity of Good Calamansi:", "Quantity of Reject Calamansi:", "Salary of Farmers:", "Maintenance Cost:"};
JTextField[] fields = {new JTextField(10), new JTextField(8), new JTextField(8), new JTextField(8), new JTextField(8), new JTextField(8), maintenanceCostField = new JTextField(8)};
for (int i = 0; i < labels.length; i++) {
JLabel label = new JLabel(labels[i]);
label.setFont(new Font("Arial", Font.PLAIN, 16));
fields[i].setFont(new Font("Arial", Font.PLAIN, 16));
gbc.gridx = 0;
gbc.gridy = i;
harvestPanel.add(createFieldPanel(label, fields[i]), gbc);
}
// Add Compute and Reset buttons
JPanel buttonPanel = new JPanel();
JButton computeButton = new JButton("Compute");
JButton resetButton = new JButton("Reset");
buttonPanel.add(computeButton);
buttonPanel.add(resetButton);
gbc.gridy++;
gbc.anchor = GridBagConstraints.CENTER;
harvestPanel.add(buttonPanel, gbc);
// Compute button action
computeButton.addActionListener(e -> {
String date = fields[0].getText();
double priceGood = Double.parseDouble(fields[1].getText());
double priceReject = Double.parseDouble(fields[2].getText());
double qtyGood = Double.parseDouble(fields[3].getText());
double qtyReject = Double.parseDouble(fields[4].getText());
double salary = Double.parseDouble(fields[5].getText());
double maintenanceCost = Double.parseDouble(fields[6].getText());
double totalPriceGood = priceGood * qtyGood;
double totalPriceReject = priceReject * qtyReject;
double totalHarvestValue = totalPriceGood + totalPriceReject - salary - maintenanceCost;
String receipt = "Harvest Receipt:\n" +
"---------------------------------\n" +
"Date: " + date + "\n" +
"Total Price of Good Calamansi: " + totalPriceGood + "\n" +
"Total Price of Reject Calamansi: " + totalPriceReject + "\n" +
"Total Salary of Farmers: " + salary + "\n" +
"Maintenance Cost: " + maintenanceCost + "\n" +
"---------------------------------\n" +
"Total Harvest Value (after salary and maintenance deduction): " + totalHarvestValue + "\n" +
"---------------------------------";
JOptionPane.showMessageDialog(null, receipt);
// Save to history
historyListModel.addElement("Harvest - Date: " + date + ", Total Harvest Value: " + totalHarvestValue);
});
// Reset button action
resetButton.addActionListener(e -> {
for (JTextField field : fields) {
field.setText("");
}
});
return harvestPanel;
}
private static JPanel createHistoryPanel() {
JPanel historyPanel = new JPanel(new BorderLayout());
historyListModel = new DefaultListModel<>();
JList<String> historyList = new JList<>(historyListModel);
JScrollPane scrollPane = new JScrollPane(historyList);
historyPanel.add(scrollPane, BorderLayout.CENTER);
return historyPanel;
}
private static JPanel createFieldPanel(JLabel label, JTextField field) {
JPanel panel = new JPanel();
panel.setLayout(new FlowLayout(FlowLayout.LEFT));
panel.add(label);
panel.add(field);
return panel;
}
private static JPanel createSectionContainer(String title, Color color) {
JPanel container = new JPanel();
container.setLayout(new BorderLayout());
container.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createLineBorder(Color.BLACK),
title, TitledBorder.LEFT, TitledBorder.TOP));
container.setBackground(color);
return container;
}
}
Editor is loading...
Leave a Comment