I Need to fetch the username from windows and i need to assign that username for my swing application and how can i do that. Here is my code
import javax.swing.*;
import java.awt.event.*;
public class PasswordFieldExample {
public static void main(String[] args) {
JFrame f=new JFrame("User-ID");
final JLabel label = new JLabel();
label.setBounds(20,150, 200,50);
JLabel l1=new JLabel("Username:");
l1.setBounds(20,20, 80,30);
JButton b = new JButton("Login");
b.setBounds(100,120, 80,30);
final JTextField text = new JTextField();
text.setBounds(100,20, 100,30);
f.add(l1); f.add(label); f.add(b); f.add(text);
f.setSize(300,300);
f.setLayout(null);
f.setVisible(true);
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String data = "Username " + text.getText();
label.setText(data);
}
});
}
}