Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.text.*;
JTextField TFUserName;
JPasswordField TPPassword;
JButton BLogin;
public LoginPage()
{
WindowUtilities.setNativeLookAndFeel();
setPreferredSize(new Dimension(796,572));
PFlightTypes.setBackground(Color.white);
PLogin.setBackground(Color.white);
PFlightDetails.setBackground(Color.white);
PFlightTypes.setBounds(0,0,500, 340);
PLogin.setBounds(500,0,350, 340);
PFlightDetails.setBounds(0,340,790,200);
PLogin.add(LUserName);
PLogin.add(TFUserName);
PLogin.add(LPassword);
PLogin.add(TPPassword);
PLogin.add(BLogin);
PFlightDetails.add(JSP1);
PFlightDetails.add(JSP2);
PFlightDetails.add(JSP3);
PFlightDetails.add(JSP4);
JSP1.setVisible(true);
JSP2.setVisible(false);
JSP3.setVisible(false);
JSP4.setVisible(false);
PFlightTypes.add(LEconomic);
PFlightTypes.add(LBusiness);
PFlightTypes.add(LEconomic1);
PFlightTypes.add(LBusiness1);
LBusiness.setVisible(false);
LEconomic1.setVisible(false);
LBusiness1.setVisible(true);
LEconomic.setVisible(true);
c.add(PFlightTypes);
c.add(PLogin);
c.add(PFlightDetails);
PFlightTypes.add(LDomesticFlight);
PFlightTypes.add(LInternationalFlight);
pack();
setVisible(true);
addWindowListener(new ExitListener());
BLogin.addActionListener(new button1(this));
}
type.PLogin.remove(type.LUserName);
type.PLogin.remove(type.TFUserName);
type.PLogin.remove(type.LPassword);
type.PLogin.remove(type.TPPassword);
type.PLogin.remove(type.BLogin);
type.c.repaint();
}
else
{
JOptionPane.showMessageDialog(null, "Invalid username or
password. Try again");
}
}
public boolean check()
{
if (cCheck.length >= 5 || cCheck.length < 4)
return false;
for(int i=0;i<4;i++)
{
if(cCheck[i]!=cPassword[i])
return false;
}
return true;
}
}
type.LDomesticFlight.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
type.LInternationalFlight.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSO
R));
}
public void mouseClicked(MouseEvent e)
{
if(bCheck)
type.bCheck = true;
else
type.bCheck = false;
type.LEconomic.setVisible(true);
type.LBusiness1.setVisible(true);
type.LEconomic1.setVisible(false);
type.LBusiness.setVisible(false);
type.JSP1.setVisible(false);
type.JSP2.setVisible(false);
type.JSP3.setVisible(false);
type.JSP4.setVisible(false);
if(bCheck)
type.JSP1.setVisible(true);
else
type.JSP2.setVisible(true);
}
}
type.LDomesticFlight1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)
);
type.LInternationalFlight1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURS
OR));
}
public void mouseClicked(MouseEvent e)
{
if (bCheck)
new DomesticFlight(type);
else
new InternationalFlight(type);
}
}
type.LEconomic1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
type.LBusiness1.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}
public void mouseClicked(MouseEvent e)
{
if(type.bCheck)
{
if (bCheck)
{
type.LBusiness1.setVisible(false);
type.LBusiness.setVisible(true);
type.LEconomic.setVisible(false);
type.LEconomic1.setVisible(true);
type.JSP1.setVisible(false);
type.JSP2.setVisible(false);
type.JSP3.setVisible(true);
type.JSP4.setVisible(false);
}
else
{
type.LEconomic1.setVisible(false);
type.LBusiness.setVisible(false);
type.LBusiness1.setVisible(true);
type.LEconomic.setVisible(true);
type.JSP1.setVisible(true);
type.JSP2.setVisible(false);
type.JSP3.setVisible(true);
type.JSP4.setVisible(false);
}
}
else
{
if (bCheck)
{
type.LBusiness1.setVisible(false);
type.LBusiness.setVisible(true);
type.LEconomic.setVisible(false);
type.LEconomic1.setVisible(true);
type.JSP1.setVisible(false);
type.JSP2.setVisible(false);
type.JSP3.setVisible(false);
type.JSP4.setVisible(true);
}
else
{
type.LEconomic1.setVisible(false);
type.LBusiness.setVisible(false);
type.LBusiness1.setVisible(true);
type.LEconomic.setVisible(true);
type.JSP1.setVisible(false);
type.JSP2.setVisible(true);
type.JSP3.setVisible(false);
type.JSP4.setVisible(false);
}
}
}
}
DomesticFlight.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
LoginPage type1;
this.type1 = type1;
PPanel1 = new JPanel(null);
PPanel1.setPreferredSize(new Dimension(500,200));
img1=new ImageIcon("map1.jpg");
LImg1 = new JLabel(img1);
LBookingDetails.setBounds(20,3,100,20);
LFrom.setBounds(20,40,100,20);
CBFrom.setBounds(100,40,100,20);
LTo.setBounds(20,100,100,20);
CBTo.setBounds(100,100,100,20);
LBookingDate.setBounds(14,160,100,20);
TFBookingDate.setBounds(100,160,100,20);
LDate.setBounds(210,160,100,20);
LClass.setBounds(20,220,100,20);
CBClass.setBounds(100,220,100,20);
BFindFlight.setBounds(50,270,100,25);
LImg1.setBounds(0,290,495,260);
PPanel1.add(LBookingDetails);
PPanel1.add(LFrom);
PPanel1.add(CBFrom);
PPanel1.add(LTo);
PPanel1.add(CBTo);
PPanel1.add(LBookingDate);
PPanel1.add(TFBookingDate);
PPanel1.add(LDate);
PPanel1.add(LClass);
PPanel1.add(CBClass);
PPanel1.add(BFindFlight);
PPanel1.add(LImg1);
PPanel1.setBackground(Color.white);
c.add(PPanel1,BorderLayout.WEST);
String[] item4={"1","2","3","4","5","6"};
CBAdult = new JComboBox(item4);
String[] item5={"0","1","2","3","4"};
CBChildren = new JComboBox(item5);
String[] item6={"0","1","2","3"};
CBInfant = new JComboBox(item6);
LPassengerDetails.setBounds(40,3,100,20);
LAdult.setBounds(40,40,100,20);
CBAdult.setBounds(140,40,100,20);
LChildren.setBounds(40,105,100,20);
CBChildren.setBounds(140,105,100,20);
LInfant.setBounds(40,170,100,20);
CBInfant.setBounds(140,170,100,20);
LImg2.setBounds(16,220,320,200);
LNotes.setBounds(55,240,380,180);
PPanel2.add(LPassengerDetails);
PPanel2.add(LAdult);
PPanel2.add(LChildren);
PPanel2.add(LInfant);
PPanel2.add(CBAdult);
PPanel2.add(CBChildren);
PPanel2.add(CBInfant);
PPanel2.add(LNotes);
PPanel2.add(LImg2);
PPanel2.setBackground(Color.white);
c.add(PPanel2,BorderLayout.EAST);
setSize(795,580);
setVisible(true);
int i = 0;
if(sClass.equals("Economic"))
{
try{
while(i<20)
{
if(type1.row1[i][1].equals(sTo))
{
iPrice =
Integer.parseInt((String)type1.row1[i][2]);
sTime = (String)type1.row1[i][3];
break;
}
i++;
}
}catch(Exception e1)
{
JOptionPane.showMessageDialog(null, "You have no
rights to access");
System.out.println("Error: "+e1);
System.exit(0);
}
}
else
{
try
{
while(i<20)
{
if(type1.row1[i][1].equals(sTo))
{
iPrice =
Integer.parseInt((String)type1.row3[i][2]);
sTime = (String)type1.row3[i][3];
break;
}
i++;
}
}catch(Exception e1)
{
JOptionPane.showMessageDialog(null, "You have no
rights to access it");
System.exit(0);
}
}
type.setTitle(iPrice + " " + sTime);
iPrice = (iPrice*iAdult)+(iPrice*(iChildren/2));
int iCount=0;
int iSeatCount=0;
try
{
//read from data
Save2 save1;
ObjectInputStream OIS1 = new ObjectInputStream(new
FileInputStream("save2"));
do
{
save1 = (Save2)OIS1.readObject();
sTempFrom[iCount] = save1.sFrom;
sTempTo[iCount] = save1.sTo;
sTempClass[iCount] = save1.sClass;
sTempBookingDate[iCount] = save1.sBookingDate;
sTempTime[iCount] = save1.sTime;
iTempAdult[iCount] = save1.iAdult;
iTempChildren[iCount] = save1.iChildren;
iTempInfant[iCount] = save1.iInfant;
iTempPrice[iCount] = save1.iPrice;
iCount++;
if(save1.sBookingDate.equals(sBookingDate))
if(save1.sTo.equals(sTo))
iSeatCount=iSeatCount + save1.iAdult +
save1.iChildren + save1.iInfant;
}while(save1!=null);
OIS1.close();
}
catch(Exception e1)
{
}
iSeatCount = iSeatCount + iAdult + iChildren + iInfant;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.io.*;
LoginPage type1;
this.type1 = type1;
PPanel1 = new JPanel(null);
PPanel1.setPreferredSize(new Dimension(500,200));
img1=new ImageIcon("map1.jpg");
LImg1 = new JLabel(img1);
LBookingDetails.setBounds(20,3,100,20);
LFrom.setBounds(20,40,100,20);
CBFrom.setBounds(100,40,100,20);
LTo.setBounds(20,100,100,20);
CBTo.setBounds(100,100,100,20);
LBookingDate.setBounds(14,160,100,20);
TFBookingDate.setBounds(100,160,100,20);
LDate.setBounds(210,160,100,20);
LClass.setBounds(20,220,100,20);
CBClass.setBounds(100,220,100,20);
BFindFlight.setBounds(50,270,100,25);
LImg1.setBounds(0,290,495,260);
PPanel1.add(LBookingDetails);
PPanel1.add(LFrom);
PPanel1.add(CBFrom);
PPanel1.add(LTo);
PPanel1.add(CBTo);
PPanel1.add(LBookingDate);
PPanel1.add(TFBookingDate);
PPanel1.add(LDate);
PPanel1.add(LClass);
PPanel1.add(CBClass);
PPanel1.add(BFindFlight);
PPanel1.add(LImg1);
PPanel1.setBackground(Color.white);
c.add(PPanel1,BorderLayout.WEST);
String[] item4={"1","2","3","4","5","6"};
CBAdult = new JComboBox(item4);
String[] item5={"0","1","2","3","4"};
CBChildren = new JComboBox(item5);
String[] item6={"0","1","2","3"};
CBInfant = new JComboBox(item6);
LPassengerDetails.setBounds(40,3,100,20);
LAdult.setBounds(40,40,100,20);
CBAdult.setBounds(140,40,100,20);
LChildren.setBounds(40,105,100,20);
CBChildren.setBounds(140,105,100,20);
LInfant.setBounds(40,170,100,20);
CBInfant.setBounds(140,170,100,20);
LImg2.setBounds(16,220,320,200);
LNotes.setBounds(55,240,380,180);
PPanel2.add(LPassengerDetails);
PPanel2.add(LAdult);
PPanel2.add(LChildren);
PPanel2.add(LInfant);
PPanel2.add(CBAdult);
PPanel2.add(CBChildren);
PPanel2.add(CBInfant);
PPanel2.add(LNotes);
PPanel2.add(LImg2);
PPanel2.setBackground(Color.white);
c.add(PPanel2,BorderLayout.EAST);
setSize(795,580);
setVisible(true);
int i = 0;
if(sClass.equals("Economic"))
{
try{
while(i<20)
{
if(type1.row2[i][1].equals(sTo))
{
iPrice =
Integer.parseInt((String)type1.row2[i][2]);
sTime = (String)type1.row2[i][3];
break;
}
i++;
}
}catch(Exception e1)
{
JOptionPane.showMessageDialog(null, "You have no
rights to access");
System.exit(0);
}
}
else
{
try
{
while(i<20)
{
if(type1.row2[i][1].equals(sTo))
{
iPrice =
Integer.parseInt((String)type1.row4[i][2]);
sTime = (String)type1.row4[i][3];
break;
}
i++;
}
}catch(Exception e1)
{
JOptionPane.showMessageDialog(null, "You have no
rights to access it");
System.exit(0);
}
}
type.setTitle(iPrice + " " + sTime);
iPrice = (iPrice*iAdult)+(iPrice*(iChildren/2));
int iCount=0;
int iSeatCount=0;
try
{
//read from data
Save1 save1;
ObjectInputStream OIS1 = new ObjectInputStream(new
FileInputStream("save1"));
do
{
save1 = (Save1)OIS1.readObject();
sTempFrom[iCount] = save1.sFrom;
sTempTo[iCount] = save1.sTo;
sTempClass[iCount] = save1.sClass;
sTempBookingDate[iCount] = save1.sBookingDate;
sTempTime[iCount] = save1.sTime;
iTempAdult[iCount] = save1.iAdult;
iTempChildren[iCount] = save1.iChildren;
iTempInfant[iCount] = save1.iInfant;
iTempPrice[iCount] = save1.iPrice;
iCount++;
if(save1.sBookingDate.equals(sBookingDate))
if(save1.sTo.equals(sTo))
iSeatCount=iSeatCount + save1.iAdult +
save1.iChildren + save1.iInfant;
}while(save1!=null);
OIS1.close();
}
catch(Exception e1)
{
}
iSeatCount = iSeatCount + iAdult + iChildren + iInfant;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
Panel2.setPreferredSize(new Dimension(500,200));
LTitle.setBounds(170,15,500,45);
LFrom.setBounds(20,80,300,20);
LTo.setBounds(20,125,300,20);
LClass.setBounds(20,170,300,20);
LBookingDate.setBounds(20,215,300,20);
LPrice.setBounds(20,260,300,20);
LTime.setBounds(20,305,300,20);
LAdult.setBounds(20,345,300,20);
LChildren.setBounds(20,385,300,20);
LInfant.setBounds(20,430,300,20);
LWishes.setBounds(530,435,300,20);
// LTicketNo.setBounds(320,80,300,20);
// LBookedBy.setBounds(320,125,300,20);
LEmpty.setBounds(3,445,1000,20);
LDemo.setBounds(280,465,300,20);
LRes.setBounds(285,485,300,20);
LFranklin.setBounds(285,505,300,20);
Panel2.add(LTitle);
Panel2.add(LFrom);
Panel2.add(LTo);
Panel2.add(LClass);
Panel2.add(LBookingDate);
Panel2.add(LAdult);
Panel2.add(LChildren);
Panel2.add(LInfant);
Panel2.add(LPrice);
Panel2.add(LTime);
//Panel2.add(LEmpty);
Panel2.add(LWishes);
// Panel2.add(LTicketNo);
// Panel2.add(LBookedBy);
Panel2.add(LEmpty);
Panel2.add(LDemo);
Panel2.add(LRes);
Panel2.add(LFranklin);
Panel2.setBackground(Color.white);
c.add(Panel2, BorderLayout.CENTER);
//pack();
setSize(700,650);
setVisible(true);
}
}
WindowUtilities.java
import javax.swing.*;
import java.awt.*;
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
}catch(Exception e)
{
System.out.println("Error setting native LAF: " + e);
}
}
//UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
//UIManager.setLookAndFeel( "com.sun.java.swing.plaf.motif.MotifLookAndFeel");
}
ExitListener.java
import java.awt.*;
import java.awt.event.*;