0% found this document useful (0 votes)
4 views12 pages

A2. Java Programming Assignment Word

The Irrigation Schedule Manager is a Java Swing desktop application designed to help farmers manage irrigation schedules for various crops, allowing users to organize and manipulate irrigation data stored in a CSV file. The application features a user-friendly interface for adding, editing, deleting, and searching irrigation schedules, while also implementing robust exception handling and data validation. This project enhances programming skills in GUI development, file handling, and object-oriented design, demonstrating practical applications in agricultural management.

Uploaded by

balajirl0303
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views12 pages

A2. Java Programming Assignment Word

The Irrigation Schedule Manager is a Java Swing desktop application designed to help farmers manage irrigation schedules for various crops, allowing users to organize and manipulate irrigation data stored in a CSV file. The application features a user-friendly interface for adding, editing, deleting, and searching irrigation schedules, while also implementing robust exception handling and data validation. This project enhances programming skills in GUI development, file handling, and object-oriented design, demonstrating practical applications in agricultural management.

Uploaded by

balajirl0303
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Report on Java Swing–CSV Integration Application

Irrigation Schedule Manager – Manage irrigation timings and methods per crop.

Balaji R L
Student Name
128157006
Register Number
6
Roll Number:
[Link] Computer Science Engineering (Cyber Security & Blockchain
Department:
technology)
Java Programming
Course Name:
2nd Year & 3rd Semester
Year & Semester:

Abstract:
The Irrigation Schedule Manager is a desktop application developed using Java
Swing that helps farmers and agricultural managers plan and manage irrigation
schedules efficiently for different crops. The system allows users to organize
irrigation details such as crop name, irrigation method, start time, duration,
frequency, and water usage per hectare. All the data is stored in a CSV file, which
can be easily updated, viewed, and exported through the application’s user-
friendly interface. Users can add, edit, delete, and search for irrigation schedules,
as well as filter records based on irrigation methods such as drip, sprinkler, or
flood. The project demonstrates the use of Java Swing for graphical user interface
design, file handling for reading and writing schedule data, and exception
handling to ensure smooth operation. This application highlights the practical
integration of programming and agricultural management, enabling efficient
scheduling and water resource utilization. It also reinforces important
programming concepts such as object-oriented design, data validation, and
persistent storage management in Java.
Expected outcome or learning benefit Through this project:

I gained a deeper understanding of Java programming concepts, particularly in


GUI development using Swing, file handling, and data validation. Implementing
the Irrigation Schedule Manager helped me learn how to design interactive user
interfaces, manage data dynamically using tables, and perform operations such as
adding, editing, deleting, and searching records efficiently. I also learned how to
read and write data in CSV format, ensuring persistence and reliability in data
storage. Working on this application improved my ability to apply object-oriented
programming principles in a real-world scenario and strengthened my problem-
solving skills in areas like exception handling and user input validation. Overall,
the project enhanced my confidence in developing complete desktop applications
in Java and gave me practical insight into how programming can be applied to
real-life domains such as agriculture and resource management.

Overview of the chosen application:


Objectives:

 Design an interactive GUI using Java Swing.


 Load and display schedule data from a CSV file.
 Add, edit, delete schedule entries (CRUD).
 Implement robust exception handling for file operations and input validation.
 Provide search and filter features (by crop name and irrigation method).
 Save/export updated schedules to CSV.
 Use modular code and document the project

Dataset Details:
Data set Name: [Link]
Details:

Coding:
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
public class IrrigationScheduleManager extends JFrame {
static final String[] COLS =
{"Crop","Method","Start","Duration","Days","Water(L/ha)","Notes"};
DefaultTableModel model; JTable table;
JTextField searchF; JComboBox<String> methodF;
File file = new File("[Link]");

public IrrigationScheduleManager() {
super("Irrigation Schedule Manager");
setSize(850,500);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setLocationRelativeTo(null);

model = new DefaultTableModel(COLS,0){public boolean isCellEditable(int


r,int c){return false;}};
table = new JTable(model);
add(new JScrollPane(table));

JPanel p = new JPanel(new FlowLayout());


JButton importBtn = new JButton("Import CSV");
JButton saveBtn = new JButton("Save CSV");
JButton addB = new JButton("Add");
JButton edit = new JButton("Edit");
JButton del = new JButton("Delete");
JButton search = new JButton("Search");
JButton filter = new JButton("Filter");
JButton clear = new JButton("Clear");

searchF = new JTextField(10);


methodF = new JComboBox<>(new String[]{"All","Drip","Sprinkler","Flood"});

[Link](importBtn); [Link](saveBtn); [Link](addB); [Link](edit); [Link](del);


[Link](new JLabel("Search:")); [Link](searchF); [Link](search);
[Link](new JLabel("Method:")); [Link](methodF); [Link](filter); [Link](clear);
add(p,[Link]);

JLabel status = new JLabel("Ready");


add(status,[Link]);

// Load default file if exists


if([Link]()) try{ loadCSV(); }catch(Exception e){ [Link]("Error
loading file"); }

// Import CSV Button


[Link](e->{
JFileChooser fc = new JFileChooser();
[Link](new [Link]("CSV
files","csv"));
if([Link](this)==JFileChooser.APPROVE_OPTION){
file = [Link]();
try{ loadCSV(); [Link]("Imported "+[Link]()); }
catch(Exception ex){ msg(ex); }
}
});

// Save CSV Button


[Link](e->{
try{ saveCSV(); [Link]("Saved to "+[Link]()); }
catch(Exception ex){ msg(ex); }
});

[Link](e->{ String[] r=form(null); if(r!=null)


[Link](r); });
[Link](e->{ int i=[Link](); if(i<0)return;
String[] r=form(getRow(i)); if(r!=null) for(int j=0;j<[Link];j++)
[Link](r[j],i,j); });
[Link](e->{ int i=[Link]();
if(i>=0)[Link](i); });

[Link](e->{
String key=[Link]().toLowerCase();
for(int i=0;i<[Link]();i++){
String c=[Link](i,0).toString().toLowerCase();
if([Link](key)){ [Link](i,i);
[Link]([Link](i,0,true)); break; }
}
});

[Link](e->{
String f=[Link]().toString();
if([Link]("All")){ try{ loadCSV(); }catch(Exception ex){ msg(ex); } return; }
DefaultTableModel m=new DefaultTableModel(COLS,0);
for(int i=0;i<[Link]();i++)
if([Link](i,1).equals(f)) [Link](getRow(i));
[Link](m); model=m;
});

[Link](e->{ try{ loadCSV(); }catch(Exception ex){ msg(ex); }});

[Link](new MouseAdapter(){
public void mouseClicked(MouseEvent e){ if([Link]()==2)
[Link](); }
});
}

void loadCSV() throws IOException {


[Link](0);
for(String line:[Link]([Link]())){
if([Link]().isEmpty()||[Link]("crop")) continue;
[Link]([Link](","));
}
}

void saveCSV() throws IOException {


try(BufferedWriter bw=[Link]([Link]())){
[Link]([Link](",",COLS)); [Link]();
for(int i=0;i<[Link]();i++){
[Link]<String> r=new ArrayList<>();
for(int j=0;j<[Link];j++)
[Link]([Link](i,j).toString());
[Link]([Link](",",r)); [Link]();
}
}
}

String[] getRow(int r){


String[] a=new String[[Link]];
for(int i=0;i<[Link];i++) a[i]=[Link](r,i).toString();
return a;
}

String[] form(String[] cur){


JTextField c=new JTextField(cur==null?"":cur[0]);
JComboBox<String> m=new JComboBox<>(new String[]
{"Drip","Sprinkler","Flood"});
if(cur!=null) [Link](cur[1]);
JTextField s=new JTextField(cur==null?"06:00":cur[2]);
JTextField d=new JTextField(cur==null?"30":cur[3]);
JTextField dy=new JTextField(cur==null?"3":cur[4]);
JTextField w=new JTextField(cur==null?"500":cur[5]);
JTextField n=new JTextField(cur==null?"":cur[6]);
JPanel p=new JPanel(new GridLayout(0,2));
[Link](new JLabel("Crop"));[Link](c);
[Link](new JLabel("Method"));[Link](m);
[Link](new JLabel("Start"));[Link](s);
[Link](new JLabel("Duration"));[Link](d);
[Link](new JLabel("Days/week"));[Link](dy);
[Link](new JLabel("Water(L/ha)"));[Link](w);
[Link](new JLabel("Notes"));[Link](n);
int
ok=[Link](this,p,"Schedule",JOptionPane.OK_CANCEL_
OPTION);
if(ok==JOptionPane.OK_OPTION)
return new String[]
{[Link](),[Link]().toString(),[Link](),[Link](),[Link](),w.g
etText(),[Link]()};
return null;
}

void msg(Exception e)
{ [Link](this,[Link]()); }

public static void main(String[] args){


[Link](()->new
IrrigationScheduleManager().setVisible(true));
}
}

Screenshots:
[Link] addition details that already stored in csv file.
[Link] of new crop that need to be irrigated.

3. After addition of jute crop.


4. Edit the crop details that already in the table.

5. After editing Rice from 7 days from week to 5 days from week.
[Link] the selected row.

7. After deleting the selected row Barley.


[Link] particular crop from the table. The searched crop highlighted.

[Link] completing all the operations final values stored in csv file.

You might also like