-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBus_Search.java
179 lines (146 loc) · 4.52 KB
/
Bus_Search.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
import java.sql.*;
import javax.swing.*;
import java.util.Date;
import java.text.*;
import java.awt.*;
import java.awt.event.*;
class Bus_Search extends JFrame
{
public Container content;
public JPanel reportingPanel;
public JTabbedPane listsTabs;
public JTextArea listPane;
public JPanel reportPanel;
public static final int SET_SIZE = 0, PRINT = 1, CLOSE = 2;
public JPanel statusPanel;
public JComboBox graphTypesCombo;
public Color skyblue = new Color(150, 190, 255);
public final ImageIcon imageIcon = new ImageIcon("Icon/header/cool.png");
private static Connection dbcon = null;
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
Statement stmt = null;
private JButton print, cancel;
private JPanel panel;
Connection con;
public Bus_Search(String str)
{
super("Buses Search");
String ss=str;
content = getContentPane();
content.setBackground(skyblue);
listsTabs = new JTabbedPane();
//print = new JButton("PRINT ", new ImageIcon("Icon/i16x16/prints.png"));
cancel = new JButton("CANCEL", new ImageIcon("Icon/i16x16/exit.png"));
panel = new JPanel();
//panel.add(print);
panel.add(cancel);
reportingPanel = new JPanel();
reportingPanel.setLayout(new BorderLayout());
reportingPanel.setBorder(BorderFactory.createEtchedBorder());
reportingPanel.add(new JLabel("Bus Search"), BorderLayout.NORTH);
reportingPanel.add(panel, BorderLayout.SOUTH);
reportPanel = new JPanel();
reportPanel.setLayout(new GridLayout(1, 1));
reportPanel.setBorder(BorderFactory.createMatteBorder(4, 4, 4, 4, Color.blue));
reportPanel.setBackground(Color.white);
reportingPanel.add(new JScrollPane(reportPanel), BorderLayout.CENTER);
listsTabs.add(reportingPanel);
setLocation((screen.width - 1270) / 2, ((screen.height - 740) / 2));
setResizable(false);
listPane = new JTextArea()
{
Image image = imageIcon.getImage();
{
setOpaque(false);
}
public void paint(Graphics g)
{
g.setColor(Color.red);
setFont(new Font("Times New Roman", Font.BOLD,15));
g.drawString("Bus Search Result", 385, 70);
g.setColor(Color.red);
super.paint(g);
}
};
listPane.setEditable(false);
listPane.setFont(new Font("Serif", Font.BOLD, 12));
listPane.setForeground(Color.black);
listPane.setLineWrap(true);
listPane.setWrapStyleWord(true);
reportPanel.add(listPane);
try
{
makeConnection();
Statement s = con.createStatement();
}
catch (Exception excp)
{
excp.printStackTrace();
}
printList(ss);
content.add(listsTabs, BorderLayout.CENTER);
cancel.addActionListener(new java.awt.event.ActionListener()
{
public void actionPerformed(java.awt.event.ActionEvent e)
{
dispose();
}
});
setResizable(false);
setSize(1000, 720);
setVisible(true);
}
public void makeConnection()
{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
String database = "";
database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database += "Travels.mdb" + ";DriverID=22;READONLY=true}";
//now we can get connection from DriverManager
con = DriverManager.getConnection(database, "", "");
}
catch (Exception e)
{
System.out.println("Error in making connection: " + e);
}
}
private void printList(String ss)
{
try
{
ResultSet rst = con.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_UPDATABLE).executeQuery("select Bus_RegNo,Model,Capacity,insurance_Status,Insurance_Expiry from Buses where Model ='" + ss + "'");
listPane.append("\n\n\n\n\n\n\n\n\n\n\n\n");
listPane.append("Bus RegNo" + "\t\t" + "Model" + "\t\t" + "Capacity" + "\t\t" + "Insurance_Status\t" + "Expiry Date\n");
while (rst.next())
{
listPane.append(" \n ");
listPane.append(rst.getString(1).trim());
listPane.append("\t\t");
listPane.append(rst.getString(2).trim());
listPane.append("\t\t");
listPane.append(rst.getString(3).trim());
listPane.append("\t\t");
listPane.append(rst.getString(4).trim());
listPane.append("\t\t");
listPane.append(rst.getString(5).trim());
listPane.append("\n\n");
}
if (rst != null)
rst.close();
}
catch (SQLException sqle)
{
JOptionPane.showMessageDialog(null, " No Records found"
+ sqle.getMessage());
return;
}
}
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
}
}