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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
public class EssaiDialog{
private Ecran ecran;
private JDialog dialog;
private JTextField jtf;
private JButton jb;
public EssaiDialog() {
ecran = new Ecran();
dialog = new JDialog(ecran,true);
initComponents();
dialog.setVisible(true);
}
private void initComponents() {
jtf = new JTextField();
jb = new JButton("Ok");
jb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent ae){
System.out.println("vous avez écrit : "+jtf.getText());
closeDialog(null);
}
});
dialog.getContentPane().add(jtf, BorderLayout.CENTER);
dialog.getContentPane().add(jb, BorderLayout.SOUTH);
dialog.addWindowListener(new java.awt.event.WindowAdapter() {
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
dialog.pack();
dialog.setLocationRelativeTo(null);
}
private void closeDialog(java.awt.event.WindowEvent evt) {
dialog.setVisible(false);
dialog.dispose();
ecran.setVisible(false);
ecran.dispose();
}
private class Ecran extends JFrame{
private Image image;
public Ecran(){
super();
setUndecorated(true);
Dimension taille = Toolkit.getDefaultToolkit().getScreenSize();
try{
image = new Robot().createScreenCapture(new Rectangle(0,0,
(int)taille.getWidth(),
(int)taille.getHeight()));
MediaTracker mt = new MediaTracker(this);
mt.addImage(image,0);
mt.waitForAll();
}catch(Exception e){e.printStackTrace();}
setSize(taille);
setVisible(true);
}
public void paint(Graphics g){
g.drawImage(image,0,0,null);
}
}
public static void main(String args[]) {
new EssaiDialog();
}
} |