import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*; import javax.swing.*; /** This program shows how to use sockets to send plain text mail messages. */ public class VideoClient { static LoginFrame framelog; static ClientFrame frame; static ControlFrame cframe; static boolean aux = false; static Socket s; static BufferedReader input; static PrintWriter output; static String[] readarrayaux; public static void main(String[] args) { framelog = new LoginFrame(); framelog.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { framelog.closeServer(s); System.exit(0); } }); framelog.setVisible(true); //frame = new ClientFrame(); //frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame1.setVisible(true); } public static void visible(){ //framelog.setVisible(false); framelog.dispose(); frame = new ClientFrame(); frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { frame.closeServer(s); System.exit(0); } }); frame.setVisible(true); } public static void visibledos(int i){ //framelog.setVisible(false); if (i==2){ cframe.dispose(); cframe = new ControlFrame(2); } else if (i==3){ cframe.dispose(); cframe = new ControlFrame(1); } else { cframe = new ControlFrame(1); } frame.enable(false); cframe.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { try { videofunc.send("NEWCONFIG",VideoClient.output); ClientFrame.status = false; frame.enable(true); cframe.dispose(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }; } }); cframe.setVisible(true); } public static void crearsocket(String ip, int port) throws IOException { s = new Socket(ip, port); input = new BufferedReader(new InputStreamReader(s.getInputStream())); output = new PrintWriter(s.getOutputStream(), true /* autoFlush */); aux=true; } public static void openflash(String dir){ java.awt.Desktop desktop = java.awt.Desktop.getDesktop(); try { java.net.URI uri = new java.net.URI(dir); desktop.browse(uri); } catch ( Exception e ) { System.err.println( e.getMessage() ); } } } /** The frame for the mail GUI. */ class LoginFrame extends JFrame { /** * */ private static final long serialVersionUID = 1L; public LoginFrame() { setSize(300, 150); setTitle("Log In"); setLocationRelativeTo(null); getContentPane().setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.weightx = 0; gbc.weighty = 0; gbc.weightx = 0; videofunc.add(this,new JLabel("IP Server:"), gbc, 0, 0, 1, 1); gbc.weightx = 100; ipserv = new JTextField("190.164.108.21", 20); videofunc.add(this,ipserv, gbc, 1, 0, 1, 1); gbc.weightx = 0; videofunc.add(this,new JLabel("Puerto:"), gbc, 0, 1, 1, 1); gbc.weightx = 100; port = new JTextField("8189",20); videofunc.add(this,port, gbc, 1, 1, 1, 1); gbc.weightx = 0; videofunc.add(this,new JLabel("Pass:"), gbc, 0, 2, 1, 1); gbc.weightx = 100; pass = new JPasswordField("now",20); videofunc.add(this,pass, gbc, 1, 2, 1, 1); gbc.fill = GridBagConstraints.BOTH; gbc.weighty = 0; JButton sendButton = new JButton("Log In"); sendButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { new Thread() { public void run() { if(!VideoClient.aux){ try { String puerto = port.getText(); int portn = Integer.parseInt(puerto); //System.out.println(puerto); //System.out.print(portn); VideoClient.crearsocket(ipserv.getText(), portn); VideoClient.aux=true; //Verify(); } catch (IOException e) { JOptionPane.showMessageDialog(null,"Can't create socket"); e.printStackTrace(); } } Verify(); } } .start(); } }); JPanel buttonPanel = new JPanel(); buttonPanel.add(sendButton); videofunc.add(this,buttonPanel, gbc, 0, 8, 2, 1); } public void closeServer(Socket s) { if(s!=null) try { s.close(); } catch (IOException e) { e.printStackTrace(); } } class RedLabel implements Runnable { private static final long serialVersionUID = 1L; private Thread t; private JComponent test; public RedLabel(JComponent asd) { this.test = asd; t = new Thread(this); t.start(); } public void PaintComp(JComponent x, Color color) { x.setBackground(color); } public void run() { PaintComp(test, Color.RED); try { Thread.sleep(2000); } catch(InterruptedException e) { } PaintComp(test, Color.WHITE); } } public boolean TestFields(){ int i=0; if(pass.getText().equals("")){ new RedLabel(pass); i=1; } if(ipserv.getText().equals("")){ new RedLabel(ipserv); i=1; } if(port.getText().equals("")){ new RedLabel(port); i=1; } if(i==1)return true; else return false; } public void Verify() { String lnread; try { if(TestFields())return; String auth64 = pass.getText(); videofunc.sendpass(auth64, VideoClient.output); String status = videofunc.receiveline(VideoClient.input); //CORRER INTERFAZ DE CLIENTE if (status.compareTo("access")==0) { JOptionPane.showMessageDialog(null, "Authentication Successful"); VideoClient.aux=false; //VideoClient.visible(); lnread = videofunc.receiveline(VideoClient.input); int max = Integer.parseInt(lnread); //JOptionPane.showMessageDialog(null, lnread); VideoClient.readarrayaux=new String[max]; for(int i=0;i