Java

profileMaha
FlightApp.java

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.awt.Font; import javax.swing.JToolTip; import java.awt.Color; import java.io.*; public class FlightApp extends JFrame implements ActionListener { JTextField pname ,seat,price; JComboBox firstclass ; JRadioButton one , two ; ButtonGroup buttongroup ; JPanel first , second , third ; JLabel l1 ,l2,l3,l4,l5,l6,l7; Font font1 , font2; JButton button1,button2,button3; public FlightApp() { setLayout(new FlowLayout()); font1 = new Font("Times New Romman", Font.PLAIN, 19); font2 = new Font("Arial" , Font.BOLD , 22); price= new JTextField(12); String flightClass[] = {"First Class","Business Class","Economy Class"}; firstclass =new JComboBox(flightClass) ; one = new JRadioButton("One Way"); two = new JRadioButton("Two Way"); buttongroup = new ButtonGroup(); first= new JPanel( new GridLayout(5,2)); // flight Panel second= new JPanel( new FlowLayout()); // group Panel third= new JPanel( new FlowLayout()); //Button Panel button1 = new JButton("New",new ImageIcon("new2.jpg")); // new Button button1.setToolTipText("the button New"); button2 = new JButton("Calculate",new ImageIcon("calcu2.png")); // calc Button button2.setToolTipText("the button Calculate"); button3= new JButton("Exit",new ImageIcon("exit.jpg")); //exit Button button3.setToolTipText("the button Exit"); l1 = new JLabel("Class : "); l1.setForeground(Color.BLUE); l1.setFont(font2); first.add(l1); firstclass.addActionListener(this); first.add(firstclass); l2 = new JLabel("Direction : "); l2.setForeground(Color.BLUE); l2.setFont(font2); second.add(l2); add(second); buttongroup.add(one); one.setActionCommand("One Way"); buttongroup.add(two); one.setBackground(Color.YELLOW); two.setSelected(true); two.setBackground(Color.YELLOW); two.setActionCommand("Two Way"); second.add(one); second.add(two); l3 = new JLabel("Name : "); l3.setForeground(Color.BLUE); l3.setFont(font2); first.add(l3); pname= new JTextField(17); first.add(pname); l4 = new JLabel("Seats : "); l4.setForeground(Color.BLUE); l4.setFont(font2); first.add(l4); seat= new JTextField(12); first.add(seat); seat.setText(""); price.setFont(font1); price.setForeground(Color.RED); price.setText(""); add(first,BorderLayout.CENTER); button1.addActionListener(this); third.add(button1); button2.addActionListener(this); third.add(button2); button3.addActionListener(this); third.add(button3); add(third,BorderLayout.SOUTH); first.setBackground(Color.YELLOW); second.setBackground(Color.YELLOW); third.setBackground(Color.YELLOW); } public void actionPerformed(ActionEvent e) { try { String k = e.getActionCommand(); if(k.equals("New")) { pname.setText(""); seat.setText(""); price.setText(""); l6.setText(""); } if(k.equals("Calculate")) { String fclass2 = (String)firstclass.getSelectedItem(); String way2 = buttongroup.getSelection().getActionCommand(); int seat2=Integer.parseInt(seat.getText()); if( seat2<=0 ) throw new IOException("seat number should not be negative or zero"); else { passenger=new Passenger(pname.getText(),fclass2,seat2,way2); price.setText(passenger.GetPrice()+""); l6.setText(passenger.GetPassenger()); } } if(k.equals("Exit")) { System.exit(0); } } catch(IOException e1) { l6.setText(e1.getMessage()); } catch(Exception excep) { JOptionPane.showMessageDialog(null,"Please enter seats number"); } } public static void main(String[] args) { FlightApp fly=new FlightApp(); fly.setLocationRelativeTo(null); fly.setVisible(true); } }