Click here to Skip to main content
15,885,941 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
public class AddRecord extends JFrame implements ActionListener{
    
    JLabel titleLabel = new JLabel("Add Record");
    
    //INFO
    JLabel nameLabel = new JLabel("Name:");
    JTextField nameTextField = new JTextField("");
    JLabel IdLabel = new JLabel("Booking ID:");
    JTextField IdTextField = new JTextField("");
    JLabel phoneNumLabel = new JLabel("Phone Number:");
    JTextField phoneNumTextField = new JTextField("");
    JLabel paxNumLabel = new JLabel("Pax Number(Maximum 20):");
    JTextField paxNumTextField = new JTextField("");
    JLabel roomNumLabel = new JLabel("Room Number(Between 100-999):");
    JTextField roomNumTextField = new JTextField("");
    JLabel roomTypeLabel = new JLabel("Room Type:");
    JComboBox roomTypeComboBox = new JComboBox();
    JLabel dateLabel = new JLabel("Date(dd/mm/yy):");
    JTextField dateTextField = new JTextField("");
    JLabel timeLabel = new JLabel("Time:");
    JComboBox timeComboBox = new JComboBox();
    
    JButton addBtn= new JButton("Add");
    JButton cancelBtn = new JButton("Cancel");
     
    public static void main(String[] args) {
        AddRecord jf = new AddRecord();
    }
    
    public AddRecord(){
        getContentPane().setBackground(Color.black);
        setTitle("Karaoke System");
        setSize(500, 500);

        Font f = new Font("Serif", Font.PLAIN,18);
        
        //ADD RECORD PROPERTIES
        titleLabel.setFont(new Font("Serif", Font.BOLD, 24));
        titleLabel.setBounds(180,30,150,20);
        titleLabel.setForeground(Color.WHITE);
        
        //NAME PROPERTIES
        nameLabel.setFont(f);
        nameLabel.setBounds(30,80,80,25);
        nameLabel.setForeground(Color.WHITE);
        
        nameTextField.setFont(f);
        nameTextField.setBounds(80,80,180,25);
        nameTextField.setBackground(Color.white);
        nameTextField.setForeground(Color.BLACK);
        
        //BOOKING ID PROPERTIES
        IdLabel.setFont(f);
        IdLabel.setBounds(280,80,150,25);
        IdLabel.setForeground(Color.WHITE);
        
        IdTextField.setFont(f);
        IdTextField.setBounds(375,80,80,25);
        IdTextField.setBackground(Color.white);
        IdTextField.setForeground(Color.BLACK);
        IdTextField.addKeyListener(new KeyAdapter(){
            public void keyTyped(KeyEvent e){
                char input = e.getKeyChar();
                if((input < '0' || input >  '9') && input != '\b'){
                    e.consume();
                    JOptionPane.showMessageDialog(null,"Invalid input!");
                }
            }
        });
        
        //PHONENUM PROPERTIES
        phoneNumLabel.setFont(f);
        phoneNumLabel.setBounds(30,120,150,25);
        phoneNumLabel.setForeground(Color.WHITE);
        
        phoneNumTextField.setFont(f);
        phoneNumTextField.setBounds(150,120,150,25);
        phoneNumTextField.setBackground(Color.white);
        phoneNumTextField.setForeground(Color.BLACK);
        phoneNumTextField.addKeyListener(new KeyAdapter(){
            public void keyTyped(KeyEvent e){
                char input = e.getKeyChar();
                if((input < '0' || input >  '9') && input != '\b'){
                    e.consume();
                    JOptionPane.showMessageDialog(null,"Invalid input!Please enter number only!");
                }
            }
        });
        
        //PAXNUM PROPERTIES
        paxNumLabel.setFont(f);
        paxNumLabel.setBounds(30,160,250,25);
        paxNumLabel.setForeground(Color.WHITE);
        
        paxNumTextField.setFont(f);
        paxNumTextField.setBounds(240,160,50,25);
        paxNumTextField.setBackground(Color.white);
        paxNumTextField.setForeground(Color.BLACK);
        paxNumTextField.addKeyListener(new KeyAdapter(){
            public void keyTyped(KeyEvent e){
                char input = e.getKeyChar();
                if((input < '0' || input >  '9') && input != '\b'){
                    e.consume();
                    JOptionPane.showMessageDialog(null,"Invalid input!Please enter number only!");
                }
            }
        });
        
        //ROOMNUM PROPERTIES
        roomNumLabel.setFont(f);
        roomNumLabel.setBounds(30,200,300,25);
        roomNumLabel.setForeground(Color.WHITE);
        
        roomNumTextField.setFont(f);
        roomNumTextField.setBounds(290,200,80,25);
        roomNumTextField.setBackground(Color.white);
        roomNumTextField.setForeground(Color.BLACK);
        roomNumTextField.addKeyListener(new KeyAdapter(){
            public void keyTyped(KeyEvent e){
                char input = e.getKeyChar();
                if((input < '0' || input >  '9') && input != '\b'){
                    e.consume();
                    JOptionPane.showMessageDialog(null,"Invalid input!Please enter number only!");
                }
            }
        });
        
        //ROOMTYPE PROPERTIES
        roomTypeLabel.setFont(f);
        roomTypeLabel.setBounds(30,240,120,25);
        roomTypeLabel.setForeground(Color.WHITE);
        
        roomTypeComboBox.setFont(f);
        roomTypeComboBox.setBounds(130,240,220,25);  
        roomTypeComboBox.setBackground(Color.white);
        roomTypeComboBox.setForeground(Color.BLACK);
        
        //DATE PROPERTIES
        dateLabel.setFont(f);
        dateLabel.setBounds(30,280,160,25);
        dateLabel.setForeground(Color.WHITE);
        
        dateTextField.setFont(f);
        dateTextField.setBounds(160,280,100,25);
        dateTextField.setBackground(Color.white);
        dateTextField.setForeground(Color.BLACK);    
        
        //TIME PROPERTIES
        timeLabel.setFont(f);
        timeLabel.setBounds(30,320,100,25);
        timeLabel.setForeground(Color.WHITE);
        
        timeComboBox.setFont(f);
        timeComboBox.setBounds(80,320,170,25);
        timeComboBox.setBackground(Color.white);
        timeComboBox.setForeground(Color.BLACK);
        
        //ADD BUTTON PROPERTIES
        addBtn.setFont(f);
        addBtn.setBounds(250,400,100,30);
        addBtn.setBackground(Color.white);
        addBtn.setForeground(Color.BLACK);
        
        //CANCEL BUTTON PROPERTIES
        cancelBtn.setFont(f);
        cancelBtn.setBounds(370,400,100,30);
        cancelBtn.setBackground(Color.white);
        cancelBtn.setForeground(Color.BLACK);
        
        add(titleLabel);
        
        add(nameLabel);
        add(nameTextField);
        
        add(IdLabel);
        add(IdTextField);
        
        add(phoneNumLabel);
        add(phoneNumTextField);
        
        add(paxNumLabel);
        add(paxNumTextField);
   
        add(roomNumLabel);
        add(roomNumTextField);
     
        roomTypeComboBox.addItem("Mini KBox(1-3 person)");
        roomTypeComboBox.addItem("Standard(4-6 person)");
        roomTypeComboBox.addItem("Platinum(7-10 person)");
        roomTypeComboBox.addItem("VIP(11-20 person)");
        add(roomTypeLabel);
        add(roomTypeComboBox);
        
        add(dateLabel);
        add(dateTextField);
    
        timeComboBox.addItem("A.M.(9am-11am)");
        timeComboBox.addItem("A.M.(11am-1pm)");
        timeComboBox.addItem("P.M.(1pm-3pm)");
        timeComboBox.addItem("P.M.(3pm-5pm)");
        timeComboBox.addItem("P.M.(5pm-7pm)");
        timeComboBox.addItem("P.M.(7pm-9pm)");
        timeComboBox.addItem("P.M.(9pm-11pm)");
        
        add(timeLabel);
        add(timeComboBox);
        
        //ADD BUTTON FUNCTION
        add(addBtn);
        addBtn.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                
                String Id = IdTextField.getText();
                String name = nameTextField.getText();
                String phoneNum = phoneNumTextField.getText();
                String paxNum = paxNumTextField.getText();
                String roomNum = roomNumTextField.getText();
                String roomType = (String)roomTypeComboBox.getSelectedItem();
                String date = dateTextField.getText();
                String time = (String)timeComboBox.getSelectedItem();
                
                ViewAll all = new ViewAll();
                all.setVisible(true);
            }
        });
    
        //BACK BUTTON FUNCTION
        add(cancelBtn);
        cancelBtn.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
                KaraokeMainSystem main = new KaraokeMainSystem();
                main.setVisible(true);   
            }
        });
 
        setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);
    }
 
 
    public void actionPerformed(ActionEvent e){
        
    }  
}


What I have tried:

public class ViewAll extends JFrame implements ActionListener{
    
    //DISPLAY
    JTextArea allRecords = new JTextArea("");
    
    public static void main(String[] args) {
        ViewAll all = new ViewAll();
    }
    public void viewAll(String name){
        allRecords.setText(name);
    }
    
    public ViewAll(){
        getContentPane().setBackground(Color.black);
        setTitle("Karaoke System");
        setSize(500, 500);   
 
        allRecords.setFont(new Font("Serif", Font.PLAIN, 12));
        allRecords.setBounds(30,15,430,430);
        allRecords.setBackground(Color.white);
        allRecords.setForeground(Color.BLACK);
        allRecords.setEditable(false);
        add(allRecords);
        
        setLayout(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);
        setVisible(true);
    }
    
    
    public void actionPerformed(ActionEvent e){

    } 
}
Posted
Updated 25-Mar-20 3:04am
Comments
Richard MacCutchan 22-Mar-20 11:27am    
You must pass the location of the records to the second form.

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900