Results 1 to 4 of 4
Thread: Jlabel in Login Applet
- 06-05-2008, 06:24 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 5
- Rep Power
- 0
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>
-
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.
- 06-05-2008, 07:11 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 5
- Rep Power
- 0
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?
- 06-05-2008, 10:29 PM #4
Member
- Join Date
- Nov 2007
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
GUI - JLabel
By Azndaddy in forum New To JavaReplies: 8Last Post: 05-02-2008, 07:03 AM -
JLabel append?
By Jononomous in forum New To JavaReplies: 0Last Post: 04-07-2008, 07:41 PM -
Applet Login System Tutorial
By Free-JavaTutorials in forum Java AppletsReplies: 0Last Post: 03-15-2008, 02:51 AM -
JLabel
By Jack in forum AWT / SwingReplies: 2Last Post: 07-02-2007, 01:55 PM -
JLabel
By Freddie in forum AWT / SwingReplies: 2Last Post: 05-29-2007, 02:19 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks