Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Name : MUHAMMAD HILMI BIN KAMARUL'AZMI
- Registration Number : 01DDT20F1122
- Class : KHAS5
- */
- import java.awt.*;
- import javax.swing.*;
- public class LT1_01DDT20F1122 extends JFrame {
- private int _xSizePanel = 300;
- private int _ySizePanel = 30;
- private int _xIncrement = 30;
- private String _days = "1-2-3-4-5-6-7-8-9-10-11-12-13-14-15-16-17-18-19-20-21-22-23-24-25-26-27-28-29-30-31";
- private String _months = "January-February-March-April-May-June-July-August-September-October-November-December";
- private String _years = "2022-2023-2024";
- public LT1_01DDT20F1122(){
- // 1 - Title
- JPanel panelLabelTitle = this.addLabel("HOTEL PAK JAGO", 0);
- JLabel lbl = (JLabel) panelLabelTitle.getComponent(0);
- lbl.setFont(new Font("Serif", 1, 30));
- lbl.setForeground(Color.BLUE);
- this.add(panelLabelTitle);
- // 2 - Form Name
- JPanel panelFormName = this.addPanelForm("Name :",0);
- this.add(panelFormName);
- // 3- Form Mobile
- JPanel panelFormMobile = this.addPanelForm("Mobile Number :",0);
- this.add(panelFormMobile);
- // 4 - Form Email
- JPanel panelFormEmail = this.addPanelForm("Email :",0);
- this.add(panelFormEmail);
- // 5 - Date Combo Box
- JPanel panelComboBoxDate = this.addPanelComboBox("Booking Date", String.format("%s/%s/%s ", _days, _months, _years), 0);
- this.add(panelComboBoxDate);
- JPanel panelComboBoxNumber = this.addPanelComboBox("Person", String.format("1-2-3-4-5-6-7-8-9 Max"), 0);
- this.add(panelComboBoxNumber);
- // 6 - Images
- ImageIcon imageIcon = new ImageIcon("C:\\Users\\User\\Downloads\\room.png");
- Image image = imageIcon.getImage();
- Image newimg = image.getScaledInstance(450, 120, java.awt.Image.SCALE_SMOOTH);
- imageIcon = new ImageIcon(newimg);
- JLabel picLabel = new JLabel(imageIcon);
- this.add(picLabel);
- // 7 - Radio Button
- String roomList = "Single Room-RM103-33 Room left!/Double Room-RM250-13 Room left!/Family Room-RM650-12 Room left!/Deluxe Room-RM450-4 Room left!";
- JPanel panelRadioButton = this.addPanelRadioButton("",roomList, 0);
- panelRadioButton.setLayout(new BoxLayout(panelRadioButton,BoxLayout.X_AXIS));
- panelRadioButton.setBorder(BorderFactory.createTitledBorder("Room List"));
- this.add(panelRadioButton);
- //============================= USING BoxLayout inside this.JFrame FlowLayout =============================
- JPanel boxPanel = new JPanel();
- boxPanel.setLayout(new BoxLayout(boxPanel, BoxLayout.Y_AXIS));
- //8 - TextArea Comment
- JPanel panelForm3 = this.addTextArea("Comment :", 0);
- this.add(panelForm3);
- // 9 - Check for agreement
- JPanel panelCheckBoxAgreement = this.addPanelCheckButton("","Accept Terms and Conditions",0);
- boxPanel.add(panelCheckBoxAgreement);
- //10 - button
- JPanel panelAddButton = this.addPanelButton("SUBMIT",0);
- JButton jbtn = (JButton)panelAddButton.getComponent(0);
- boxPanel.add(panelAddButton);
- this.add(boxPanel);
- //============================= INITIALIZATION =============================
- this.endInitialization();
- }
- private void endInitialization() {
- this.setTitle("BOOKING HOTEL PAK JAGO THE GREAT");
- this.setLayout(new FlowLayout());
- this.setDefaultCloseOperation(3);
- this.setSize(500, 650);
- this.getContentPane().setBackground(new Color(255, 252, 187));
- this.setResizable(false);
- this.setVisible(true);
- }
- //============================= REUSEABLE METHOD =============================
- private JPanel addLabel(String name, int xPosition) {
- JPanel panel = new JPanel();
- JLabel label = new JLabel(name);
- panel.add(label);
- this.setPanel(panel, xPosition);
- return panel;
- }
- private JPanel addTextArea(String name, int xPosition) {
- JPanel panel = new JPanel();
- JLabel label = new JLabel(name);
- panel.add(label);
- JTextArea area = new JTextArea("", 5, 31);
- panel.add(area);
- panel.setBackground(new Color(255, 252, 187));
- return panel;
- }
- private JPanel addPanelForm(String name, int xPosition) {
- JPanel panel = new JPanel();
- JLabel label = new JLabel(name);
- panel.add(label);
- JTextField textField = new JTextField(20);
- panel.add(textField);
- this.setPanel(panel, xPosition);
- return panel;
- }
- private JPanel addPanelRadioButton(String name, String buttonList, int xPosition) {
- String[] split = buttonList.split("/");
- JPanel panel = new JPanel();
- JLabel label = new JLabel(name);
- panel.add(label);
- ButtonGroup bg = new ButtonGroup();
- for (String item: split) {
- String[] split2 = item.split("-");
- JRadioButton r1 = new JRadioButton("<html>" + split2[0] + "<br/>" + split2[1] + "<br/>" + split2[2] + "</html>");
- bg.add(r1);
- r1.setBackground(new Color(255, 252, 187));
- panel.add(r1);
- }
- this.setPanel(panel, xPosition);
- return panel;
- }
- private JPanel addPanelComboBox(String name, String comboBoxList, int xPosition)
- {
- String[] split = comboBoxList.split("/");
- JPanel panel = new JPanel();
- JLabel label = new JLabel(name);
- panel.add(label);
- for (String item: split) {
- String[] item2 = item.split("-");
- JComboBox cb=new JComboBox(item2);
- panel.add(cb);
- }
- panel.setLayout(new FlowLayout());
- return panel;
- }
- private JPanel addPanelCheckButton(String name, String buttonList, int xPosition) {
- String[] split = buttonList.split("/");
- JPanel panel = new JPanel();
- JLabel label = new JLabel(name);
- panel.add(label);
- for (String item: split) {
- JCheckBox checkBox = new JCheckBox(item);
- checkBox.setBackground(new Color(255, 252, 187));
- panel.add(checkBox);
- }
- panel.setBackground(new Color(255, 252, 187));
- panel.setBounds(0,xPosition * _xIncrement, _xSizePanel, 60);
- panel.setLayout(new FlowLayout());
- return panel;
- }
- private JPanel addPanelButton(String buttonList, int xPosition) {
- JPanel panel = new JPanel();
- String[] split = buttonList.split("-");
- for (String item: split) {
- JButton button = new JButton(item);
- panel.add(button);
- }
- this.setPanel(panel, xPosition);
- return panel;
- }
- private void setPanel(JPanel panel, int xPosition) {
- panel.setBackground(new Color(255, 252, 187));
- panel.setBounds(0,
- xPosition * _xIncrement, _xSizePanel, _ySizePanel);
- panel.setLayout(new FlowLayout());
- }
- //============================= MAIN METHOD =============================
- public static void main(String args[]) {
- new LT1_01DDT20F1122();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement