📄 passengerdetails.java
字号:
package airline;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class PassengerDetails extends Frame implements ActionListener
{
String title="Passenger Information";
Frame f;
Label lbl_formname=new Label("Passenger's Information");
Label lbl_pname=new Label("Passenger's Name");
Label lbl_gender=new Label("Gender");
Label lbl_age=new Label("Age");
Label lbl_fltno=new Label("Flight No.");
Label lbl_fromcity=new Label("Starting City");
Label lbl_tocity=new Label("Destination City");
Label lbl_dot=new Label("Date of travel");
Label lbl_pnr=new Label("PNR No.");
Label lbl_class=new Label("Class");
Label lbl_seatno=new Label("Seat no.");
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_pname,tf_gender,tf_age,tf_fromcity,tf_tocity,tf_fltno,tf_dot,tf_pnr,tf_class,tf_seatno;
Font font=new Font("Times New Roman",0,14);
Font fontform=new Font("Times New Roman",0,25);
int lbl_x=70;
int txt_x=200;
int lbl_y=180;
int txt_y=175;
int lbl_width=120;
int txt_width=150;
int lbl_hieght=20;
int txt_hieght=25;
Connection con;
Statement s1;
ResultSet rs;
//yes.resize(20,30);
// f=new CustomerDetails("A Frame Window");
public PassengerDetails()
{
super("Passenger's Information");
f=new Frame(title);
PasWindowAdapter adapter=new PasWindowAdapter(this);
f.addWindowListener(adapter);
f.setLayout(null);
lbl_formname.setFont(fontform);
lbl_formname.setBounds(300,75,300,75);
f.add(lbl_formname);
lbl_pname.setFont(font);
lbl_pname.setBounds(lbl_x,lbl_y,lbl_width,lbl_hieght);
f.add(lbl_pname);
lbl_gender.setFont(font);
lbl_gender.setBounds(lbl_x,lbl_y+40,lbl_width,lbl_hieght);
f.add(lbl_gender);
lbl_age.setFont(font);
lbl_age.setBounds(lbl_x,lbl_y+80,lbl_width,lbl_hieght);
f.add( lbl_age);
lbl_fltno.setFont(font);
lbl_fltno.setBounds(lbl_x,lbl_y+120,lbl_width,lbl_hieght);
f.add( lbl_fltno);
lbl_fromcity.setFont(font);
lbl_fromcity.setBounds(lbl_x,lbl_y+160,lbl_width,lbl_hieght);
f.add( lbl_fromcity);
tf_pname=new TextField(25);
tf_pname.setBounds(txt_x,txt_y,txt_width,txt_hieght);
f.add(tf_pname);
tf_gender=new TextField(25);
tf_gender.setBounds(txt_x,txt_y+40,txt_width,txt_hieght);
f.add(tf_gender);
tf_age=new TextField(25);
tf_age.setBounds(txt_x,txt_y+80,txt_width,txt_hieght);
f.add(tf_age);
tf_fltno=new TextField(25);
tf_fltno.setBounds(txt_x,txt_y+120,txt_width,txt_hieght);
f.add(tf_fltno);
tf_fromcity=new TextField(25);
tf_fromcity.setBounds(txt_x,txt_y+160,txt_width,txt_hieght);
f.add(tf_fromcity);
lbl_x=400;
lbl_tocity.setFont(font);
lbl_tocity.setBounds(lbl_x,lbl_y,lbl_width,lbl_hieght);
f.add( lbl_tocity);
lbl_dot.setFont(font);
lbl_dot.setBounds(lbl_x,lbl_y+40,lbl_width,lbl_hieght);
f.add( lbl_dot);
lbl_pnr.setFont(font);
lbl_pnr.setBounds(lbl_x,lbl_y+80,lbl_width,lbl_hieght+10);
f.add( lbl_pnr);
lbl_class.setFont(font);
lbl_class.setBounds(lbl_x,lbl_y+120,lbl_width,lbl_hieght);
f.add( lbl_class);
lbl_seatno.setFont(font);
lbl_seatno.setBounds(lbl_x,lbl_y+160,lbl_width,lbl_hieght);
f.add( lbl_seatno);
txt_x=520;
tf_tocity=new TextField(25);
tf_tocity.setBounds(txt_x,txt_y,txt_width,txt_hieght);
f.add(tf_tocity);
tf_dot=new TextField(8);
tf_dot.setBounds(txt_x,txt_y+40,txt_width,txt_hieght);
f.add(tf_dot);
tf_pnr=new TextField(25);
tf_pnr.setBounds(txt_x,txt_y+80,txt_width,txt_hieght);
f.add(tf_pnr);
tf_class=new TextField(3);
tf_class.setBounds(txt_x,txt_y+120,txt_width,txt_hieght);
f.add(tf_class);
tf_seatno=new TextField(25);
tf_seatno.setBounds(txt_x,txt_y+160,txt_width,txt_hieght);
f.add(tf_seatno);
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("aaaa ");
s1=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
try{
rs=s1.executeQuery("select * from passenger");
rs.next();
}catch(Exception e)
{
System.out.print("Exception occure 11 "+e);
}
tf_pname.setText(rs.getString(1));
tf_fltno.setText(rs.getString(2));
tf_fromcity.setText(rs.getString(3));
tf_tocity.setText(rs.getString(4));
tf_dot.setText(rs.getString(5));
tf_class.setText(rs.getString(6));
tf_seatno.setText(rs.getString(7));
tf_gender.setText(rs.getString(8));
tf_age.setText(rs.getString(9));
tf_pnr.setText(rs.getString(10));
cmd_save.setEnabled(false);
}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_pname.setText(rs.getString(1));
tf_fltno.setText(rs.getString(2));
tf_fromcity.setText(rs.getString(3));
tf_tocity.setText(rs.getString(4));
tf_dot.setText(rs.getString(5));
tf_class.setText(rs.getString(6));
tf_seatno.setText(rs.getString(7));
tf_gender.setText(rs.getString(8));
tf_age.setText(rs.getString(9));
tf_pnr.setText(rs.getString(10));
}
if(e.getSource()==cmd_prev)
{
rs.previous();
tf_pname.setText(rs.getString(1));
tf_fltno.setText(rs.getString(2));
tf_fromcity.setText(rs.getString(3));
tf_tocity.setText(rs.getString(4));
tf_dot.setText(rs.getString(5));
tf_class.setText(rs.getString(6));
tf_seatno.setText(rs.getString(7));
tf_gender.setText(rs.getString(8));
tf_age.setText(rs.getString(9));
tf_pnr.setText(rs.getString(10));
}
if(e.getSource()==cmd_add)
{
tf_pname.setText(rs.getString(1));
tf_fltno.setText(rs.getString(2));
tf_fromcity.setText(rs.getString(3));
tf_tocity.setText(rs.getString(4));
tf_dot.setText(rs.getString(5));
tf_class.setText(rs.getString(6));
tf_seatno.setText(rs.getString(7));
tf_gender.setText(rs.getString(8));
tf_age.setText(rs.getString(9));
tf_pnr.setText(rs.getString(10));
}
if(e.getSource()==cmd_save)
{
s1.executeUpdate("update passenger set p_name='"+tf_pname.getText()+"',gender='"+tf_gender.getText()+"',p_age='"+tf_age.getText()+"' where pnr_no='"+tf_pnr.getText()+"' and seat_no='"+tf_seatno.getText()+"'");
tf_fltno.setEnabled(true);
tf_fromcity.setEnabled(true);
tf_tocity.setEnabled(true);
tf_dot.setEnabled(true);
tf_class.setEnabled(true);
tf_seatno.setEnabled(true);
tf_pnr.setEnabled(true);
cmd_save.setEnabled(false);
rs=s1.executeQuery("select * from passenger");
}
if(e.getSource()==cmd_edit)
{
tf_pname.setText("");
tf_fltno.setEnabled(false);
tf_fromcity.setEnabled(false);
tf_tocity.setEnabled(false);
tf_dot.setEnabled(false);
tf_class.setEnabled(false);
tf_seatno.setEnabled(false);
tf_gender.setText("");
tf_age.setText("");
tf_pnr.setEnabled(false);
cmd_save.setEnabled(true);
}
}catch(Exception er){
System.out.println(er);
}
}
class PasWindowAdapter extends WindowAdapter
{
//CustomerDetails sampleFrame;
Frame sampleFrame;
public PasWindowAdapter(PassengerDetails sFrame)
{
System.out.println("window");
this.sampleFrame=sFrame;
}
public void windowClosing(WindowEvent we)
{
System.out.println("terminating");
f.hide();
//System.exit(0);
//sampleFrame.setVisible(false);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -