Java/SWT JFace Eclipse/Password — различия между версиями

Материал из Java эксперт
Перейти к: навигация, поиск
 
м (1 версия)
 
(нет различий)

Текущая версия на 08:55, 1 июня 2010

SWT Password

User name Password Dialog

   <source lang="java">

/* SWT/JFace in Action GUI Design with Eclipse 3.0 Matthew Scarpino, Stephen Holder, Stanford Ng, and Laurent Mihalkovic ISBN: 1932394273 Publisher: Manning

  • /

import org.eclipse.jface.dialogs.Dialog; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.ruposite; import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class UsernamePasswordDialog extends Dialog {

 private static final int RESET_ID = IDialogConstants.NO_TO_ALL_ID + 1;
 private Text usernameField;
 private Text passwordField;
 public UsernamePasswordDialog(Shell parentShell) {
   super(parentShell);
 }
 protected Control createDialogArea(Composite parent) {
   Composite comp = (Composite) super.createDialogArea(parent);
   GridLayout layout = (GridLayout) comp.getLayout();
   layout.numColumns = 2;
   Label usernameLabel = new Label(comp, SWT.RIGHT);
   usernameLabel.setText("Username: ");
   usernameField = new Text(comp, SWT.SINGLE);
   GridData data = new GridData(GridData.FILL_HORIZONTAL);
   usernameField.setLayoutData(data);
   Label passwordLabel = new Label(comp, SWT.RIGHT);
   passwordLabel.setText("Password: ");
   passwordField = new Text(comp, SWT.SINGLE | SWT.PASSWORD);
   data = new GridData(GridData.FILL_HORIZONTAL);
   passwordField.setLayoutData(data);
   return comp;
 }
 protected void createButtonsForButtonBar(Composite parent) {
   super.createButtonsForButtonBar(parent);
   createButton(parent, RESET_ID, "Reset All", false);
 }
 protected void buttonPressed(int buttonId) {
   if (buttonId == RESET_ID) {
     usernameField.setText("");
     passwordField.setText("");
   } else {
     super.buttonPressed(buttonId);
   }
 }

}

      </source>
   
  
 
  



User Password

   <source lang="java">

/******************************************************************************

* All Right Reserved. 
* Copyright (c) 1998, 2004 Jackwind Li Guojie
* 
* Created on Feb 17, 2004 9:28:47 PM by JACK
* $Id$
* 
*****************************************************************************/

import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class UserPassword {

 Display display = new Display();
 Shell shell = new Shell(display);
 
 Text textUser;
 Text textPassword;
 private void init() {
   (new Label(shell, SWT.NULL)).setText("User name: ");
   
   textUser = new Text(shell, SWT.SINGLE | SWT.BORDER);
   textUser.setText("default_user");
   textUser.setTextLimit(16);
   
   (new Label(shell, SWT.NULL)).setText("Password: ");
   
   textPassword = new Text(shell, SWT.SINGLE | SWT.BORDER);
   System.out.println(textPassword.getEchoChar());
   textPassword.setEchoChar("*");
 }  
 
 public UserPassword() {
   shell.setLayout(new GridLayout(2, false));
   
   init();
   
   textUser.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
   textPassword.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
   
   shell.pack();
   shell.open();
   //textUser.forceFocus();
   // Set up the event loop.
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       // If no more entries in event queue
       display.sleep();
     }
   }
   display.dispose();
 }
 public static void main(String[] args) {
   new UserPassword();
 }

}

      </source>