Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-05-2008, 08:24 PM
Member
 
Join Date: Nov 2007
Posts: 5
nokomis is on a distinguished road
Jlabel in Login Applet
How can I put a JLabel in my applet? I've tried different ways but cannot seem to get it to work. All I want to do is put "username" and "password" above the text and password fields.

<code>import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class LoginApplet extends JApplet
implements ActionListener {

private JTextField login;
private JPasswordField password;
private JButton loginButton;

public void init() {
// Set the layout manager
Container c = getContentPane();
c.setLayout(new BorderLayout());

// Create the fields and button

login = new JTextField(10);

password = new JPasswordField("asecret");
loginButton = new JButton("Login");

// Add components to the container

c.add(login, BorderLayout.NORTH);
c.add(password, BorderLayout.CENTER);
c.add(loginButton, BorderLayout.SOUTH);

// Add event handlers
login.addActionListener(this);
password.addActionListener(this);
loginButton.addActionListener(this);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == login) {
password.requestFocus();
} else if ((e.getSource() == password)
|| (e.getSource() == loginButton)) {
JOptionPane.showMessageDialog(null,
"Login: " + login.getText()
+ "\nPassword: "
+ new String(password.getPassword()),
"Login Message",
JOptionPane.INFORMATION_MESSAGE);
}
}
}</code>
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 06-05-2008, 08:29 PM
Fubarable's Avatar
Senior Member
 
Join Date: Jun 2008
Posts: 883
Fubarable is on a distinguished road
You'll likely need to nest JPanels for this to work. Put your textfields in their own jpanel, perhaps boxlayout, oriented in a page axis direction, and add your JLabel first then the JTextField, then add these to the main JPanel BorderLayout whatever.

Again, the key here is to nest JPanels, each using whatever layout would best solve your problem.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 06-05-2008, 09:11 PM
Member
 
Join Date: Nov 2007
Posts: 5
nokomis is on a distinguished road
Okay, I modified an existing one, but after compiling, it still shows the old values in the html page, but on the appletviewer, the new modifications show up. Why?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 06-06-2008, 12:29 AM
Member
 
Join Date: Nov 2007
Posts: 5
nokomis is on a distinguished road
figured it out....pilot error!
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
GUI - JLabel Azndaddy New To Java 8 05-02-2008 09:03 AM
JLabel append? Jononomous New To Java 0 04-07-2008 09:41 PM
Applet Login System Tutorial Free-JavaTutorials Java Applets 0 03-15-2008 04:51 AM
JLabel Jack AWT / Swing 2 07-02-2007 03:55 PM
JLabel Freddie AWT / Swing 2 05-29-2007 04:19 PM


All times are GMT +3. The time now is 08:26 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org