I am using Java to create a gui and so far I have everything working.
But there is a section of code thats not working out and Ill post the whole file here (not very big) to let you guys see whats going on. The issue lies in the action listner where I state "if a text feild is empty, display the option pane, else show the following" and its not showing the labels and buttons.
Help?
package student.information.search;
import javax.swing.JFrame;
import java.awt.GridBagLayout;
import javax.swing.WindowConstants;
import java.awt.Rectangle;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import java.awt.ActiveEvent;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JTextField;
import javax.swing.JButton;
import student.information.readonly.ReadOnlyStudentForm;
public class StudentSearch extends Frame implements ActionListener
{
JTextField textField = new JTextField();
JFrame frame = new JFrame();
JPanel contentPane = (JPanel) frame.getContentPane();
GridBagLayout gridBagLayout = new GridBagLayout();
public StudentSearch()
{
gridBagLayout.columnWidths = new int[]{20, 0, 12, 137, 17};
gridBagLayout.rowHeights = new int[]{26, 0, 6, 0, 20};
gridBagLayout.columnWeights = new double[]{1, 0, 0, 0, 0};
gridBagLayout.rowWeights = new double[]{0, 0, 0, 0, 1};
contentPane.setLayout(gridBagLayout);
JButton button = new JButton();
button.setText("Search");
button.addActionListener(this);
contentPane.add(button, new GridBagConstraints(3, 3, 1, 1, 0.0, 0.0, 13, 0, new Insets(0, 0, 0, 0), 0, 0));
textField.setColumns(8);
contentPane.add(textField, new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0, 768, 2, new Insets(0, 0, 0, 0), 0, 0));
JLabel label = new JLabel();
label.setText("Student Seach");
contentPane.add(label, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 256, 0, new Insets(0, 0, 0, 0), 0, 0));
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.setTitle("Student Search");
frame.setBounds(new Rectangle(500, 0, 500, 320));
frame.setVisible(true);
}
public void actionPerformed( ActionEvent arg0)
{
if (textField.getText().equals(""))
{
JOptionPane.showConfirmDialog(null, "Please enter a value in the search feild", "Error", JOptionPane.OK_CANCEL_OPTION);
}
else
{
//Show the text fields here and the user information.
/**
* While there are students for this search, change the text fields to Name, Last Name and ID and have a button called
* View that when clicked allows for you to view all that students information.
*/
JLabel firstName = new JLabel();
firstName.setText("Label");
contentPane.add(firstName, new GridBagConstraints(5, 5, 1, 1, 0.0, 0.0, 768, 0, new Insets(0, 0, 0, 0), 0, 0));
JLabel lastName = new JLabel();
lastName.setText("Label");
contentPane.add(lastName, new GridBagConstraints(3, 5, 1, 1, 0.0, 0.0, 256, 0, new Insets(0, 0, 0, 0), 0, 0));
JLabel studentID = new JLabel();
studentID.setText("Label");
contentPane.add(studentID, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0, 256, 0, new Insets(0, 0, 0, 0), 0, 0));
JButton viewStudentInformation = new JButton();
viewStudentInformation.setText("Search");
viewStudentInformation.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
//For viewing individual student information
new ReadOnlyStudentForm();
}
});
contentPane.add(viewStudentInformation, new GridBagConstraints(7, 3, 1, 1, 0.0, 0.0, 13, 0, new Insets(0, 0, 0, 0), 0, 0));
}
}
}