1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JTextField;
public class Test {
public static void main(String[] args) {
JFrame frame = new JFrame();
final JDialog dialog = new JDialog(frame, "login", true);
dialog.setLayout(new FlowLayout());
dialog.add(new JTextField("login"));
dialog.add(new JTextField("password"));
dialog.add(new JButton("Entrer"));
dialog.pack();
JButton button = new JButton("Se connecter");
frame.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
dialog.setVisible(true);
}
});
frame.setSize(200, 200);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setVisible(true);
}
} |
Partager