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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| import java.io.*;
import java.net.*;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLWarning;
import java.sql.Statement;
import java.util.StringTokenizer;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
@SuppressWarnings("serial")
public class Test extends JFrame implements MouseListener,ActionListener{
ServerSocket providerSocket;
Socket connection = null;
ObjectOutputStream out;
ObjectInputStream in;
String message;
JPanel p=new JPanel();
JLabel l=new JLabel();
JButton b=new JButton("Démarrer le serveur");
JButton b1=new JButton("Arrêter le serveur");
JTextArea t=new JTextArea("donnee");
Test(){
this.setTitle("Animation");
this.setSize(600, 600);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setLocationRelativeTo(null);
this.addWindowListener (new WindowAdapter( ){public void windowClosing(WindowEvent e)
{ System.exit(0);
}});
p.setBackground(Color.white);
p.setLayout(new BorderLayout());
JPanel p1=new JPanel();
JPanel p2=new JPanel();
JPanel c=new JPanel();
p1.add(b);
p2.add(b1);
b.addMouseListener(this);
b.addActionListener(this);
c.add(t);
Font police = new Font("Arial", Font.BOLD, 14);
c.setFont(police);
c.setPreferredSize(new Dimension(400, 400));
c.setForeground(Color.BLUE);
p.add(p1,BorderLayout.SOUTH);
p.add(p2,BorderLayout.NORTH);
p.add(c,BorderLayout.CENTER);
this.setContentPane(p);
this.setVisible(true);
}
public void actionPerformed(ActionEvent arg0) {
if(arg0.getSource() == b)
{this.run();
b1.setEnabled(true);}
if(arg0.getSource() == b1)
try {
providerSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
this.addWindowListener (new WindowAdapter( ){public void windowClosing(WindowEvent e)
{ System.exit(0);
}});
}
}
public void mouseClicked(MouseEvent event) {
if(event.getSource() == b)
{this.run();
b1.setEnabled(true);}
if(event.getSource() == b1)
try {
providerSocket.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
this.addWindowListener (new WindowAdapter( ){public void windowClosing(WindowEvent e)
{ System.exit(0);
}});
}
}}} |
Partager