Advertisement
Bukisoh

fenetre.java

Nov 25th, 2020
781
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.15 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.EventQueue;
  3.  
  4. import javax.swing.JFrame;
  5. import javax.swing.JPanel;
  6. import javax.swing.border.EmptyBorder;
  7. import javax.swing.JLabel;
  8. import javax.swing.JTextField;
  9. import javax.swing.JButton;
  10. import javax.swing.SwingConstants;
  11. import java.awt.Color;
  12. import java.awt.event.ActionListener;
  13. import java.awt.event.ActionEvent;
  14.  
  15. public class fenetre extends JFrame {
  16.  
  17.     private JPanel Panneau1;
  18.     private JTextField tf_ip;
  19.     private JTextField tf_port;
  20.     private JLabel lbl_Etat;
  21.     private JButton btn_Envoyer;
  22.     private JButton btn_Recevoir;
  23.     private JButton btnConnecter;
  24.     private JButton btn_Fermer;
  25.     private JButton btn_Quitter;
  26.     private Reseau reseau;
  27.  
  28.     /**
  29.      * Launch the application.
  30.      */
  31.     public static void main(String[] args) {
  32.         EventQueue.invokeLater(new Runnable() {
  33.             public void run() {
  34.                 try {
  35.                     fenetre frame = new fenetre();
  36.                     frame.setVisible(true);
  37.                 } catch (Exception e) {
  38.                     e.printStackTrace();
  39.                 }
  40.             }
  41.         });
  42.     }
  43.  
  44.     /**
  45.      * Create the frame.
  46.      */
  47.     public fenetre() {
  48.         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  49.         setBounds(100, 100, 546, 492);
  50.         Panneau1 = new JPanel();
  51.         Panneau1.setBorder(new EmptyBorder(5, 5, 5, 5));
  52.         setContentPane(Panneau1);
  53.         Panneau1.setLayout(null);
  54.        
  55.         JLabel lbl_port = new JLabel("PORT :");
  56.         lbl_port.setBounds(20, 49, 46, 14);
  57.         Panneau1.add(lbl_port);
  58.        
  59.         tf_ip = new JTextField();
  60.         tf_ip.setBounds(212, 46, 86, 20);
  61.         Panneau1.add(tf_ip);
  62.         tf_ip.setColumns(10);
  63.        
  64.         JLabel lbl_Ip = new JLabel("IP :");
  65.         lbl_Ip.setBounds(185, 49, 46, 14);
  66.         Panneau1.add(lbl_Ip);
  67.        
  68.         tf_port = new JTextField();
  69.         tf_port.setBounds(64, 46, 86, 20);
  70.         Panneau1.add(tf_port);
  71.         tf_port.setColumns(10);
  72.        
  73.         btnConnecter = new JButton("Connecter");
  74.         btnConnecter.addActionListener(new ActionListener() {
  75.             public void actionPerformed(ActionEvent e) {
  76.                 OnConnecter();
  77.             }
  78.         });
  79.         btnConnecter.setBounds(379, 45, 100, 23);
  80.         Panneau1.add(btnConnecter);
  81.        
  82.         btn_Envoyer = new JButton("Envoyer");
  83.         btn_Envoyer.addActionListener(new ActionListener() {
  84.             public void actionPerformed(ActionEvent e) {
  85.                 OnEnvoyer();
  86.             }
  87.         });
  88.         btn_Envoyer.setBounds(61, 112, 89, 23);
  89.         Panneau1.add(btn_Envoyer);
  90.        
  91.         btn_Recevoir = new JButton("Recevoir");
  92.         btn_Recevoir.addActionListener(new ActionListener() {
  93.             public void actionPerformed(ActionEvent e) {
  94.                 OnRecevoir();
  95.             }
  96.         });
  97.         btn_Recevoir.setBounds(230, 112, 89, 23);
  98.         Panneau1.add(btn_Recevoir);
  99.        
  100.         btn_Fermer = new JButton("Fermer");
  101.         btn_Fermer.addActionListener(new ActionListener() {
  102.             public void actionPerformed(ActionEvent e) {
  103.                 OnClose();
  104.             }
  105.         });
  106.         btn_Fermer.setBounds(379, 159, 89, 23);
  107.         Panneau1.add(btn_Fermer);
  108.        
  109.         lbl_Etat = new JLabel("ETAT SYSTEME");
  110.         lbl_Etat.setOpaque(true);
  111.         lbl_Etat.setBackground(Color.CYAN);
  112.         lbl_Etat.setHorizontalAlignment(SwingConstants.CENTER);
  113.         lbl_Etat.setBounds(64, 217, 404, 146);
  114.         Panneau1.add(lbl_Etat);
  115.        
  116.         btn_Quitter = new JButton("Quitter");
  117.         btn_Quitter.addActionListener(new ActionListener() {
  118.             public void actionPerformed(ActionEvent e) {
  119.                 System.exit(0);
  120.             }
  121.         });
  122.         btn_Quitter.setBounds(209, 384, 89, 23);
  123.         Panneau1.add(btn_Quitter);
  124.  
  125.     }
  126.     protected void OnConnecter()
  127.     {
  128.     String ip= tf_ip.getText();
  129.     String port= tf_port.getText();
  130.     try
  131.     {
  132.     int sport = Integer.parseInt(port);
  133.    
  134.     reseau = new Reseau();
  135.    
  136.     int retour=reseau.Connecter(ip, sport);
  137.    
  138.     if (retour==0)
  139.        
  140.     lbl_Etat.setText("Connexion reussie "+sport+"   "+ip); 
  141.     else
  142.     lbl_Etat.setText("Connexion échec "+sport+"   "+ip);  
  143.     }
  144.    
  145.     catch(NumberFormatException e)
  146.     {
  147.         lbl_Etat.setText("erreur n° port");
  148.     }
  149.     }
  150.    
  151.     protected void OnClose()
  152.     {
  153.     lbl_Etat.setText("closesocket");
  154.    
  155.     }
  156.    
  157.     protected void OnEnvoyer()
  158.     {
  159.         String message="HAMZA TG MERCI";
  160.         int retour=reseau.Envoyer(message);
  161.         lbl_Etat.setText("Envoyer"+retour);
  162.  
  163.     }
  164.     protected void OnRecevoir()
  165.     {
  166.         StringBuffer msg_recu = new StringBuffer();
  167.         int retour=reseau.Recevoir(msg_recu);
  168.         if (retour==0)
  169.             lbl_Etat.setText("recevoir " +msg_recu.toString());
  170.         else
  171.             lbl_Etat.setText("erreur " +retour);
  172.    
  173.     }
  174. }
  175.  
  176.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement