Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Swing / AWT / SWT
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Tim Cooke
paul wheaton
Jeanne Boyarsky
Ron McLeod
Sheriffs:
Paul Clapham
Liutauras Vilda
Devaka Cooray
Saloon Keepers:
Tim Holloway
Roland Mueller
Bartenders:
Forum:
Swing / AWT / SWT
help arranging layout of TextField
John Johnson
Greenhorn
Posts: 1
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 24207
46
I like...
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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
Posts: 4632
posted 18 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
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(); } } }
Consider Paul's
rocket mass heater
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
keyboard action of my JButton
Applet Login via database
Please help me with this code... I don't know what I'm missing...
Applet Login via database
Applet Code Error
More...