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 63 64 65 66
| package textautosaisieforum;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class principal {
public static void main(String[] args) {
JTextField mot=new JTextField();
JPanel panel= new JPanel();
JButton bouton1 = new JButton("ici");
Font f=new Font("Arial", Font.BOLD, 20);
bouton1.setFont(f);
bouton1.setBackground(Color.gray);
bouton1.setForeground(Color.black);
bouton1.setBounds(15, 80, 80, 40); //positionnement du bouton en partant du coin gauche x horiz y verti v long ww larg
panel.add(bouton1);
bouton1.addActionListener(new ActionListener() {//si je rajoute action listener sur le bouton
//je reperd le curseur
public void actionPerformed(ActionEvent ae) {
}
});
JLabel label = new JLabel("aa", JLabel.CENTER);
Font f14=new Font("Arial", Font.BOLD, 20);
label.setFont(f14);
JFrame pan = new JFrame("saisie rapide");
pan.setAlwaysOnTop( true );//pour que la fenetre s affiche devant le reste
pan.setContentPane(panel);
pan.setSize(580, 400);// taille de la fenetre
pan.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pan.setLocationRelativeTo(null);
Font gt=new Font("Arial", Font.BOLD, 20);
label.setBounds(20,200, 50, 60);
mot.setFont(gt);//caractristiques case texte entree
mot.setBounds(250,200, 100,60);
panel.setLayout(null);
panel.add(label);
panel.add(mot);
pan.addWindowListener((WindowListener) new WindowAdapter() {//avec ca j ai le cursueur a la creation de la fenetre
//mais quand on clic sur le bouton 1,le curseur disparait
public void windowOpened(WindowEvent e){
mot.requestFocus();
}
});
pan.setVisible(true);
}
} |
Partager