Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
Swing / AWT / SWT
Author
help arranging layout of TextField
John Johnson
Greenhorn
Joined: Oct 24, 2006
Posts: 1
posted
Oct 30, 2006 17:58:00
0
I need to get the ID and Password TextFields to look like this:
ID: TEXTFIELD
Password: TEXTFIELD
import java.awt.*; import java.applet.*; import java.awt.event.*; public class PasswordApplet extends Applet implements ActionListener { //Declaring variables String id, password; boolean success; String idArray[ ]={"id", "Admin", "Student", "Guest"}; String passwordArray[ ]={"password", "ad06", "stud06", "gu06" }; //Create components for applet Label headerLabel = new Label("Please type your ID and Password"); Label idLabel = new Label("ID:"); TextField idField = new TextField(7); Label passwordLabel = new Label("Password:"); TextField passwordField = new TextField(7); Button loginButton = new Button("Login"); public void init() { //Set color, layout, and add components setBackground(Color.black); setForeground(Color.blue); setLayout(new FlowLayout(FlowLayout.LEFT,40,30)); add(headerLabel); add(idLabel); add(idField); idField.requestFocus(); add(passwordLabel); add(passwordField); passwordField.setEchoChar('*'); add(loginButton); loginButton.addActionListener(this); } public void actionPerformed(ActionEvent e) { //Assigning data id = idField.getText(); password = passwordField.getText(); success = false; //Sequential search for (int i=0; i<4; i++) { if ((idArray[i].compareTo(id)==0) && (passwordArray[i].compareTo(password)==0)) success=true; } if (success==true) {headerLabel.setText("Login Successful"); repaint(); } else { headerLabel.setText("Invalid. Try again."); idField.setText (""); passwordField.setText(""); idField.requestFocus(); } } }
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24041
13
I like...
posted
Oct 30, 2006 20:09:00
0
Hi,
Welcome to JavaRanch!
We have a "Swing/AWT/JFace/SWT" forum where this question would fit right in; I will move it there for you.
[Jess in Action]
[AskingGoodQuestions]
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
Oct 30, 2006 20:51:00
0
try this
if ID and Password are not in the correct spot, modify lines like this, to suit
new Label("ID:",Label.RIGHT);
import java.awt.*; import java.applet.*; import java.awt.event.*; public class TestApplet extends Applet implements ActionListener { String id, password; boolean success; String idArray[ ]={"id", "Admin", "Student", "Guest"}; String passwordArray[ ]={"password", "ad06", "stud06", "gu06" }; Label headerLabel = new Label("Please type your ID and Password",Label.CENTER); Label idLabel = new Label("ID:",Label.RIGHT); TextField idField = new TextField(7); Label passwordLabel = new Label("Password:",Label.RIGHT); TextField passwordField = new TextField(7); Button loginButton = new Button("Login"); public void init() { Panel panel = new Panel(new BorderLayout()); setBackground(Color.black); setForeground(Color.blue); Panel p = new Panel(); p.add(headerLabel); panel.add(p,BorderLayout.NORTH); Panel p1 = new Panel(new GridLayout(2,2,10,10)); p1.add(idLabel); p1.add(idField); p1.add(passwordLabel); p1.add(passwordField); panel.add(p1,BorderLayout.CENTER); Panel p2 = new Panel(); p2.add(loginButton); panel.add(p2,BorderLayout.SOUTH); add(panel); passwordField.setEchoChar('*'); loginButton.addActionListener(this); } public void actionPerformed(ActionEvent e) { id = idField.getText(); password = passwordField.getText(); success = false; for (int i=0; i<4; i++) { if ((idArray[i].compareTo(id)==0) && (passwordArray[i].compareTo(password)==0)) success=true; } if (success==true) { headerLabel.setText("Login Successful"); repaint(); } else { headerLabel.setText("Invalid. Try again."); idField.setText (""); passwordField.setText(""); idField.requestFocus(); } } }
I agree. Here's the link:
http://ej-technologies/jprofiler
- if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
subject: help arranging layout of TextField
Similar Threads
Applet Code Error
Applet Login via database
keyboard action of my JButton
Applet Login via database
Please help me with this code... I don't know what I'm missing...
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter