Showing posts with label Netbeans Ide. Show all posts
Showing posts with label Netbeans Ide. Show all posts

Dynamic Tooltip in Java

Tuesday, 1 April 2014

Sun Java Logo

Tooltip is helpful for every software users it displays the use of that feature of a software and also it make it easy for the user to work with that software.

In this project we will develop a project with Tooltip Functionality,It is developed with the help of Netbeans Ide It is a Graphical User Interface application.

Now,Open up Netbeans Ide

Go to ,

  1. File--->New Project
  2. Categories—>java
  3. Project—>Java Desktop Application

Click Next and then Finish

Now switch to design view add a jbutton from palatte

Now swtch to source view

Import the following package.

import com.sun.media.ui.ToolTip;

Declare ToolTip as class level variable like that

ToolTip tip=new ToolTip("set your text here");

find this function and write this code below it initComponents();

tip.setLocationRelativeTo(jButton1); //displays tooltip below jbutton

tip.setSize(200,50);

That’s it.

Now right click jbutton in design view and got to

Events—>Mouse—>MouseEntered

You will see the code like this

private void jButton1MouseEntered(java.awt.event.MouseEvent evt) {                                      
        tip.setVisible(true); //setting visible tooltip
}

Now again go to design view and right click jbutton

Events—>Mouse—>MouseExited

You will see the code like this

private void jButton1MouseExited(java.awt.event.MouseEvent evt) {                                     
tip.setVisible(false); //setting invisible tooltip
}

All done compile and run move cursor to jbutton and see the tooltip.

 

Play Movie From Database

Saturday, 15 March 2014

 

What You Need Is

  1. Java Version 6 or Later 
  2. Ms Sql Server 2005 or Later
  3. Netbeans Ide 6.5 or Later
  4. Os Windows 7
  5. Java Media Framework (JMF)
  6. Jdbc Odbc Connectivity
  7. Turn Off Windows 7 User Account Control (UAC)

 

STEP 1.

 

Create a database named as circuit and a Table named as Images with column named as puploads and name

Here I am providing the script

CREATE database circuit

CREATE TABLE Images
(
    [puploads] [image] NULL,
    [name] [varchar](50)

)

 

STEP 2.

 

To communicate with database java has to use Jdbc Odbc Drivers

Now Goto,

Start menu—>Control Panel—>System and Security—>Administrative Tools

—>Data Sources (ODBC)

Here is the link

http://proamrishwas.blogspot.in/2014/03/jdbc-odbc-connectivity.html

 

STEP 3.

 

Due to windows 7 doesn't give permission to read write file we have to turn off User Account Control(UAC)

Just type UAC into the start menu or Control Panel search box.

and scroll to Never Notify

 

STEP 4.

 

Now The Coding Part

Uploding Video File to database

try
       {
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
       }
       catch(ClassNotFoundException e)
       {
           System.out.println(e);
       }
      
       try
       {
       String name1=jTextField2.getText().trim();
       namex=name1;
       String pic="INSERT INTO Images([Puploads],[name]) VALUES(?,?)";
       String ure="jdbc:odbc:xer";
       Connection con=null;
       con = DriverManager.getConnection(ure,"sa","sa");
       String url=jTextField1.getText().trim();
       File f=new File(url);
       FileInputStream fis=new FileInputStream(f);
       PreparedStatement pst=con.prepareStatement(pic);
       pst.setBinaryStream(1, fis, fis.available());
       pst.setString(2,name1);
       int rxb=pst.executeUpdate();
       pst.close();
       con.close();
      
       }
       catch(Exception sd)
       {
           System.out.println(sd);
       }

 

STEP 5.

 

Now Retriving the video or movie file

try
{

String namex=jTextField2.getText().trim();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException e)
{
    System.out.println(e);
}
String ure="jdbc:odbc:xer";
Connection con=null;
  
con = DriverManager.getConnection(ure,"sa","sa");
String query = "SELECT (Puploads) from Images where name ='"+namex+"'";
//out.println(query);
ResultSet rs = con.createStatement().executeQuery(query);
if(rs.next())
{

byte[] bytearray = new byte[4096];
int size=0;
InputStream image;
image = rs.getBinaryStream(1);
File f=new File(System.getProperty("java.io.tmpdir")+"/temp.mpg");
FileOutputStream fos=new FileOutputStream(f);
while((size=image.read(bytearray))!= -1 )
{
    fos.write(bytearray);

//it will write the file in temp folder C:\Users\xxx\AppData\Local\Temp
}

image.close();
rs.close();
fos.close();
con.close();
}
}
catch (Exception exc)
{ System.out.println(exc);
}
        
 

try
{
String mdurl="file:///"+System.getProperty("java.io.tmpdir")+"/temp.mpg";
URL url=new URL(mdurl);
Player player=Manager.createRealizedPlayer(url);
Component cmpt=player.getVisualComponent();
       
Component ctrls=player.getControlPanelComponent();
cmpt.resize(600, 400);
this.add(cmpt,BorderLayout.CENTER);
ctrls.resize(600, 400);
this.add(ctrls,BorderLayout.SOUTH);
player.start();
this.resize(600, 470);
}
catch(Exception sdd)
{
            System.out.println(sdd);
  }
       
       

Basically this program first read video or movie file from database writes that file to temproray directory of windows and than it plays.

Note:-Java Media Framework not supports all media formats I have used .avi and .mpg file in this project

If you have any Query and Comments please Write down in comment Box

Thanks

Paste Long Url