There are several improvements that can be made, and I'm not sure any of them will solve your problem, because I can't duplicate it.
This one certainly won't: Give your variables better names! For example, why name the cancel button "objJButton2"??? Name the dang thing "cancelButton" or something that makes sense. The same with the rest of your variables!
Run your Swing applications on the EDT. An alarm should go off anytime you build and run a Swing app on the main thread or entirely in the main() method. This may actually be contributing to the error you're seeing, causing the components to blink every time the GUI is redrawn, but I'm not sure since I can't see it.
Finally, the last component being added to the JFrame is becoming the JFrame's background. I think this is because the default layout manager for the JFrame is BorderLayout, so the last component added is taking the BorderLayout.CENTER position. You can verify this by commenting out the last component being added (currently the cancel button) and observe what happens. Even using a simple layout manager like FlowLayout is preferred to what you've done, but since this is a probably a program to study how things work, playing around to see what happens is fine.
Here's your program modified to do everything I've described except changing the variable names - that's for you to do. Let me know if you still see the components coming in and out.
/* File: TechStudentFrame.java
* GregBrannon, August 2013, modified TechStudent's post:
* http://www.javaprogrammingforums.com/whats-wrong-my-code/
* 30834-gui-does-not-stay-loaded-applet.html
*/
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
public class TechStudentFrame
{
// the default constructor that builds the frame and sets it visible
public TechStudentFrame()
{
// set the frame's basic characteristics
JFrame objJFrame = new JFrame("Login");
objJFrame.setSize(250,150);
objJFrame.setResizable( false );
objJFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
objJFrame.setLayout( new FlowLayout() );
// build the components to be added to the frame
JButton objJButton1 = new JButton("Login");
JButton objJButton2 = new JButton("Cancel");
JTextField objJTextField1 = new JTextField(" ",10);
JTextField objJTextField2 = new JTextField(" ",10);
JLabel objJLabel1 = new JLabel();
objJLabel1.setText("Username");
JLabel objJLabel2 = new JLabel();
objJLabel2.setText("Password");
// add the components to the frame
objJFrame.add(objJLabel1);
objJFrame.add(objJTextField1);
objJFrame.add(objJLabel2);
objJFrame.add(objJTextField2);
objJFrame.add(objJButton1);
objJFrame.add(objJButton2);
//JFrame.setDefaultLookAndFeelDecorated(true);
// set the frame visible
objJFrame.setVisible( true );
}
// the main() method creates an instance of the frame on the EDT
// see this article for more info:
// http://www.javaworld.com/community/node/7717
public static void main(String args[])
{
SwingUtilities.invokeLater( new Runnable()
{
public void run()
{
new TechStudentFrame();
}
} );
} // end method main()
} // end class TechStudentFrame