import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Project1_JaneShteyn
{
public static void main (String[] args)
{
// creates and presents the program frame
JFrame frame = new JFrame ("Today's Available Delta Flights From ATL to JFK");
frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
FlightOptionsPanel panel = new FlightOptionsPanel();
frame.getContentPane().add (panel);
frame.pack();
frame.setVisible(true);
}
}
public class Project1_JaneShteyn extends JPanel
{
private JLabel flights;
private JRadioButton flight123, flight456, flight789;
private String flight123Seats, flight456Seats, flight789Seats;
public FlightOptionsPanel()
{
flight123Seats = "Departing at 3pm, 6 available seats";
flight456Seats = "Departing at 4pm, 6 available seats";
flight789Seats = "Departing at 5pm, 6 available seats";
flight = new JLabel (flight123Seats);
flight.setFont (new Font ("Helvetica", Font.BOLD, 24));
flight123 = new JRadioButton ("Flight 123, true");
flight123.setBackground (Color.magenta);
flight456 = new JRadioButton ("Flight 456");
flight456.setBackground (Color.magenta);
flight789 = new JRadioButton ("Flight 789");
flight789.setBackground (Color.magenta);
ButtonGroup group = new ButtonGroup();
group.add (flight123);
group.add (flight456);
group.add (flight789);
FlightListener listener = new FlightListener();
flight123.addActionListener (listener);
flight456.addActionListener (listener);
flight789.addActionListener (listener);
add (flight123);
add (flight456);
add (flight789);
setBackground (Color.green);
setPreferredSize (new Dimension(300,100));
}
private class FlightListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
Object source = event.getSource();
if (sourse == flights)
flights.setText (flight123Seats);
else
if (source == flights)
flights.setText (flight456Seats);
else
flights.setText (flight789);
}
}
}