Pessoal tenho esse código,
import javax.swing.<em>;
import java.awt.</em>;
import <a href="http://java.io">java.io</a>.*;
import java.util.Properties;
public class Login extends JFrame {
FileInputStream fis = null;
Properties props = new Properties();
File file = new File ("cfg.ini");
String msg;
String usr;
public Login() {
setTitle("Login");
setSize(200,150);
GridBagLayout layout = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
c.fill= GridBagConstraints.HORIZONTAL;
getContentPane().setLayout(layout);
JButton btnLogin = new JButton("Login");
JLabel lblLogin = new JLabel("Usuário");
JLabel lblSenha = new JLabel("Senha");
JTextField txtLogin = new JTextField("teixeira");
JPasswordField txtSenha = new JPasswordField('*');
c.gridy = 0;
c.gridx = 0;
layout.setConstraints(lblLogin, c);
getContentPane().add(lblLogin);
c.gridy = 1;
c.gridx = 0;
layout.setConstraints(lblSenha, c);
getContentPane().add(lblSenha);
c.gridy = 0;
c.gridx = 1;
layout.setConstraints(txtLogin, c);
getContentPane().add(txtLogin);
c.gridy = 1;
c.gridx = 1;
layout.setConstraints(txtSenha, c);
getContentPane().add(txtSenha);
c.gridy = 2;
c.gridx = 1;
layout.setConstraints(btnLogin, c);
getContentPane().add(btnLogin);
setDefaultLookAndFeelDecorated(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public void arquivo() {
file = file.getAbsoluteFile();
try {
fis = new FileInputStream(file);
props.load(fis);
String usr = props.getProperty("usr");
JOptionPane.showMessageDialog(null,"Usuário:" + " " +
usr);
fis.close();
}
catch (IOException e) {
JOptionPane.showMessageDialog(
null,"Erro" + "
" + e.getMessage());
System.exit(0);
}
}
public static void main(String args[]){
new Login();
}
}
1 - agora no objeto txtLogin, eu quero que apareça o usuário em Colection (usr)
2 - Pq não fica com o setDefaultLookAndFeelDecorated ativo ?
onde estou errando,
grato pela atenção antecipadamente de todos !