Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.BorderLayout;
- import java.awt.EventQueue;
- import javax.swing.JFrame;
- import javax.swing.JPanel;
- import javax.swing.border.EmptyBorder;
- import javax.swing.JLabel;
- import javax.swing.JTextField;
- import javax.swing.JButton;
- import javax.swing.SwingConstants;
- import java.awt.Color;
- import java.awt.event.ActionListener;
- import java.awt.event.ActionEvent;
- public class fenetre extends JFrame {
- private JPanel Panneau1;
- private JTextField tf_ip;
- private JTextField tf_port;
- private JLabel lbl_Etat;
- private JButton btn_Envoyer;
- private JButton btn_Recevoir;
- private JButton btnConnecter;
- private JButton btn_Fermer;
- private JButton btn_Quitter;
- private Reseau reseau;
- /**
- * Launch the application.
- */
- public static void main(String[] args) {
- EventQueue.invokeLater(new Runnable() {
- public void run() {
- try {
- fenetre frame = new fenetre();
- frame.setVisible(true);
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- });
- }
- /**
- * Create the frame.
- */
- public fenetre() {
- setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- setBounds(100, 100, 546, 492);
- Panneau1 = new JPanel();
- Panneau1.setBorder(new EmptyBorder(5, 5, 5, 5));
- setContentPane(Panneau1);
- Panneau1.setLayout(null);
- JLabel lbl_port = new JLabel("PORT :");
- lbl_port.setBounds(20, 49, 46, 14);
- Panneau1.add(lbl_port);
- tf_ip = new JTextField();
- tf_ip.setBounds(212, 46, 86, 20);
- Panneau1.add(tf_ip);
- tf_ip.setColumns(10);
- JLabel lbl_Ip = new JLabel("IP :");
- lbl_Ip.setBounds(185, 49, 46, 14);
- Panneau1.add(lbl_Ip);
- tf_port = new JTextField();
- tf_port.setBounds(64, 46, 86, 20);
- Panneau1.add(tf_port);
- tf_port.setColumns(10);
- btnConnecter = new JButton("Connecter");
- btnConnecter.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- OnConnecter();
- }
- });
- btnConnecter.setBounds(379, 45, 100, 23);
- Panneau1.add(btnConnecter);
- btn_Envoyer = new JButton("Envoyer");
- btn_Envoyer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- OnEnvoyer();
- }
- });
- btn_Envoyer.setBounds(61, 112, 89, 23);
- Panneau1.add(btn_Envoyer);
- btn_Recevoir = new JButton("Recevoir");
- btn_Recevoir.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- OnRecevoir();
- }
- });
- btn_Recevoir.setBounds(230, 112, 89, 23);
- Panneau1.add(btn_Recevoir);
- btn_Fermer = new JButton("Fermer");
- btn_Fermer.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- OnClose();
- }
- });
- btn_Fermer.setBounds(379, 159, 89, 23);
- Panneau1.add(btn_Fermer);
- lbl_Etat = new JLabel("ETAT SYSTEME");
- lbl_Etat.setOpaque(true);
- lbl_Etat.setBackground(Color.CYAN);
- lbl_Etat.setHorizontalAlignment(SwingConstants.CENTER);
- lbl_Etat.setBounds(64, 217, 404, 146);
- Panneau1.add(lbl_Etat);
- btn_Quitter = new JButton("Quitter");
- btn_Quitter.addActionListener(new ActionListener() {
- public void actionPerformed(ActionEvent e) {
- System.exit(0);
- }
- });
- btn_Quitter.setBounds(209, 384, 89, 23);
- Panneau1.add(btn_Quitter);
- }
- protected void OnConnecter()
- {
- String ip= tf_ip.getText();
- String port= tf_port.getText();
- try
- {
- int sport = Integer.parseInt(port);
- reseau = new Reseau();
- int retour=reseau.Connecter(ip, sport);
- if (retour==0)
- lbl_Etat.setText("Connexion reussie "+sport+" "+ip);
- else
- lbl_Etat.setText("Connexion échec "+sport+" "+ip);
- }
- catch(NumberFormatException e)
- {
- lbl_Etat.setText("erreur n° port");
- }
- }
- protected void OnClose()
- {
- lbl_Etat.setText("closesocket");
- }
- protected void OnEnvoyer()
- {
- String message="HAMZA TG MERCI";
- int retour=reseau.Envoyer(message);
- lbl_Etat.setText("Envoyer"+retour);
- }
- protected void OnRecevoir()
- {
- StringBuffer msg_recu = new StringBuffer();
- int retour=reseau.Recevoir(msg_recu);
- if (retour==0)
- lbl_Etat.setText("recevoir " +msg_recu.toString());
- else
- lbl_Etat.setText("erreur " +retour);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement