0

I am trying to create a professional login / registration form and at the minute I have this code that is not working: It is going to be for a FPL Forum I am creating through NetBeans.

Any help on the subject would be much appreciated.

    package fplforum;

import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;

import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

public class RegistrationForm extends JFrame implements ActionListener {
    public RegistrationPanel panel;
    public JButton submit, cancel;
    public boolean done;
    public Object UITools;

    public RegistrationForm() {
        JPanel main = new JPanel();
        main.setLayout(new BorderLayout());
        main.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10));

        JLabel label = new JLabel("Java CoG Kit Registration");
        label.setFont(Font.decode("Arial-bold-18"));
        label.setBorder(BorderFactory.createEmptyBorder(5, 10, 20, 10));

        main.add(label, BorderLayout.NORTH);

        panel = new RegistrationPanel();
        //panel.getReregister().addActionListener(this);
        //main.add(panel, BorderLayout.CENTER);
        setTitle("Java CoG Kit Registration Form");

        JPanel buttons = new JPanel();
        buttons.setLayout(new FlowLayout());

        submit = new JButton("Submit");
        submit.addActionListener(this);
        buttons.add(submit);

        //submit.setEnabled(panel.getReregister().isSelected());

        cancel = new JButton("Cancel");
        cancel.addActionListener(this);
        buttons.add(cancel);

        main.add(buttons, BorderLayout.SOUTH);

        getContentPane().add(main);
    }

        @Override
    public void actionPerformed(ActionEvent e) {
        if (e.getSource() == submit) {
            try {
                panel.submit(false);
                JOptionPane.showMessageDialog(this, "Thank you for registering the Java CoG Kit",
                        "Registration successful", JOptionPane.INFORMATION_MESSAGE);
                done();
            }
            catch (IOException e1) {
                JOptionPane.showMessageDialog(this, "Could not submit registration information: "
                        + e.toString(), "Error", JOptionPane.ERROR_MESSAGE);
            }
        }
        else if (e.getSource() == cancel) {
            done();
        }
        else {
            //must be the don't send switch
            submit.setEnabled(panel.getReregister().isSelected());
        }
    }

    private void done() {
        done = true;
        synchronized (this) {
            notify();
        }
    }

    public void run() {
        setSize(500, 380);
        UITools.left(null, this);
        setVisible(true);
        try {
            synchronized (this) {
                while (!done) {
                    wait();
                }
            }
        }
        catch (InterruptedException e) {
            JOptionPane.showMessageDialog(this, "The main thread was interrupted", "Error",
                    JOptionPane.ERROR_MESSAGE);
        }
        setVisible(false);
        dispose();
    }

    public static void main(String[] args) {
        //RegistrationFrame frame = new RegistrationFrame();
        //frame.run();
        //System.exit(0);
    }

    private static class RegistrationPanel {

        public RegistrationPanel() {
        }

        private Object getReregister() {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }

        private void submit(boolean b) {
            throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
        }
    }
}

It will compile but nothing happens, how do I fix it?

Aaron Boyse
  • 3
  • 1
  • 2
  • *"I am trying to create a professional login / registration form.."* BTW - use a modal `JDialog` for this, rather than ..whatever that code was attempting in order to achieve modality. – Andrew Thompson Dec 21 '15 at 18:15

1 Answers1

1

If it compiles and executes, then it works. It does not work as you want it to work, but it surely works. You have an empty main method, so it will not do anything. This is your main method:

public static void main(String[] args) {
    //RegistrationFrame frame = new RegistrationFrame();
    //frame.run();
    //System.exit(0);
}

All the lines are commented out, so there are no operations to execute. Take out the // at the start of your lines to have some action. Also, as far as I know, you do not have a RegistrationFrame class, you might want to instantiate RegistrationForm instead. Also, why do you call System.exit(0) ?

Lajos Arpad
  • 64,414
  • 37
  • 100
  • 175
  • It is now outputting this comment: Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - Erroneous sym type: java.lang.Object.left at fplforum.RegistrationForm.run(RegistrationForm.java:89) at fplforum.RegistrationForm.main(RegistrationForm.java:108) Java Result: 1 – Aaron Boyse Dec 21 '15 at 15:55