Java Reference
In-Depth Information
FIGURE 12.8: Example of a password field.
field shows only stars when text is entered into it. In all other aspects, the two classes work
similarly.
We will create a very simple application; see Figure 12.8. The program starts by dis-
playing a window. The window, in turn, displays a modal dialog box. Users can return to
the window only after they enter the correct login and password in the dialog box.
import javax . swing . ;
import java .awt . ;
import java .awt. event . ;
import java.util.Arrays;
public class PasswordGame {
public static void main(String [] args) {
LoginFrame frame = new LoginFrame () ;
}
}
class LoginFrame extends JFrame
{
public LoginFrame ()
{
setVisible( true );
setSize (300 , 300) ;
LoginDialog dialog = new LoginDialog( this );
dialog . setSize (200 , 100) ;
dialog . setVisible( true );
}
class LoginDialog extends JDialog {
public LoginDialog(JFrame owner) {
super (owner, "Authentication" , true );
setResizable( false );
setDefaultCloseOperation(JDialog .DONOTHING ON CLOSE) ;
JPanel centerPanel = new JPanel () ;
 
Search WWH ::




Custom Search