📄 flightdetails.java
字号:
package airline;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class FlightDetails extends Frame implements ActionListener
{
String title="Flight Details";
Frame f;
Label lbl_formname=new Label("Flight Details");
Label lbl_flightno=new Label("Flight Number");
Label lbl_deptime=new Label("Departure Time");
Label lbl_arrtime=new Label("Arrival Time");
Label lbl_fromcity=new Label("Starting City");
Label lbl_tocity=new Label("Destination City");
Label lbl_maxseat=new Label("Maximum Seats");
Label lbl_fare=new Label("Fare");
Label lbl_weekdays=new Label("Weekdays");
Label lbl_class=new Label("Class");
Button cmd_add,cmd_save,cmd_edit,cmd_delete,cmd_next,cmd_prev,cmd_first,cmd_last;
int cmd_hieght=30;
int cmd_x=250;
int cmd_y=435;
int cmd_width=60;
int count=0;
TextField tf_flightno,tf_deptime,tf_arrtime,tf_fromcity,tf_tocity,tf_maxseat,tf_fare,tf_weekdays,tf_class;
Font font=new Font("Times New Roman",0,14);
Font fontform=new Font("Times New Roman",0,25);
int lbl_x=80;
int txt_x=200;
int lbl_y=180;
int txt_y=175;
int lbl_width=105;
int txt_width=150;
int lbl_hieght=20;
int txt_hieght=25;
Connection con;
Statement s1;
ResultSet rs;
public FlightDetails()
{
super("Flight Details");
f=new Frame(title);
FlWindowAdapter adapter=new FlWindowAdapter(this);
f.addWindowListener(adapter);
f.setLayout(null);
lbl_formname.setFont(fontform);
lbl_formname.setBounds(300,75,300,75);
f.add(lbl_formname);
lbl_flightno.setFont(font);
lbl_flightno.setBounds(lbl_x,lbl_y,lbl_width,lbl_hieght);
f.add(lbl_flightno);
lbl_deptime.setFont(font);
lbl_deptime.setBounds(lbl_x,lbl_y+40,lbl_width,lbl_hieght);
f.add(lbl_deptime);
lbl_arrtime.setFont(font);
lbl_arrtime.setBounds(lbl_x,lbl_y+80,lbl_width,lbl_hieght);
f.add( lbl_arrtime);
lbl_fromcity.setFont(font);
lbl_fromcity.setBounds(lbl_x,lbl_y+120,lbl_width,lbl_hieght);
f.add( lbl_fromcity);
lbl_tocity.setFont(font);
lbl_tocity.setBounds(lbl_x,lbl_y+160,lbl_width,lbl_hieght);
f.add( lbl_tocity);
tf_flightno=new TextField(25);
tf_flightno.setBounds(txt_x,txt_y,txt_width,txt_hieght);
f.add(tf_flightno);
tf_deptime=new TextField(25);
tf_deptime.setBounds(txt_x,txt_y+40,txt_width,txt_hieght);
f.add(tf_deptime);
tf_arrtime=new TextField(25);
tf_arrtime.setBounds(txt_x,txt_y+80,txt_width,txt_hieght);
f.add(tf_arrtime);
tf_fromcity=new TextField(25);
tf_fromcity.setBounds(txt_x,txt_y+120,txt_width,txt_hieght);
f.add(tf_fromcity);
tf_tocity=new TextField(25);
tf_tocity.setBounds(txt_x,txt_y+160,txt_width,txt_hieght);
f.add(tf_tocity);
lbl_x=400;
lbl_weekdays.setFont(font);
lbl_weekdays.setBounds(lbl_x,lbl_y,lbl_width,lbl_hieght);
f.add( lbl_weekdays);
lbl_maxseat.setFont(font);
lbl_maxseat.setBounds(lbl_x,lbl_y+40,lbl_width,lbl_hieght);
f.add( lbl_maxseat);
lbl_class.setFont(font);
lbl_class.setBounds(lbl_x,lbl_y+80,lbl_width,lbl_hieght+10);
f.add( lbl_class);
lbl_fare.setFont(font);
lbl_fare.setBounds(lbl_x,lbl_y+120,lbl_width,lbl_hieght);
f.add( lbl_fare);
//lbl_exp.setFont(font);
//lbl_exp.setBounds(lbl_x,lbl_y+160,lbl_width,lbl_hieght);
//f.add( lbl_exp);
txt_x=520;
tf_weekdays=new TextField(25);
tf_weekdays.setBounds(txt_x,txt_y,txt_width,txt_hieght);
f.add(tf_weekdays);
tf_maxseat=new TextField(8);
tf_maxseat.setBounds(txt_x,txt_y+40,txt_width,txt_hieght);
f.add(tf_maxseat);
tf_class=new TextField(25);
tf_class.setBounds(txt_x,txt_y+80,txt_width,txt_hieght);
f.add(tf_class);
tf_fare=new TextField(3);
tf_fare.setBounds(txt_x,txt_y+120,txt_width,txt_hieght);
f.add(tf_fare);
//tf_exp=new TextField(25);
//tf_exp.setBounds(txt_x,txt_y+160,txt_width,txt_hieght);
//f.add(tf_exp);
cmd_add=new Button("Add");
cmd_add.setBounds(cmd_x,cmd_y,cmd_width,cmd_hieght);
cmd_add.addActionListener(this);
f.add(cmd_add);
cmd_save=new Button("Save");
cmd_save.setBounds(cmd_x+90,cmd_y,cmd_width,cmd_hieght);
cmd_save.addActionListener(this);
f.add(cmd_save);
cmd_edit=new Button("Edit");
cmd_edit.setBounds(cmd_x+180,cmd_y,cmd_width,cmd_hieght);
cmd_edit.addActionListener(this);
f.add(cmd_edit);
cmd_delete=new Button("Delete");
cmd_delete.setBounds(cmd_x+270,cmd_y,cmd_width,cmd_hieght);
cmd_delete.addActionListener(this);
f.add(cmd_delete);
cmd_y=485;
cmd_next=new Button("Next");
cmd_next.setBounds(cmd_x,cmd_y,cmd_width,cmd_hieght);
cmd_next.addActionListener(this);
f.add(cmd_next);
cmd_prev=new Button("Previous");
cmd_prev.setBounds(cmd_x+90,cmd_y,cmd_width,cmd_hieght);
cmd_prev.addActionListener(this);
f.add(cmd_prev);
cmd_first=new Button("First");
cmd_first.setBounds(cmd_x+180,cmd_y,cmd_width,cmd_hieght);
cmd_first.addActionListener(this);
f.add(cmd_first);
cmd_last=new Button("Last");
cmd_last.setBounds(cmd_x+270,cmd_y,cmd_width,cmd_hieght);
cmd_last.addActionListener(this);
f.add(cmd_last);
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getConnection("jdbc:odbc:Reservation","reservation","varun");
//System.out.print("varun ");
s1=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
//System.out.print("jk");
try{
rs=s1.executeQuery("select schedule.flt_no,schedule.dep_time,schedule.Ar_time,schedule.from_city,schedule.to_city,flight_detail.week_days,schedule.max_seat,fare.class,fare.flt_fare from fare,schedule,flight_detail where flight_detail.flt_no=schedule.flt_no and flight_detail.flt_no=fare.flt_no ");
//System.out.println(" kjk");
rs.next();
//rs.next();
}catch(Exception e)
{
System.out.print("Exception occure 11 "+e);
}
tf_flightno.setText(rs.getString(1));
tf_deptime.setText(rs.getString(2));
tf_arrtime.setText(rs.getString(3));
tf_fromcity.setText(rs.getString(4));
tf_tocity.setText(rs.getString(5));
tf_weekdays.setText(rs.getString(6));
tf_maxseat.setText(rs.getString(7));
tf_class.setText(rs.getString(8));
tf_fare.setText(rs.getString(9));
//tf_email.setText(rs.getString(10));
}catch(Exception e)
{
System.out.print("Exception occure 12 "+e);
}
f.setSize(1800,1800);
f.setVisible(true);
}
public void visible()
{
f.setVisible(true);
}
public void paint(Graphics g)
{
}
public void actionPerformed(ActionEvent e)
{
try{
if(e.getSource()==cmd_next)
{
rs.next();
tf_flightno.setText(rs.getString(1));
tf_deptime.setText(rs.getString(2));
tf_arrtime.setText(rs.getString(3));
tf_fromcity.setText(rs.getString(4));
tf_tocity.setText(rs.getString(5));
tf_weekdays.setText(rs.getString(6));
tf_maxseat.setText(rs.getString(7));
tf_class.setText(rs.getString(8));
tf_fare.setText(rs.getString(9));
//tf_email.setText(rs.getString(10));
}
if(e.getSource()==cmd_prev)
{
rs.previous();
tf_flightno.setText(rs.getString(1));
tf_deptime.setText(rs.getString(2));
tf_arrtime.setText(rs.getString(3));
tf_fromcity.setText(rs.getString(4));
tf_tocity.setText(rs.getString(5));
tf_weekdays.setText(rs.getString(6));
tf_maxseat.setText(rs.getString(7));
tf_class.setText(rs.getString(8));
tf_fare.setText(rs.getString(9));
}
if(e.getSource()==cmd_add)
{
tf_flightno.setText("");
tf_deptime.setText("");
tf_arrtime.setText("");
tf_fromcity.setText("");
tf_tocity.setText("");
tf_weekdays.setText("");
tf_maxseat.setText("");
tf_class.setText("Economy");
tf_fare.setText("");
tf_fare.setEditable(false);
}
if(e.getSource()==cmd_save)
{
if(count==0)
{
s1.executeUpdate("insert into flight_detail values('"+tf_flightno.getText()+"','"+tf_weekdays.getText()+"')");
s1.executeUpdate("insert into schedule values('"+tf_flightno.getText()+"','"+tf_fromcity.getText()+"','"+tf_tocity.getText()+"','"+tf_arrtime.getText()+"','"+tf_deptime.getText()+"','"+tf_maxseat.getText()+"')");
s1.executeUpdate("insert into fare values('"+tf_flightno.getText()+"','"+tf_fromcity.getText()+"','"+tf_tocity.getText()+"','"+tf_class.getText()+"','"+tf_fare.getText()+"')");
cmd_add.setEnabled(false);
tf_class.setText("Business");
tf_class.setEnabled(false);
tf_fare.setText("");
count=1 ;
}
if(count==1)
{
s1.executeUpdate("insert into fare values('"+tf_flightno.getText()+"','"+tf_fromcity.getText()+"','"+tf_tocity.getText()+"','"+tf_class.getText()+"','"+tf_fare.getText()+"')");
cmd_add.setEnabled(true);
count=0;
}
}
}catch(Exception er){
System.out.println(er);
}
}
class FlWindowAdapter extends WindowAdapter
{
//CustomerDetails sampleFrame;
Frame sampleFrame;
public FlWindowAdapter(FlightDetails sFrame)
{
System.out.println("window");
this.sampleFrame=sFrame;
}
public void windowClosing(WindowEvent we)
{
System.out.println("terminating");
//System.exit(0);
f.hide();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -