Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: JButtons help
|
Posted: Jun 17, 2002 12:21 AM
|
|
/* Access.java * @author: Charles Bell * @version: Jun 17, 2002 */
import java.awt.*; import javax.swing.*;
/** Access */ public class Access extends JFrame{ public Access(){ super("Access"); init(); } public static void main(String[] args){ Access access = new Access(); } public void init(){ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); String user = login(); JPanel topPanel = new JPanel(); JPanel middlePanel = new JPanel(); JPanel bottomPanel = new JPanel(); topPanel.add(new JLabel(user)); middlePanel.add(new JLabel("Welcome to my web site.")); bottomPanel.add(new JLabel("Please feel free to write more Java programs.")); getContentPane().add(topPanel, BorderLayout.NORTH); getContentPane().add(middlePanel, BorderLayout.CENTER); getContentPane().add(bottomPanel, BorderLayout.SOUTH); pack(); setLocationRelativeTo(null); show(); } private String login(){ String userName = ""; JFrame f = new JFrame(); JTextField nameField = new JTextField(8); JPasswordField passwordField = new JPasswordField(8); passwordField.setEchoChar('*'); String message = "Login:"; Object[] array = {message,nameField, passwordField}; //JOptionPane editpane = new JOptionPane(textfield); JPanel loginPanel = new JPanel(); JPanel namePanel = new JPanel(); JPanel accessCodePanel = new JPanel(); loginPanel.setLayout(new BorderLayout()); namePanel.setLayout(new BorderLayout()); accessCodePanel.setLayout(new BorderLayout()); namePanel.add(new JLabel("User Name: "), BorderLayout.WEST); namePanel.add(nameField, BorderLayout.EAST); accessCodePanel.add(new JLabel("Password: "), BorderLayout.WEST); accessCodePanel.add(passwordField, BorderLayout.EAST); loginPanel.add(namePanel, BorderLayout.NORTH); loginPanel.add(accessCodePanel, BorderLayout.SOUTH); JOptionPane loginPane = new JOptionPane(loginPanel, JOptionPane.PLAIN_MESSAGE, JOptionPane.DEFAULT_OPTION); JDialog dialog = loginPane.createDialog(f,message); //center frame on screen f.setLocationRelativeTo(null); dialog.show(); userName = nameField.getText(); String password = new String(passwordField.getPassword()); //put your own validation code in here return userName; } }
|
|