Skip to content
August 26, 2011 / Narayan

Blog has been transferred.

Hello user,
All the blogs and the updates are now available on the http://blog.ngopal.com.np .I’ve stopped blogging at here. This blog consists all the blog posts related:

  • Java
  • JavaFX
  • Android (soon)

 

Have fun !

Thanks. and Good Bye.🙂

November 6, 2010 / Narayan

Building Facebook application

Hello reader ,

This post is almost related to facebook platform  We’ll cover up first how to setup our application on facebook .All you need to do is go to Facebook Developer and register a new application. Please follow the process as below(according to Nov 6 2010):

After you have registered your application your page goes to appliation setting.After all you can see step by step process to set your application.The main about is simple just give name of your application and some description and leave everything as it is.

Next for Site domain You need to have select proper domain for your application where your application is living otherwise you will not be able to access many function of facebook when your app is on web.

Facebook Integration menus is main setting part of your application choose your own unique application domain e.g. testmyapp but don’t use any special char , only character of lowercase. Then give fully qualified url of your application where your application lives but remember the url must end with either / or ? (e.g.  http://example.com/myapp/  or http://example.com/myapp/app.php? ). I like iframe because it’s easy than fbml with no any tag restriction. Finally use Bookmark url as of CanvasPage urlAt last, it’s the Advance tab which is simple.The facebook automatically redirects to the url ->Deauthorize Callback when any user just denied your application to allow your app to use his/her basic info or data. Use canvas session parameter which is very good practice of authentication of facebook user.

After all you just save the setting. Now you can see your application by going to http://apps.faecbook.com/your_unique_app_domain

Thanks for watching this article.Please be free to comment and share your views.

September 14, 2010 / Narayan

Facebook and Twitter updates from JavaFX

Hello I’ve developed one new javafx application which is very easy and fast . From this application you can update your facebook and twitter status at once without any time delay.It’s very easy to use.

Features:

  • Follow to twitter users
  • Update facebook status
  • Easy to find tweets of friends
  • Gives  recent 20 tweets of any users
  • Favourites and Delete function for tweets.
  • Shrinking the long url via bit.ly
  • Connect your facebook with twitter and get fb user’s tweets

Screenshots:

The appication is available at below links(Please ensure that you have installed java ):

July 2, 2010 / Narayan

SLC 2067 Result

The Office of the Controller of Examinations (OCE), Sanothimi, on Friday published the results of the School Leaving Certificate (SLC) 2066 examinations which was held last year. 64.31 percent students passed the SLC 2066, according to the Controller of Examinations (OCE) Sanothimi, Bhaktapur. Altogether 456,719—regular 412,592 and exempted 44,127—examinees had faced the exams. According to OCE, altogether 247,689 out of 412,592 regular students have passed the examinations this year. SLC Result will be available here soon. P.S. The Offical site of The Office of the Controller of Examinations, Department of Education were already crashed due to heavy traffic on those sites. So you can get your slc result from

http://slc.webnep.com.np

June 30, 2010 / Narayan

Adding JLabel in JTable

Hello guys,

This post is related to the Swing of Java. Mostly in JTable we can see that we need the icons in a table for the reliability and RIA of software for the front-end user. So to use icon we used to import the .png/.jpg/.gif in our project. Firstly you need to know how the JTable cell are being rendered and we need to know the model of the JTable.

You can refer to the api:

Ok now let’s move to the main Job.

We need to know which one column is need to place an icon. Futher more the table must be made from our own custom Table Model. Not only that we need to add a table cell renderer . Our main motto is to add a JLabel in a Cell of JTable. After you have referred to the API it would be easier to deal with the cell renderer. This cell renderer can be obtained by extending DefaultTableCellRenderer.

Source Code for CellRenderer:


import javax.swing.JLabel;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class Renderer extends DefaultTableCellRenderer{

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
         boolean hasFocus, int row, int column)
     {

        if(value instanceof JLabel){
           //This time return only the JLabel without icon
            return (JLabel)value;
        }

        else
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

     }
}

In the same way i’ll create a extended DefaultTableModel


import javax.swing.JLabel;

class MyModel extends javax.swing.table.DefaultTableModel{

    Object[][] row = {{new JLabel("Row 1 Col 1"), "Row 1 Col 2", "Row 1 Col3"},
                      {new JLabel("Row 2 Col 1"), "Row 2 Col 2", "Row 2 Col3"},
                      {new JLabel("Row 3 Col 1"), "Row 3 Col 2", "Row 3 Col3"},
                      {new JLabel("Row 4 Col 1"), "Row 4 Col 2", "Row 4 Col3"}};

    Object[] col = {"Column 1", "Column 2", "Column 3"};

    public MyModel (){

	//Adding columns
        for(Object c: col)
            this.addColumn(c);

	//Adding rows
        for(Object[] r: row)
            addRow(r);

    }

    @Override

    public Class getColumnClass(int columnIndex) {
        if(columnIndex == 0)return getValueAt(0, columnIndex).getClass();

        else return super.getColumnClass(columnIndex);

    }

}

Now we’ll create a small app extending JFrame and utilizing the above classes.


import javax.swing.*;
import ftp.gui.IconTableCellRenderer;

public class MyTableTest extends JFrame{
    public MyTableTest(String title){

        super(title);
        showGUI();

    }

    public void showGUI(){

        JTable table = new JTable();
        table.setModel(new MyModel());//invoking our custom model
        table.setDefaultRenderer(JLabel.class,  new Renderer());// for the rendering of cell
        JScrollPane jp = new JScrollPane(table);
        getContentPane().add(jp);
        setVisible(true);
        setSize(500,300);

    }

    public static void main(String[] args) {
        MyTableTest t = new MyTableTest("Table Custom");
    }

}

After all the output must be like this:

Output

To make the JLabel selected as other cell of JTable.

For this you need to add some more code in Cell Renderer.

Modified Cell Renderer for selection of JLabel

import javax.swing.JLabel;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

public class Renderer extends DefaultTableCellRenderer{

    public void fillColor(JTable t,JLabel l,boolean isSelected ){
        //setting the background and foreground when JLabel is selected
        if(isSelected){
            l.setBackground(t.getSelectionBackground());
            l.setForeground(t.getSelectionForeground());
        }

        else{
            l.setBackground(t.getBackground());
            l.setForeground(t.getForeground());
        }

    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
         boolean hasFocus, int row, int column)
     {

        if(value instanceof JLabel){
            JLabel label = (JLabel)value;
            //to make label foreground n background visible you need to
            // setOpaque -> true
            label.setOpaque(true);
            fillColor(table,label,isSelected);
            return label;

        }

        else
            return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
     }

}

Now the output must be something like this:

output

To add Icon on JTable Cell

For adding icon on JTable you can simply add a line of code in your Renderer.

I’ve just added one line code in the above DefaultTableCellRender extended class i.e. Renderer


//In the method of getTableCellRendererComponent

        if(value instanceof JLabel){
            JLabel label = (JLabel)value;
            //you can add the image here
            label.setIcon(new ImageIcon(getClass().getResource("folder.png")));
            label.setOpaque(true);
            fillColor(table,label,isSelected);

            return label;
        }

//other stuff

Output:

output with icon

That’s all for today.

Thanks you and Don’t hasitate on giving comment.

May 7, 2010 / Narayan

JavaFX 1.3 in Netbeans 6.5 or higher

Many developer of JAVAFX are very eager to know how is the JavaFX 1.3 and what are the new facilities. But what if any one tells please update your Netbeans to 6.9(beta).
You would probably say : “Oh ! Boring again updating Netbeans to 6.9 ?? It’s too embrassing..”.

So to get rid of this I can guide you how can a Netbeans be compatible with JavaFX 1.3 . Check this out here

April 28, 2010 / Narayan

New feature of Javafx 1.3: Tooltip at Control and Node

Today I’m going to show how to get the Tooltip on rollover of any object. Firstly check out the API of JavaFX 1.3 ToolTip. We use Tooltip on various application for the reference to the user. We especially use this feature for Object,Button or any Image.

Let’s see how the tooltip works.

Requirement:

Firstly you need to make any Object (only from javafx.scene.control which I’ll tell later.) of JavaFx e.g. Button,PasswordBox,TextBox,Label,ComboBox etc.

Sample Code (For making ToolTip):

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Tooltip;

/**
 * @author JAVANEPAL
 */

var submit = Button {
	text: "Submit"
        tooltip:Tooltip{
            text:"It's a button"
        }
}

Stage {
    title: "Application title"
    scene: Scene {
        width: 250
        height: 80
        content: [
            submit
        ]
    }
}

Output:(you can see “It’s a button” as tooltip of Button)

ToolTip

Now the question comes what to do when I would like to make a tooltip for any shape of Javafx like : Rectangle, Circle, Polygon, etc. or on any Nodes. So for that you need to have a small trick .
Let’s have a code of making one Rectangle:

var myRect = Rectangle {
	x: 10, y: 10
	width: 140, height: 90
	fill: Color.GRAY
}

then let’s make one Tooltip variable.

var mytip = Tooltip{
    text:"It's a tooltip for shapes or Nodes too"
}

As we know that the tooltip only works on javafx.scene.control classes
but we are having some tricks here. Let’s put the Rectangle and Tooltip at a Group class’s content[]

var myGroup=Group {
       
	content: [
		myRect,mytip
	]
        //This is helpful for the rollover
        //and display tooltip
        onMouseEntered: function (e:MouseEvent): Void {
                 mytip.activate();
        }
        //This is helpful for the rollout
        //and quit tooltip
        onMouseExited: function (e:MouseEvent): Void {
            mytip.deactivate();
        }

}

In above code we have used the rollover event in Group, which helps us to run the tooltip and rollout event for the disable of tooltip.
Finally it’s finished we have made the Tooltip shown at Nodes too.

Source code for Tooltip on Nodes

import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.scene.control.Tooltip;
import javafx.scene.shape.Rectangle;
import javafx.scene.paint.Color;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;

/**
 * @author JAVANEPAL
 */


var myRect = Rectangle {
	x: 10, y: 10
	width: 140, height: 90
	fill: Color.GRAY
}
var mytip = Tooltip{
    text:"It's a tooltip for shapes too"
}

var myGroup=Group {
       
	content: [
		myRect,mytip
	]
        //This is helpful for the rollover
        //and display tooltip
        onMouseEntered: function (e:MouseEvent): Void {
             mytip.activate();
        }
        //This is helpful for the rollout
        //and quit tooltip
        onMouseExited: function (e:MouseEvent): Void {
            mytip.deactivate();
        }

}


Stage {
    title: "Application title"
    scene: Scene {
        width: 250
        height: 120
        content: [
            myGroup
        ]
    }
}

Output:

Javafx Tooltip