Dynamic Tooltip in Java
Tuesday, 1 April 2014
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 ,
- File--->New Project
- Categories—>java
- 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.
A Simple Message Box In Java
Monday, 10 February 2014
To do this job Two java components are needed
- jButton1
- jLabel1
Now we have to put this code on jButton1ActionPerformed
As written below
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt){int a=JOptionPane.showConfirmDialog(mainPanel,"Have a Good Day","Please Press Ok or Cancel",JOptionPane.OK_CANCEL_OPTION);if(a==0){jLabel1.setText("You HAve Pressed Ok");}else if(a==2){jLabel1.setText("You Have Pressed Cancel");}else if(a==-1){jLabel1.setText("Dont Play a Joke with me");}else{jLabel1.setText("Wow");}}
File Attribute Viewer
Saturday, 8 February 2014
Its is a useful Application to see hiddden attributes of a file for ex.. is it a system file ,readonly or something else.
To do this first of all we have to take some java component given below
all though it is a GUI Application or Program
- jButton
- jLabel
Now On jButton1ActionPerformed we have to write down this code
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
JFileChooser jfc=new JFileChooser();
jfc.setFileSelectionMode(jfc.FILES_ONLY);
jfc.setCurrentDirectory(new File("C:/"));
int a=jfc.showOpenDialog(null);
if(a==jfc.APPROVE_OPTION)
{
String hg=jfc.getSelectedFile().toString();
try
{
String lines;
Process procs=Runtime.getRuntime().exec("attrib "+hg);
BufferedReader binput=new BufferedReader(new InputStreamReader(procs.getInputStream()));
while ((lines = binput.readLine()) != null)
{
if (!lines.trim().equals(""))
{
lines = lines.substring(0);
filterme(lines);
}//if ends
} //while ends
}
catch(Exception esd)
{
System.out.println(esd.toString());
}
}//open dialog if ends
}
Now The filterme function
public void filterme(String getline)
{
boolean b=getline.trim().startsWith("S");
String one=getline.substring(0,6);
hamja(one.trim()); //Here calling hamja function with parameters }
Now The hamja function in this function we Filter the parameters sent by filterme function you can also use switch case for this but I have used if,else
public void hamja(String exten)
{
if(exten.equals("SHR"))
{
System.out.println("System,Hidden,Readonly");
jLabel1.setText("System,Hidden,Readonly");
}
else if(exten.equals("S R"))
{
System.out.println("Its System Readonly");
jLabel1.setText("Its System Readonly");
}
else if(exten.equals("SH"))
{
System.out.println("Its System,Hidden");
jLabel1.setText("Its System,Hidden");
}
else if(exten.equals("S"))
{
System.out.println("Its System");
jLabel1.setText("Its System");
}
else if(exten.equals("H"))
{
System.out.println("Its Hidden");
jLabel1.setText("Its Hidden");
}
else if(exten.equals("R"))
{
System.out.println("Its Readonly");
jLabel1.setText("Its Readonly");
}
else if(exten.equals("A HR"))
{
System.out.println("Its archive,Hidden,Readonly");
jLabel1.setText("Its Archive,Hidden,Readonly");
}
else if(exten.equals("A"))
{
System.out.println("Its archive");
jLabel1.setText("Its archive");
}
else if(exten.equals("A SH"))
{
System.out.println("Its archive,system,hidden");
jLabel1.setText("Its Archive,System,Hidden");
}
else if(exten.equals("A H"))
{
System.out.println("Its archive,hidden");
jLabel1.setText("Its Archive,Hidden");
}
else
{
System.out.println(exten);
}
}
