How to tie a tie

This post is not about IT. But i think it is very valuable to you. This video about how to tie a tie.I put this video because lot of gentlemen face a problem when they tie a tie. I also face that. so watch that..

Code: Save Button Code

This code is little bit difficult to understand than other code. This code want your basic SQL Language knowledge. I'll put SQL notes presently. Now you can learn it from using this link.
Basic SQL

In this problem first you have to create a database and then create a table. I create Database called SWOWNER and create table called NAME.

And i add another field called ID(Jtextfield3) in our form. We can doing this without that field. but i think it is easy for you if i add that field.

in my table(Name) ID is the primary key.
first you have to open the sql console or there have GUI based sql ide such as MySQL Control Center, PHP My admin(this is web based sql gui ide).

Code for create database.
CREATE DATABASE database_name


Then go in to the database using following commands


Then you have to create a table in the SWOWNER database called as NAME.(there's no rule that the Database name and table names are writing Block letters. Its for you for understand easy). In the table there have three field called ID(int), Fname(varchar) and Lname(varchar).

Code for create table.
CREATE TABLE table_name(colomn_name1 data_type,colomn_name2 data_type,...)

Fname varchar(255)
Lname varchar(255)



in this table ID and Fname colomn aren't be null. it should be have value and Lname can be null.
The primary key is ID.
okkkkk this are all about sql. not about java. now i write code for save button. so double click on the save(JButton1) button.

before coding to save button first you have to create db class.
right click on the your package that consist in source package >> New >> Java class >> db >> Finish
now it create db class. first you have to import sql drivers(i dont know what is the real name for that). To that we can use following command

import java.sql.*;

if we put * all of drivers are import. When we use netbeance ide it is automatically import this drivers. then write follwing commands in the db class.

private static Connection con;
public static Connection getMyConnection() throws Exception{


con = DriverManager.getConnection("jdbc:mysql://localhost:3306/SWOWNER", "root", "");

return con;



DriverManager.getConnection("jdbc:mysql://localhost:3306/Database_Name", "SQL_username", "SQL_password");

if we didn't use this db class not problem. the problem is we have to write above command all place where we connected java and sql. so i think crate db class is suitable and its very clear full.

before code the save button you have to add mysql-connector-java-5.0.7-bin.jar to libraries. To know about how to download and installed mysql java connecter click here.

to add java sql connector file to the netbeance right click on the libraries>> Add JAR/Folder >> select the file>>open. If it add it shows like following picture.

OKKkk. now we can write code for save button.

Save Button Command

try {
Connection con = db.getMyConnection();

Statement stmt = con.createStatement();

String sql=" insert into NAME() values('"+ jTextField1.getText() +"','"+ jTextField2.getText() +"','"+jTextField3.getText()+"')";


catch (Exception e)



String fn=jTextField1.getText();
String ln=jTextField2.getText();
String id=jTextField3.getText();

Connection con = db.getMyConnection();
Statement stmt = con.createStatement();
String sql="insert into NAME() values('"+ fn +"','"+ ln +"','"+id+"')";

catch (Exception e) {




String sql=" insert into Table_Name() values( ' "+ jTextField1.getText() + " ' ,'"+ jTextField2.getText() +"','"+jTextField3.getText()+"')";

jTextField1.getText() :>>this code means that get all data that in the jtextField1. this code write inside in ' " + + " ' (don't forget)

insert into Table_Name() :>> this code is sql code. we can put out column name in the bracket. If we didn't use all fields(columns) to save data we should write the coloumn names that we use to save data

i think that second code is good if you use. because it is very clear if we use large number of feilds for table and we can check each textfield.(soon on).

Ohh its over. I'm so tired. Get a brake.>>>>

Code: Exit ButtonCode

I use above example for show that. There have Exit button(jButton2). When you press Exit button it should close the forms. To that there have another simple code.

First double click on the exit button(or right click >> Event >> actionPerformed). Now it show the relevant methode. Then type this code.


Now its OK. If you press Exit button it will close. Amazing....

Code: how the curser going down when ever we press enter key

I create simple form using netbeance. In this form there have First Name(jLabel1), Last Name(jLabel2), two fields(jTextField1, jTextField2) and two buttons Save(jButton1) Exit(jButton2).

Now if i run the program it display simple form. I add First Name in to the Jtextfield1 and press enter. The curser didn't go to other field. PROBLEM???????

To solve this problem there have code. In this form i want to first add first name and then second name. So first go to the First Name textfield(Jtextfield1). Then Right click >> Events >> Key >> KeyPressed. Then show that methode. So there you have to write some small code.

if (evt.getKeyCode() == 10) {



10 meance if you press enter. This code saying, if you press enter at Jtextfield1 (==10) curser should go to the Jtextfield2.

It's very simple.. Enjoy with it.

How to create GUI using Netbeance IDE

In java we can execute program two ways.
  1. Command Line
  2. Graphical User Interface(GUI)
if you execute your program using DOS command prompt it is belongs to command line execute mode. This is not user friendly. Today this type software use is rare. Now a day people trend is using GUI to execute java. in this post i hope to write how to design simple form using netbeance ide. if you want design some software i recommended that first design the all forms that consist in your software in a paper. So you can freely design your software forms.(but it is your choice) . Ok friend now we look at how to create java application in netbeance. i put the all steps in snaps.

Step 1: double click in the netbence IDE(ha ha ha).

Step 2:File >> New Project
Then show that dialog box. Select Java application and press next button.

Step 3:

install java

If your machine not available java???? How do you know that? Yes. You can know that java installed to your machine or not. There have various ways.
  1. Control panel >> check that java were installed.(if java were install the icon will show)
  2. In command line type javac and press enter >> show some symbols and some valid commands.

  • Warning:
To show these things you have to set the path. I will show you how to set the path in presently.

Above steps are primary steps to know that machine had install java or not. OK. Do you have java in your machine??? Yes. so this below instructions are not relevant to you. But i think that it can improve your knowledge. Now i put how the java installed to the machine.

Installation of JAVA

To install java first you have to go to the web site. You can go to that site using following link.

After click the link you came there. Then select platform(Windows, Linux, Salaries,etc ). Then click download button. Then ask that your user name and password. If you regitered there you can add your user name and password. If you not its not problem. You can skip this step.

Goal of this blog


I'm kalpa prasad. Undergraduate in University of colombo school of computing(UCSC) in sri lanka. Now a days we(our group) have to create software for our printing department. So we decide to create a standalone stock handling system using java. I also beginner to the java. So i think in this blog we can share knowledge. I post all of things that i knowing and you can comment for that and we can share our knowledge and keep it up.this is the main goal of this blog.

I think that beginners for java can join with this blog and they can get lot of knowledge. I would like to invite all of expertise in java to join with us and share knowledge. At the end of this program if you get something of this blog it is the major thing of this blog. The name of this blog is swowner. This means Software Owner. I believe that end of this blog you can be a Software Owner. So finely i would like to invite all of the people who is interest about java to join with

All the best and thank you...

Powered by Blogger
Creative Commons License
Expert by kalpa prasad gamage is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
Based on a work at
Permissions beyond the scope of this license may be available at