Wednesday, November 22, 2006

Practical 08 Question 1


//(a)Import all relevant packages
import javax.swing.*;
import java.awt.*; // Layout

/*(b)Write the codes to specify
TourBookingFrame as the subclass of JFrame.*/
public class TourBookingFrame extends JFrame{

private ButtonGroup buttongroup;
/*(c)Declare all the components in the JFrame
*/
private JLabel welcomeLbl;
private JTextArea detailsTxt;
private JRadioButton memberBtn, nonMemberBtn;
private JButton submitBtn, resetBtn;
// (d)Declare all the JPanels
private JPanel northPanel, centerPanel, southPanel;

public TourBookingFrame(){
//(e)Create northPanel and welcomeLbl.
// Add welcomeLbl to northPanel
northPanel = new JPanel();
welcomeLbl = new JLabel("Welcome to Tour Booking"
+ " System, enter your booking"
+ " details below");
northPanel.add(welcomeLbl);

// f) Create centerPanel and detailsTxt.
// Add detailsTxt to centerPanel.
// detailsTxt should be 10 rows 40 columns wide.
centerPanel = new JPanel();
detailsTxt = new JTextArea(10,40);
centerPanel.add(detailsTxt);

// (g) Create southPanel & component(s) in southPanel.
// Add the component(s) to southPanel.
southPanel = new JPanel();
memberBtn = new JRadioButton("Member");
nonMemberBtn = new JRadioButton("Non-member");
submitBtn = new JButton("Submit");
resetBtn = new JButton("Reset");
southPanel.add(memberBtn);
southPanel.add(nonMemberBtn);
southPanel.add(submitBtn);
southPanel.add(resetBtn);

buttongroup = new ButtonGroup();
buttongroup.add(memberBtn);
buttongroup.add(nonMemberBtn);

//(h)Which Layout Manager would the JFrame be using?
// Add all the JPanels to the respective areas of
//the content Pane of the JFrame.
getContentPane().add(northPanel, BorderLayout.NORTH);
getContentPane().add(centerPanel, BorderLayout.CENTER);
getContentPane().add(southPanel, BorderLayout.SOUTH);

} //end constructor

}//end class

No comments: