dcsimg
Some help regarding java frames, buttons and video
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   dimi_kanenas
Posted On:   Wednesday, February 11, 2009 09:22 AM

Hi to all My name is Dimitrios and i am developing a program which is consisted by a client program and a server program. The purpose of the application is to stream video (TV channels) to the client.The server program is used to authenticate the client (at the moment) where the client after the authentication is providing a GUI in order to choose the Chanel and watch the video.In more detail: Client site: 2 classes ( frames) The 1st frame (login.java) prompts for username and password. The server (prog) authenticates the pass and if correct the client "moves" to the next frame (by set visible false to the 1st frame). The 2nd frame (client.java) is th   More>>

Hi to all

My name is Dimitrios and i am developing a program which is consisted by a client program and a server program. The purpose of the application is to stream video (TV channels) to the client.The server program is used to authenticate the client (at the moment) where the client after the authentication is providing a GUI in order to choose the Chanel and watch the video.In more detail:

Client site:

2 classes ( frames)

The 1st frame (login.java) prompts for username and password. The server (prog) authenticates the pass and if correct the client "moves" to the next frame (by set visible false to the 1st frame).

The 2nd frame (client.java) is the actual GUI of the program. It is consisted by two buttons (assume we have two T.V channel options) and an internal frame which is where the video is displayed.


_________________________________________________________________

In order to develop this program i have split up the tasks and try to solve each task at a time. What i mean is:


1)Create an authentication procedure (DONE)

2)Create the GUI of the client (DONE)

3)Create the operation where button is pressed and video is played IN THE INTERNAL FRAME (in progress)

4)Stream video (in progress)


_________________________________________________________________


Since i don't know yet how am i going to produce the streaming what iv done is to embed a simple quicktime player in the client and open a movie file to produce video. I need to produce the video in the internal frame first.


My question is:


1) How am i going to produce the video in the internal frame after the button is pressed. Note that the button is not in the internal frame (obvious i think).


2)i decided to use quicktime player API cause during my research i fpund out that is the best option.I did trie JMF but i wasnt that satisfied. Do you propose any other solution. I did try to find out if i could embed Windows Media player in my frame but i didn't find any info regarding WMP and java frames.


I do have some knowledge about java but i wouldnt consider my self an advance programmer. THIS IS NOT A JOB CASE but a presentation from my UNI.


Thanks in advance for reading all this.

_________________________________________________________________


My code:


SERVER

			
import java.io.*;
import java.net.*;

public class server
{
public static void main (String argv[]) throws Exception
{
//INITIATING THE SERVER(WELLCOME MESGS + OPTION FOR VARIABLE PORT//
String uname;
String pass;
String authRess;
String portString;
int portNumber;

BufferedReader inFromUser= new BufferedReader (new InputStreamReader(System.in));

System.out.println ("What port would you like to receive connections on?");

portString= inFromUser.readLine();
portNumber=Integer.parseInt(portString);

ServerSocket wellcomesocket= new ServerSocket (portNumber);

while (true)
{
System.out.println ("Listening on Port: "+portNumber);

// <-------------------------------------------------------------->//


//Connection Handling//
Socket connectionSocket= wellcomesocket.accept();
System.out.println ("Connection has been made!!
");

//Receiving User info to authenticate//
BufferedReader inFromClient= new BufferedReader (new InputStreamReader(connectionSocket.getInputStream()));
uname= inFromClient.readLine();
pass= inFromClient.readLine();
System.out.println ("Authenticating....... : "+ "username: " + uname + "
");
System.out.println ("Authenticating....... : "+ "password: " + pass + "
");
// //

//AUTHENTICATING//
if (uname.equals("usrtest") & pass.equals("passtest")) {

//Sending Answear//
DataOutputStream OuttoClient= new DataOutputStream (connectionSocket.getOutputStream());
authRess= ("ok");
OuttoClient.writeBytes (authRess + '
');

} else
{
DataOutputStream OuttoClient= new DataOutputStream (connectionSocket.getOutputStream());
authRess= ("no");
OuttoClient.writeBytes (authRess + '
');
}

System.out.println ("Answear: "+ authRess);
}
}
}



CLIENT



			

import java.io.*;
import java.net.*;
import javax.swing.*;

public class login extends javax.swing.JFrame {


public login() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {

jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jTextField1 = new javax.swing.JTextField();
jTextField2 = new javax.swing.JTextField();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("Log in");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
connectauth(evt);
}
});

jButton2.setText("Exit");
jButton2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});

jLabel1.setText("User Name");

jLabel2.setText("Password");

jMenu1.setText("File");
jMenuBar1.add(jMenu1);

jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2))
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addGap(8, 8, 8)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE)
.addComponent(jTextField1, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 58, Short.MAX_VALUE))))
.addGap(125, 125, 125))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 10, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2))
.addGap(30, 30, 30))
);

pack();
}//


private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
System.exit(0);
}

private void connectauth(java.awt.event.MouseEvent evt) {
String uname = jTextField1.getText();
String upass = jTextField2.getText();
String host="localhost";
String state=null;
int port=1300;


try{
Socket consock= new Socket(host,port);

//send info//
DataOutputStream OutToServer= new DataOutputStream(consock.getOutputStream());
OutToServer.writeBytes (uname + '
');
OutToServer.writeBytes (upass + '
');
// //


//Receive auth answear//
BufferedReader InFromServer= new BufferedReader (new InputStreamReader (consock.getInputStream()));
state=InFromServer.readLine();
// //

//Authenticate//
if (state.equals("ok")){
JOptionPane.showMessageDialog(null,"Access Granted !! " + "Msg:" + state);
client panelClient= new client();
setVisible(false);
//System.exit(0);
//panelClient.client();
//client.setVisible(true);
} else {JOptionPane.showMessageDialog(null,"Wrong user name " + "Msg:" + state);
}
// //

}catch (Exception e) {
System.err.println(e);
System.err.println("Connection Error");
}




}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new login().setVisible(true);
}
});
} //end main

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration

}// end Class



			

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.io.File;
import quicktime.*;
import quicktime.app.*;
import quicktime.app.players.*;
import quicktime.app.display.*;
import quicktime.io.*;
import quicktime.std.*;
import quicktime.std.movies.*;
import quicktime.*;
import javax.swing.*;

public class client extends javax.swing.JFrame {

static Movie movie;
/** Creates new form client */
public client()
{
initComponents();
setVisible(true);
// login.setVisible(false);
}

// @SuppressWarnings("unchecked")
//
private void initComponents() {

jButton1 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jInternalFrame1 = new javax.swing.JInternalFrame();
jMenuBar1 = new javax.swing.JMenuBar();
jMenu1 = new javax.swing.JMenu();
jMenu2 = new javax.swing.JMenu();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

jButton1.setText("ANT1 Channel");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
buttonClickAnt(evt);
}
});

jButton2.setText("SKY Channel");

jInternalFrame1.setBackground(new java.awt.Color(0, 51, 51));
jInternalFrame1.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(255, 255, 51)));
jInternalFrame1.setResizable(true);
jInternalFrame1.setVisible(true);
jInternalFrame1.addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
trip(evt);
}
public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
}
public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
}
});

javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
jInternalFrame1Layout.setHorizontalGroup(
jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 259, Short.MAX_VALUE)
);
jInternalFrame1Layout.setVerticalGroup(
jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 216, Short.MAX_VALUE)
);

jMenu1.setText("File");
jMenuBar1.add(jMenu1);

jMenu2.setText("Edit");
jMenuBar1.add(jMenu2);

setJMenuBar(jMenuBar1);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
.addComponent(jButton2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGap(28, 28, 28)
.addComponent(jInternalFrame1))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)))
.addContainerGap(30, Short.MAX_VALUE))
);

pack();
}//

private void buttonClickAnt(java.awt.event.MouseEvent evt) {

try {
QTSession.open();
FileDialog fd = new FileDialog (this,"Select source movie",FileDialog.LOAD);
fd.show();
if (fd.getFile() == null)
return;

// get movie from file
File f = new File (fd.getDirectory(), fd.getFile());
OpenMovieFile omFile =
OpenMovieFile.asRead (new QTFile (f));
movie = Movie.fromFile (omFile);

// get a Drawable for Movie, put in QTCanvas
MoviePlayer player = new MoviePlayer (movie);
QTCanvas canvas = new QTCanvas();
canvas.setClient (player, true);
add (canvas);

// windows-like close-to-quit
addWindowListener (new WindowAdapter() {
public void windowClosing (WindowEvent e) {
QTSession.close();
System.exit(0);
}
});
} catch (Exception e) {
e.printStackTrace();
}

try {
movie.start();
} catch (Exception e) {
e.printStackTrace();
}

}


private void trip(javax.swing.event.InternalFrameEvent evt) {

}

// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JInternalFrame jInternalFrame1;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenu jMenu2;
private javax.swing.JMenuBar jMenuBar1;
// End of variables declaration

}
   <<Less
About | Sitemap | Contact