
Hi pls help im stuck, my program wont run. thank you.
/********************/
/* UsingBoxLayout */
/* */
/********************/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* Summary description for UsingBoxLayout
*
*/
public class Ceeda3 extends JFrame
{
// Variables declaration
private JLabel labH1;
private JLabel labH2;
private JLabel labH3;
private JLabel labH4;
private JLabel labH5;
private JLabel labV1;
private JPanel contentPane;
//-----
private JPanel pnlCenterBoxLayout;
//-----
private JButton btnOK;
private JButton btnCancel;
private JButton btnApply;
private JPanel pnlBottomFlowLayout;
//-----
private JLabel jLabel1;
private JTextField txfID;
private JPanel pnlID;
//-----
private JLabel jLabel2;
private JTextField txfSurname;
private JPanel pnlSurname;
//-----
private JLabel jLabel3;
private JTextField txfFirstname;
private JPanel pnlFirstname;
//-----
private JLabel jLabel4;
private JTextField txfEmail;
private JPanel pnlEmail;
//-----
//-----
private JLabel jLabel5;
private JTextField txfCellphone;
private JPanel pnlCellphone;
//-----
//-----
private JLabel jLabel6;
private JRadioButton rbtnMale;
private JRadioButton rbtnFemale;
private JPanel pnlSex;
//-----
private JLabel jLabel7;
private JComboBox cmbRaceGroup;
private JPanel pnlRace;
//-----
private JLabel jLabel8;
private JTextField txfPermanentAddress;
private JPanel pnlPermanentAddress;
//-----
private JLabel jLabel9;
private JTextField txfCurrentAddress;
private JPanel pnlCurrentAddress;
//-----
private ButtonGroup btnGroup_Sex;
// End of variables declaration
public Ceeda3()
{
super();
initializeComponent();
//
// TODO: Add any constructor code after initializeComponent call
//
this.setVisible(true);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always regenerated
* by the Windows Form Designer. Otherwise, retrieving design might not work properly.
* Tip: If you must revise this method, please backup this GUI file for JFrameBuilder
* to retrieve your design properly in future, before revising this method.
*/
private void initializeComponent()
{
labH1 = new JLabel();
labH2 = new JLabel();
labH3 = new JLabel();
labH4 = new JLabel();
labH5 = new JLabel();
labV1 = new JLabel();
contentPane = (JPanel)this.getContentPane();
//-----
pnlCenterBoxLayout = new JPanel();
//-----
btnOK = new JButton();
btnCancel = new JButton();
btnApply = new JButton();
pnlBottomFlowLayout = new JPanel();
//-----
jLabel1 = new JLabel();
txfID = new JTextField();
pnlID = new JPanel();
//-----
//-----
jLabel2 = new JLabel();
txfSurname = new JTextField();
pnlSurname = new JPanel();
//-----
jLabel3 = new JLabel();
txfFirstname = new JTextField();
pnlFirstname = new JPanel();
//-----
jLabel4 = new JLabel();
txfEmail = new JTextField();
pnlEmail = new JPanel();
//-----
jLabel5 = new JLabel();
txfCellphone = new JTextField();
pnlCellphone= new JPanel();
//-----
jLabel6 = new JLabel();
rbtnMale = new JRadioButton();
rbtnFemale = new JRadioButton();
pnlSex = new JPanel();
//-----
jLabel7 = new JLabel();
cmbRaceGroup = new JComboBox();
pnlRace = new JPanel();
//-----
jLabel8 = new JLabel();
txfPermanentAddress = new JTextField();
pnlPermanentAddress = new JPanel();
//-----
jLabel9 = new JLabel();
txfCurrentAddress = new JTextField();
pnlCurrentAddress = new JPanel();
//-----
btnGroup_Sex = new ButtonGroup();
//
// labH1
//
labH1.setToolTipText("This empty label is used for Horizontal Gap Setting of BorderLayout to be effective, if necessarily.");
//
// labH2
//
labH1.setToolTipText("This empty label is used for Horizontal Gap Setting of BorderLayout to be effective, if necessarily.");
//
// labH3
//
labH1.setToolTipText("This empty label is used for Horizontal Gap Setting of BorderLayout to be effective, if necessarily.");
//
// labH4
//
labH1.setToolTipText("This empty label is used for Horizontal Gap Setting of BorderLayout to be effective, if necessarily.");
//
// labH5
//
labH2.setToolTipText("This empty label is used for Horizontal Gap Setting of BorderLayout to be effective, if necessarily.");
//
// labV1
//
labV1.setToolTipText("This empty label is used for Vertical Gap Setting of BorderLayout to be effective, if necessarily.");
//
// contentPane
//
contentPane.setLayout(new BorderLayout(10, 10));
contentPane.add(pnlCenterBoxLayout, BorderLayout.CENTER);
contentPane.add(pnlBottomFlowLayout, BorderLayout.SOUTH);
contentPane.add(labH1, BorderLayout.WEST);
contentPane.add(labH2, BorderLayout.EAST);
contentPane.add(labH3, BorderLayout.WEST);
contentPane.add(labH4, BorderLayout.SOUTH);
contentPane.add(labH5, BorderLayout.EAST);
contentPane.add(labV1, BorderLayout.NORTH);
//
// pnlCenterBoxLayout
//
pnlCenterBoxLayout.setLayout(new BoxLayout(pnlCenterBoxLayout, BoxLayout.Y_AXIS));
pnlCenterBoxLayout.add(pnlID, 1);
pnlCenterBoxLayout.add(pnlSurname, 2);
pnlCenterBoxLayout.add(pnlFirstname, 3);
pnlCenterBoxLayout.add(pnlEmail, 4);
pnlCenterBoxLayout.add(pnlCellphone, 5);
pnlCenterBoxLayout.add(pnlSex, 6);
pnlCenterBoxLayout.add(pnlRace, 7);
pnlCenterBoxLayout.add(pnlPermanentAddress, 8);
pnlCenterBoxLayout.add(pnlCurrentAddress, 9);
pnlCenterBoxLayout.setBorder(BorderFactory.createEtchedBorder());
pnlCenterBoxLayout.setToolTipText("This JPanel is using BoxLayout manager.");
//
// btnOK
//
btnOK.setText(" OK ");
btnOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnOK_actionPerformed(e);
}
});
//
// btnCancel
//
btnCancel.setText(" Cancel ");
btnCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnCancel_actionPerformed(e);
}
});
//
// btnApply
//
btnApply.setText(" Apply ");
btnApply.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
btnApply_actionPerformed(e);
}
});
//
// pnlBottomFlowLayout
//
pnlBottomFlowLayout.setLayout(new FlowLayout(FlowLayout.CENTER, 6, 5));
pnlBottomFlowLayout.add(btnOK, 0);
pnlBottomFlowLayout.add(btnCancel, 1);
pnlBottomFlowLayout.add(btnApply, 2);
pnlBottomFlowLayout.setToolTipText("This JPanel is using FlowLayout manager.");
//
// jLabel1
//
jLabel1.setText("ID no.:");
jLabel1.setPreferredSize(new Dimension(106, 22));
//
// txfID
//
txfID.setColumns(20);
txfID.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
txfID_actionPerformed(e);
}
});
//
// pnlID
//
pnlID.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlID.add(jLabel1, 0);
pnlID.add(txfID, 1);
//
// jLabel2
//
jLabel2.setText("Surname:");
jLabel2.setPreferredSize(new Dimension(106, 22));
//
// txfSurname
//
txfSurname.setColumns(20);
txfSurname.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
txfSurname_actionPerformed(e);
}
});
//
// pnlSurname
//
pnlSurname.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlSurname.add(jLabel2, 0);
pnlSurname.add(txfSurname, 1);
//
// jLabel3
//
jLabel3.setText("Firstname:");
jLabel3.setPreferredSize(new Dimension(106, 22));
//
// txfFirstname
//
txfFirstname.setColumns(20);
txfFirstname.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
txfFirstname_actionPerformed(e);
}
});
//
// pnlFirstname
//
pnlFirstname.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlFirstname.add(jLabel3, 0);
pnlFirstname.add(txfFirstname, 1);
//
// jLabel4
//
jLabel4.setText("Email Address:");
jLabel4.setPreferredSize(new Dimension(106, 22));
//
// txfEmail
//
txfEmail.setColumns(20);
txfEmail.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
txfEmail_actionPerformed(e);
}
});
//
// pnlEmail
//
pnlEmail.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlEmail.add(jLabel4, 0);
pnlEmail.add(txfEmail, 1);
//
// jLabel5
//
jLabel5.setText("Cellphone:");
jLabel5.setPreferredSize(new Dimension(106, 22));
//
// txfCellphone
//
txfCellphone.setColumns(20);
txfCellphone.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
txfCellphone_actionPerformed(e);
}
});
//
// pnlCellphone
//
pnlCellphone.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlCellphone.add(jLabel5, 0);
pnlCellphone.add(txfCellphone, 1);
//
// jLabel6
//
jLabel6.setText("Sex:");
jLabel6.setPreferredSize(new Dimension(106, 22));
//
// rbtnMale
//
rbtnMale.setText("Male");
rbtnMale.setSelected(true);
rbtnMale.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e)
{
rbtnMale_itemStateChanged(e);
}
});
//
// rbtnFemale
//
rbtnFemale.setText("Female");
rbtnFemale.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e)
{
rbtnFemale_itemStateChanged(e);
}
});
//
// pnlSex
//
pnlSex.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlSex.add(jLabel6, 0);
pnlSex.add(rbtnMale, 1);
pnlSex.add(rbtnFemale, 2);
//
// jLabel7
//
jLabel7.setText("Age:");
jLabel7.setPreferredSize(new Dimension(106, 22));
//
// cmbAgeGroup
//
cmbRaceGroup.addItem("Select race");
cmbRaceGroup.addItem("Black");
cmbRaceGroup.addItem("Coloured");
cmbRaceGroup.addItem("White");
cmbRaceGroup.addItem("Asian");
cmbRaceGroup.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
cmbAgeGroup_actionPerformed(e);
}
});
//
// pnlAge
//
pnlRace.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlRace.add(jLabel7, 0);
pnlRace.add(cmbRaceGroup, 1);
//
// jLabel8
//
jLabel8.setText("Permanent Address:");
jLabel8.setPreferredSize(new Dimension(106, 22));
//
// txfPermanentAddress
//
txfPermanentAddress.setColumns(20);
txfPermanentAddress.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
txfPermanentAddress_actionPerformed(e);
}
});
//
// pnlPermanentAddress
//
pnlPermanentAddress.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlPermanentAddress.add(jLabel8, 0);
pnlPermanentAddress.add(txfPermanentAddress, 1);
//
// jLabel9
//
jLabel9.setText("Current Address:");
jLabel9.setPreferredSize(new Dimension(106, 22));
//
// txfCurentAddress
//
txfCurrentAddress.setColumns(20);
txfCurrentAddress.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
txfCurrentAddress_actionPerformed(e);
}
});
//
// pnlCurrentAddress
//
pnlCurrentAddress.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 5));
pnlCurrentAddress.add(jLabel9, 0);
pnlCurrentAddress.add(txfCurrentAddress, 1);
//
// btnGroup_Sex
//
btnGroup_Sex.add(rbtnFemale);
btnGroup_Sex.add(rbtnMale);
//
// UsingBoxLayout
//
this.setTitle("Application Form");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(815, 543));
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
//
// TODO: Add any appropriate code in the following Event Handling Methods
//
private void btnOK_actionPerformed(ActionEvent e)
{
System.out.println("\nbtnOK_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void btnCancel_actionPerformed(ActionEvent e)
{
System.out.println("\nbtnCancel_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void btnApply_actionPerformed(ActionEvent e)
{
System.out.println("\nbtnApply_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void txfID_actionPerformed(ActionEvent e)
{
System.out.println("\ntxfID_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void txfSurname_actionPerformed(ActionEvent e)
{
System.out.println("\ntxfSurname_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void txfFirstname_actionPerformed(ActionEvent e)
{
System.out.println("\ntxfFirstname_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void txfEmail_actionPerformed(ActionEvent e)
{
System.out.println("\ntxfEmail_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void txfCellphone_actionPerformed(ActionEvent e)
{
System.out.println("\ntxfCellphone_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void rbtnMale_itemStateChanged(ItemEvent e)
{
System.out.println("\nrbtnMale_itemStateChanged(ItemEvent e) called.");
System.out.println(">>" + ((e.getStateChange() == ItemEvent.SELECTED) ? "selected":"unselected"));
// TODO: Add any handling code here
}
private void rbtnFemale_itemStateChanged(ItemEvent e)
{
System.out.println("\nrbtnFemale_itemStateChanged(ItemEvent e) called.");
System.out.println(">>" + ((e.getStateChange() == ItemEvent.SELECTED) ? "selected":"unselected"));
// TODO: Add any handling code here
}
private void cmbAgeGroup_actionPerformed(ActionEvent e)
{
System.out.println("\ncmbAgeGroup_actionPerformed(ActionEvent e) called.");
Object o = cmbRaceGroup.getSelectedItem();
System.out.println(">>" + ((o==null)? "null" : o.toString()) + " is selected.");
// TODO: Add any handling code here for the particular object being selected
}
private void txfPermanentAddress_actionPerformed(ActionEvent e)
{
System.out.println("\ntxfPermanentAddress_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
private void txfCurrentAddress_actionPerformed(ActionEvent e)
{
System.out.println("\ntxfCurrentaddress_actionPerformed(ActionEvent e) called.");
// TODO: Add any handling code here
}
//
// TODO: Add any method code to meet your needs in the following area
//
//============================= Testing ================================// //= =// //= The following main method is just for testing this class you built.=// //= After testing,you may simply delete it. =// //======================================================================// public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ex) { System.out.println("Failed loading L&F: "); System.out.println(ex); } new Ceeda3(); } //= End of Testing =
}
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.