Bus Time Table in Java

Bus Time Table in Java

View Answers

December 22, 2009 at 4:38 PM

Hi Friend,

Try the following code:

import java.io.*;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.sql.*;
import java.util.*;

class Project{
JFrame f;
JPanel p1,p2,p3,p4,p;
JTabbedPane tp;
ImageIcon btnimg1,btnimg2;
JLabel l1, l2, l3, l4,l5,l6,l7,l8,l9,l10,l11,l12,l13,l14,l15,l16,l17,l18,l19,l20;
JTextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10,tf11,tf12;
JScrollPane sp1;
JButton savebtn,resetbtn,searchbtn,editbtn1,editbtn2,delbtn,btn ;
GridBagLayout gbl;
GridBagConstraints gbc;

Project(){
f=new JFrame("Bus TimeTable");
p=new JPanel();
p1=new JPanel(new GridLayout(6,2));
p2=new JPanel(new GridLayout(6,2));
p3=new JPanel(new GridLayout(6,2));
p4=new JPanel(new GridLayout(2,2));
tp=new JTabbedPane();
l1=new JLabel("Bus No:");
l2=new JLabel("Source:");
l3=new JLabel("Time(hh:mm:ss):");
l4=new JLabel("Destination:");
l5=new JLabel("Time(hh:mm:ss):");
l6=new JLabel("Enter bus no:");
l7=new JLabel("Bus No:");
l8=new JLabel("Source:");
l9=new JLabel("Time(hh:mm:ss):");
l10=new JLabel("Destination:");
l11=new JLabel("Time(hh:mm:ss):");
l12=new JLabel("Enter Bus No:");
l13=new JLabel("Source");
l14=new JLabel();
l15=new JLabel("Time(hh:mm:ss)");
l16=new JLabel();
l17=new JLabel("Destination");
l18=new JLabel();
l19=new JLabel("Time(hh:mm:ss)");
l20=new JLabel();

tf1=new JTextField(12);
tf2=new JTextField(12);
tf3=new JTextField(12);
tf4=new JTextField(12);
tf5=new JTextField(12);
tf6=new JTextField(12);
tf7=new JTextField(12);
tf8=new JTextField(12);
tf9=new JTextField(12);
tf10=new JTextField(12);
tf11=new JTextField(12);
tf12=new JTextField(12);
savebtn=new JButton(" Save ");
resetbtn=new JButton(" Reset");
searchbtn=new JButton("Search");
editbtn1=new JButton(" Edit ");
editbtn2=new JButton(" Save");
delbtn=new JButton(" Delete");
btn=new JButton("Back");
p1.add(l1);
p1.add(tf1);
p1.add(l2);
p1.add(tf2);
p1.add(l3);
p1.add(tf3);
p1.add(l4);
p1.add(tf4);
p1.add(l5);
p1.add(tf5);
p1.add(savebtn);
p1.add(resetbtn);

p2.add(l13);
p2.add(l14);
p2.add(l15);
p2.add(l16);
p2.add(l17);
p2.add(l18);
p2.add(l19);
p2.add(l20);
p2.add(l6);
p2.add(tf6);
p2.add(searchbtn);
p2.add(btn);


p3.add(l7);
p3.add(tf7);
p3.add(l8);
p3.add(tf8);
p3.add(l9);
p3.add(tf9);
p3.add(l10);
p3.add(tf10);
p3.add(l11);
p3.add(tf11);
p3.add(editbtn1);
p3.add(editbtn2);

p4.add(l12);
p4.add(tf12);
p4.add(delbtn);
p.add(p4);

December 22, 2009 at 4:40 PM

continue...

l13.setVisible(false);
l14.setVisible(false);
l15.setVisible(false);
l16.setVisible(false);
l17.setVisible(false);
l18.setVisible(false);
l19.setVisible(false);
l20.setVisible(false);
btn.setVisible(false);
resetbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
tf1.setText("");
tf2.setText("");
tf3.setText("");
tf4.setText("");
tf5.setText("");
}
});

savebtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
try{
String v1=tf1.getText();
String v2=tf2.getText();
String v3=tf3.getText();
String v4=tf4.getText();
String v5=tf5.getText();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st=con.createStatement();
int i=st.executeUpdate("insert into timetable(busno,source,time1,destination,time2)values('"+v1+"','"+v2+"','"+v3+"','"+v4+"','"+v5+"')");

}
catch(Exception exp1){
JOptionPane.showMessageDialog(p1,"Error Code 1 : Submit Failed... ");
}
}
});
searchbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
l13.setVisible(true);
l14.setVisible(true);
l15.setVisible(true);
l16.setVisible(true);
l17.setVisible(true);
l18.setVisible(true);
l19.setVisible(true);
l20.setVisible(true);
btn.setVisible(true);
l6.setVisible(false);
tf6.setVisible(false);
searchbtn.setVisible(false);

try
{
String v=tf6.getText();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from timetable where busno='"+v+"'");
rs.next();
l14.setText(rs.getString("source"));
l16.setText(rs.getString("time1"));
l18.setText(rs.getString("destination"));
l20.setText(rs.getString("time2"));
}
catch(Exception exp3)
{
JOptionPane.showMessageDialog(p2,"Can't Search may be you have entered an invalid Bus Code");
}
btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
l13.setVisible(false);
l14.setVisible(false);
l15.setVisible(false);
l16.setVisible(false);
l17.setVisible(false);
l18.setVisible(false);
l19.setVisible(false);
l20.setVisible(false);
btn.setVisible(false);
l6.setVisible(true);
tf6.setVisible(true);
searchbtn.setVisible(true);
}
});
}
});


editbtn1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){

try
{
String v=tf7.getText();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st=con.createStatement();
ResultSet rs=st.executeQuery("select * from timetable where busno='"+v+"'");
String st1="",st2="",st3="",st4="";
while(rs.next()){

st1=rs.getString("source");
st2=rs.getString("time1");
st3=rs.getString("destination");
st4=rs.getString("time2");
}
tf8.setText(st1);
tf9.setText(st2);
tf10.setText(st3);
tf11.setText(st4);

}
catch(Exception exp4)
{
JOptionPane.showMessageDialog(p3,"Can not edit data...");
}
}
});

December 22, 2009 at 4:42 PM

continue..

editbtn2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){

try
{
int x=JOptionPane.showConfirmDialog(p3,"Confirm edit? All data will be replaced");
if(x==0)
{
try{
String v1=tf7.getText();
String v2=tf8.getText();
String v3=tf9.getText();
String v4=tf10.getText();
String v5=tf11.getText();
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st=con.createStatement();
st.executeUpdate("update timetable set source='"+v2+"', time1='"+v3+"', destination='"+v4+"', time2='"+v5+"' where busno='"+v1+"'");
JOptionPane.showMessageDialog(p3,"Saved........");
con.close();
}
catch(Exception exp5)
{
JOptionPane.showMessageDialog(p3,"Problem in updating edit fields...");
}
}
else if(x==1)
{

JOptionPane.showMessageDialog(p3,"Action terminated by user...");
}
else if(x==2)
{
tf7.setText("");
tf8.setText("");
tf9.setText("");
tf10.setText("");
tf11.setText("");
}
}
catch(Exception exp6)
{
JOptionPane.showMessageDialog(p3,"Error Code 6 : Editing Failed... ");
}
}
});
delbtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae){
String v=tf12.getText();
try{
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test";, "root", "root");
Statement st=con.createStatement();
int i=st.executeUpdate("Delete from timetable where busno='"+v+"'");
JOptionPane.showMessageDialog(p4,"Information is successfully deleted.");
}
catch(Exception e){
JOptionPane.showMessageDialog(p4,"Error in deleting data");
}


}
});
}
void dis()
{
f.getContentPane().add(tp);
tp.addTab("Add Details",p1);
tp.addTab("Search Options",p2);
tp.addTab("Edit Options",p3);
tp.addTab("Delete Options",p);

f.setSize(500,200);
f.setVisible(true);
f.setResizable(true);
}
public static void main(String args[]){
Project pro=new Project();
pro.dis();
}
}

For the above code, you need to create following table:

CREATE TABLE `timetable` (
`busno` int(255) default NULL,
`source` varchar(255) default NULL,
`time1` varchar(255) default NULL,
`destination` varchar(255) default NULL,
`time2` varchar(255) NOT NULL
)

Thanks









Related Tutorials/Questions & Answers:
Bus Time Table in Java - Development process
Bus Time Table in Java  I want mini project for Bus timeTable...(); l1=new JLabel("Bus No:"); l2=new JLabel("Source:"); l3=new JLabel("Time...=new JLabel("Time(hh:mm:ss):"); l12=new JLabel("Enter Bus No:"); l13=new JLabel
Java Error in Bus Time Table Project - Development process
Java Error in Bus Time Table Project  Please Solve Errors import... JTabbedPane(); l1=new JLabel("Bus No:"); l2=new JLabel("Source:"); l3=new JLabel("Time...:"); l11=new JLabel("Time(hh:mm:ss):"); l12=new JLabel("Enter Bus No:"); l13=new
Advertisements
Time Table in Java
Time Table in Java  Hi, Deepak i am developing a time table for a school on java,but i am confuse how to start so please give me idea about
Time table generation
Time table generation  Hi I am 3rd year bca student i want create time table generator for my project.i am going to create it as school time table... informations we have to provide to generate time table? pls make me clear. Thanks
Time table generation
Time table generation  Hi I am 3rd year bca student i want create time table generator for my project.i am going to create it as school time table management.i want some ideas related this project I mean i want
generating time table - JSP-Servlet
generating time table  hi friends, i want generate examination timetable for examinations of courses like btech(cse,ece,eee..etc),if i give starting date of examinaton then automatically generate timetable for all subjects
Displaying database table on the windows screen in real time.
Displaying database table on the windows screen in real time.  Problem statement... I have a database table which is running on a remote host .I need to write a program to display this table in a windows form or on a html page
how to upload a student time table excelsheet
end as java .in my student module i have time table so how to upload excelsheet time table or is it possible maintain dynamically plz help me.   ...how to upload a student time table excelsheet   Hi good morning iam
table in java
table in java  Could any one make compiler in java please reply me
table in java
table in java  Could any one make compiler in java please reply me
table in java
table in java  Could any one make compiler in java please reply me
table in java
table in java  please l want to make table and insert by user
Decreasing process time by caching through the Hash Table in Java
Decreasing process time by caching through the Hash Table in Java... illustrates you how to improve the process time of any type of the operation performed by your java program. You can easily improve the process completion time
jsp code for dynamic time table generation - JSP-Servlet
jsp code for dynamic time table generation  hi I am doing my academic project college automation. I want to generate time table dynamically... For the above code, we have created three database tables 1)btech: CREATE TABLE
get absolute time java
get absolute time java  How to get absolute time in java
Java run time polymorphism
Java run time polymorphism  What is run-time polymorphism or dynamic method dispatch
how to move records from one table to other based on its creation time
how to move records from one table to other based on its creation time  Hi all,, As part of my requirement ,the records in one table have to move to second table based on the record creation time means the records should
Java Hash table
Java Hash table   Hi I have to create code to allow the insertion of a sequence of numbers into a hash table,using a fixed size hash table. Then i... of numbers; insert these into the hash table. Can anyone give me any help
time
time  how to find the current system time between the user login and logout using java
date and time in awt(java)
date and time in awt(java)  sir, do you have an example of date in awt java which can be view over a textfield.   Display time in JTextField import java.util.*; import javax.swing.*; import java.awt.event.*; public
Java table & list
Java table & list  I am taking string elements from user in list, And I want those list elements to be added to table row one by one, The jTable & list are at different classes but under same package. How to do so? Please
Create a Table - Java Beginners
Create a Table in Java  How can i create table in Java?  Java Example Code - Creating table in JAVA- - - - - - - - - - - - - - - - - - - - - - Hi, here i am giving you a java program code, that creates a table with two
Java Table Create
Java Table Create  hi........ thanks 4 ur reply......... but i... the following is the table Jan Feb Mar........... pH 2 3 4....... values also. I want that pH, temp etc should also come in that table
time
time  sir, i want to show system time on a textfield in awt(java). woulk you send me an example of time which can show time in standard format like H:M:S pls help me sir   Display time in JTextField import
table
table  multiplicatyion table
java time - Java Beginners
java time  Hi, Iam created a desktop login application using swings. pls observe the following code: import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.sql.*; class LoginDemo{ JButton
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do? For this i already received the answer. But its converting the time in 24hr format to 12hr format
different execution time - Java Beginners
different execution time    hello, when i run the bellow code more than one time i am getting different execution time("Total time taken"), Ex. when i run first time it prints Total time taken 47 second time it prints Total
creation of table using a Java swing
creation of table using a Java swing  how to create a table dynamically in Java swing
java coding for creating table in the console
java coding for creating table in the console  write a java program to create table
TABLE
TABLE   Why doesn't <TABLE WIDTH="100%"> use the full browser width
time
time display only as hh:mm.  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database
time
time format hh:mm:ss  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display in different
time
time  Hi. I have retrieved time from mysql database. its in th format hh:mm:ss. but i want to display only as hh:mm. wat to do?   Here is a jsp example that fetch the time from the database and display in different
time
retrieved time from mysql database  Hi. I have retrieved time from.... wat to do?   Here is a jsp example that fetch the time from... is a jsp example that fetch the time from the database and display in different
Table
Table  How i generate table in showMessageDialog. I want that i creat a table and run in showMessageDialogeprint("cprint("code sample");ode sample
Java Execution Time Measurement(JETM)
Java Execution Time Measurement(JETM)  How can we integrate JETM in eclipse
Table
Table  How I generate table in showMessageDialog. E.g 3X1=3 3X2=6 3X3=9print("code sample
Table
Table  How i generate table in showMessageDialog. I want to creat a table and run in showMessageDialoge. Pl make a table programe which run..., JOptionpane, Integer.parseInt. Please use only these above methods to make table
java run time error - JDBC
java run time error  when i m running for batch execution program in jdbc i m facing this kind of runtime error as Exception in thread "main..."); Statement st=con.createStatement(); st.addBatch("create table upen(empno number
table
input from oracle table(my database table..) This is a very important table of my
table
table  Hi..I have a list of links which links to a table in the same page.If I click first link the table is displayed at the top, likewise if i click the last link the table is displayed at the last,i dont know how to set

Ads