Showing posts with label Semester 7. Show all posts
Showing posts with label Semester 7. Show all posts

PHP Examples - Files


PHP Examples - Files

Program:

<html >
<head>

<title>PHP Example 12 : FILES</title>
</head>

<body>

<?php
 
 echo "PHP Example 12";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"FILES";
 echo"</h1>";
 echo"<br/>";

 $filename="testfile.txt"; // Filename 
 
 $f1=fopen("$filename","w"); // Opening file in write mode
 echo "<br/>testfile.txt created.<br/>";
 fwrite($f1,"www.2k8618.blogspot.com"); // Writing data to file
 echo "<br/>Data written.<br/>";

 fclose($f1); //File closed
// echo "<br/>File closed.<br/>";


 $f2=fopen("$filename","r"); // Opening file in read mode

 $dataop= fread($f2,25); // Data read from file
 
 echo "<br/>Data read.<br/>";
 echo $dataop;
 fclose($f2);
  
 // unlink($filename); // to delete file
 

 echo"<br/>";

 echo "<br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>

Output:



PHP Examples - Session - Pageviews

PHP Examples - Session - Number of Pageviews

Program:

<?php

 session_start(); // Starting PHP Session
 if(isset($_SESSION['pageviews'])) // Checking Session variable is set or not  
  $_SESSION['pageviews']+=1;
 else
  $_SESSION['pageviews']=1; // Setting Session variable 
 
 //echo $_SESSION['pageviews'];

?>  
<html >
<head>
<title>PHP EXAMPLE 11 : SESSION </title>
</head>

<body>

<?php
 
 echo "<br/>PHP Example 11";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"SESSION : Number of Pageviews";
 echo"</h1>";
 echo"<br/><br/>";
 echo "<b><h2> Number of Page Views: ".$_SESSION['pageviews']."</h2></b>";
 
 echo "<br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>
</body>
</html>


Output:








PHP Examples - Student Details - Delete Data From Database - Form

PHP Examples - Student Details
Delete Data From Database -  Form

Program:

// php10.php

<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHP EXAMPLE 9 : Database with Form - Deletion </title>
</head>

<body>

<?php
 
 echo "<br/>PHP Example 9";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"Delete Data From DATABASE";
 echo"</h1>";
 echo"<br/>";
 
 // echo"<br>CONNECTING...";
 $con = mysql_connect("localhost","root","");  // Connecting to the database
 if(!$con)
  die('Connection Failed'.mysql_error());
 echo"<br>CONNECTED...";
 if(!mysql_select_db("DB1",$con)) 
 {
  if(mysql_query("CREATE DATABASE DB1",$con)) // Creating database
   echo"<br><br>DB1 Created...";
  else
   echo 'Error Occured...'.mysql_error();
  
  mysql_select_db("DB1",$con);  // Creating tables
  
  mysql_query(" CREATE TABLE Students(
  Rollnum int NOT NULL,
  Name varchar(20),
  Mark int,
  PRIMARY KEY(Rollnum) )",$con);
 }
 $data= mysql_query(" SELECT Rollnum FROM Students ",$con); // Retreiving data
 echo"<center>
 <h2><b><u> STUDENT DETAILS </u></b></h2>
 <form method=\"post\" action=\"deletedata.php\"><br/><br/><br/>
 Select Roll Number: <select name=\"selection\">";

 while($rec=mysql_fetch_array($data))
 {
  echo "<option>".$rec['Rollnum']."</option>";  
 }
 
 echo "</select>
 <input type=\"submit\" value=\"Delete\" />
 </form>
 </center>";
 mysql_close($con);  // Closing connection
?>
</body>
</html>

// deletedata.php

<html >
<head>

<title>PHP EXAMPLE 9 : Database with Form - Deletion</title>
</head>

<body>
<?php
 
 echo "<br/>PHP Example 9";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"Delete Data From DATABASE";
 echo"</h1>";
 echo"<br/>";
 
 //echo $_POST['selection'];
 
 echo"<br>CONNECTING...";
 $con = mysql_connect("localhost","root","");  // Connecting to the database
 if(!$con)
   die('Connection Failed'.mysql_error());
 echo"<br>CONNECTED...";
 if(!mysql_select_db("DB1",$con)) 
 {
  if(mysql_query("CREATE DATABASE DB1",$con)) // Creating database
   echo"<br><br>DB1 Created...";
  else
   echo 'Error Occured...'.mysql_error();
  mysql_select_db("DB1",$con);  // Creating tables
  mysql_query(" CREATE TABLE Students(
  Rollnum int NOT NULL,
  Name varchar(20),
  Mark int,
  PRIMARY KEY(Rollnum) )",$con);
 }
 $deleteqry="SELECT * FROM Students where Rollnum =". $_POST['selection'];
 $data1= mysql_query($deleteqry,$con); // Retreiving data
  
  //echo $data1;
  if($rec=mysql_fetch_array($data1))
   echo "<br/>Deleting...<br/>".$rec['Rollnum']." ".$rec['Name']." ".$rec['Mark']."<br/>";  
  else
   die( "<br/> Error in database access...".mysql_errno());  
  
  $deleterec = "DELETE FROM Students WHERE Rollnum=".$_POST['selection'];
 if(!mysql_query($deleterec,$con))
   die( "<br/> Error in deletion...".mysql_errno());  
 echo"<br><br>Record Deleted...<br/> Updated Table...";    

$data= mysql_query(" SELECT * FROM Students ",$con); // Retreiving data

 echo "<table border='2'>
   <tr> 
   <th> Roll No</th>
   <th> Name</th>
   <th> Mark </th>
   </tr>";

 while($rec=mysql_fetch_array($data))
 {
  echo "<tr><td>".$rec['Rollnum']."</td><td>".$rec['Name']."</td><td>".$rec['Mark']."</td></tr>";  
 }
 echo"</table>";
 
 // mysql_query(" DROP DB1 ",$con);
 mysql_close($con);  // Closing connection

 echo "<br/><br/><br/><br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>

Output:



PHP Examples - Form - Insert Data To Database

PHP Examples - Form 
 Insert Data To Database

Program:
// php9.php
<html >
<head>
<title>PHP EXAMPLE 9 : Database with Form - Insertion </title>
</head>

<body>

<?php
 
 echo "<br/>PHP Example 9";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"Insert Form Data To DATABASE";
 echo"</h1>";
 echo"<br/>";
?>
<center>
<h2><b><u> STUDENT DETAILS </u></b></h2>
<form method="post" action="insertdata.php"><br/><br/><br/>
Roll No: <input type="text" value="" name="rollno"/><br/><br/><br/>
Name: <input type="text" value="" name="name1"/><br/><br/><br/>
Mark: <input type="text" value="" name="mark"/><br/><br/><br/>
<input type="submit" value="Submit" />

</form>
</center>
</body>
</html>




// insertdata.php

<html >
<head>

<title>PHP EXAMPLE 9 : Database with Form - Insertion</title>
</head>

<body>
<?php
 
 echo "<br/>PHP Example 9";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"Insert Form Data To DATABASE";
 echo"</h1>";
 echo"<br/>";
 
 echo"<br>CONNECTING...";
 $con = mysql_connect("localhost","root","");  // Connecting to the database
 if(!$con)
   die('Connection Failed...'.mysql_error());
 echo"<br>CONNECTED...";
 if(!mysql_select_db("DB1",$con)) 
 {
  if(mysql_query("CREATE DATABASE DB1",$con)) // Creating database
   echo"<br><br>DB1 Created...";
  else
   echo 'Error Occured...'.mysql_error();
  mysql_select_db("DB1",$con);  // Creating tables
  mysql_query(" CREATE TABLE Students(
  Rollnum int NOT NULL,
  Name varchar(20),
  Mark int,
  PRIMARY KEY(Rollnum) )",$con);
  echo"<br><br>Table  Students Created...";  
 }

 
  
 echo"<br><br>Table  Students Created...";  
   // Inserting data
 $insertst = "INSERT INTO Students VALUES ('$_POST[rollno]','$_POST[name1]','$_POST[mark]')";
 if(!mysql_query($insertst,$con))
   die( "<br/> Error...".mysql_errno());  
 echo"<br><br>Records added...<br/> Updated Table...";    
 $data= mysql_query(" SELECT * FROM Students ",$con); // Retreiving data

 echo "<table border='2'>
   <tr> 
   <th> Roll No</th>
   <th> Name</th>
   <th> Mark </th>
   </tr>";

 while($rec=mysql_fetch_array($data))
 {
  echo "<tr><td>".$rec['Rollnum']."</td><td>".$rec['Name']."</td><td>".$rec['Mark']."</td></tr>";  
 }
 echo"</table>";
 
 // mysql_query(" DROP DB1 ",$con);
 mysql_close($con);  // Closing connection

 echo "<br/><br/><br/><br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>

PHP Examples - Cookie - Time of Last Visit


PHP Examples - Cookie - Time of Last Visit


Program:
<html >
<head>

<title>PHP Example 8 : COOKIE</title>
</head>

<body>
<?php
 
 echo "<br/>PHP Example 8";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"COOKIE";
 echo"</h1>";
 echo"<br/>";
 echo "Server Time:\t".date("D,d M Y , g:i:s A")."<br/>";
 // echo "Cookie created...";

 if(isset($_COOKIE['time_of_visit']))
 {
  $y=$_COOKIE['time_of_visit'];
  echo "<br/>You visited here : $y";
 }
 $x=60*60*24*60+time();
 setcookie('time_of_visit',date("D,d M Y , g:i:s A"), $x);

 echo "<br/><br/><br/><br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";

?>

</body>
</html>



Output:

PHP Examples - Function


PHP Example - Function

Program:
<html >
<head>

<title>PHP Example 6 : FUNCTIONS</title>
</head>

<body>
<?php
 
 echo "<br/>PHP Example 6";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"FUNCTIONS";
 echo"</h1>";
 echo"<br/>";
 
 function add($a,$b) //function for the addition
 {
  return $a+$b;
 }
 $x=20;
 $y=30;
 $z=add($x,$y);
 echo "<br/>Adding $x & $y   $z";
 
 echo "<br>Adding 10 & 20  ".add(10,20);
 
 echo "<br/><br/><br/><br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";

?>


</body>
</html>

PHP Examples - Databases - Mysql



PHP Examples 
 Databases - MySQL

  • Connect to database
mysql_connect("hostname","user","password");
  • Create database
mysql_query("CREATE DATABASE DB_name", connection);
  • Create table
mysql_query(" CREATE TABLE Table_name ( Name varchar(20),...)", connection);


...

Program:


<html >
<head>

<title>PHP Example 7 : DATABASES (MySQL)</title>
</head>

<body>
<?php
 
 echo "PHP Example 7";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"DATABASES: ( MySQL )";
 echo"</h1>";
 echo"<br/>";

 
 echo"<br>CONNECTING...";
 $con = mysql_connect("localhost","root","");  // Connecting to the database
 if(!$con)
   die('Connection Failed'.mysql_error());
 echo"<br>CONNECTED...";
 if(!mysql_select_db("DB1",$con)) 
 {
  if(mysql_query("CREATE DATABASE DB1",$con)) // Creating database
   echo"<br><br>DB1 Created...";
  else
   echo 'Error Occured...'.mysql_error();
  mysql_select_db("DB1",$con);  // Creating tables
 }

 mysql_query(" CREATE TABLE Students(
  Rollnum int NOT NULL,
  Name varchar(20),
  Mark int,
  PRIMARY KEY(Rollnum) )",$con);
  
 echo"<br><br>Table  Students Created...";  
   // Inserting data
 mysql_query(" INSERT INTO Students VALUES ('1','NIDHEESH','91')",$con);
 mysql_query(" INSERT INTO Students VALUES ('2','SAJITH','96')",$con);
 mysql_query(" INSERT INTO Students VALUES ('3','IRSHAD','88')",$con);
 mysql_query(" INSERT INTO Students VALUES ('4','AJISH','90')",$con);
 mysql_query(" INSERT INTO Students VALUES ('5','BINDU','90')",$con);
 mysql_query(" INSERT INTO Students VALUES ('6','RAFEEQ','95')",$con);
 echo"<br><br>Records added...";  
   
 $data= mysql_query(" SELECT * FROM Students ",$con); // Retreiving data

 echo "<table border='2'>
   <tr> 
   <th> Roll No</th>
   <th> Name</th>
   <th> Mark </th>
   </tr>";

 while($rec=mysql_fetch_array($data))
 {
  echo "<tr><td>".$rec['Rollnum']."</td><td>".$rec['Name']."</td><td>".$rec['Mark']."</td></tr>";  
 }
 echo"</table>";
 
 // mysql_query(" DROP DB1 ",$con);
 mysql_close($con);  // Closing connection

 echo "<br/><br/><br/><br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>

PHP Examples - Arrays

PHP Examples 

 Arrays

Program:
<html >
<head>

<title>PHP Example 5 : ARRAYS</title>
</head>

<body>
<?php
 
 echo "PHP Example 5";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"ARRAYS";
 echo"</h1>";
 echo"<br/>";

 $array1 = array(5,3,7,6,1,2,9);  //Creating array 
 $array1[] = 8;
 $array1[] = 4;
 
 $n=count($array1); // Counting no of elements
 
 echo"<br/><b> Before sorting: </b> ";
 for($i=0;$i<$n;$i++)  //Printing array elements 
  echo $array1[$i]." ";  

 for($i=0;$i<$n;$i++)  //Sorting
 for($j=$i+1;$j<$n;$j++)
 {
  if($array1[$i]>$array1[$j])
  {
   $temp=$array1[$i];
   $array1[$i]=$array1[$j];
   $array1[$j]=$temp;
   }
 }
 
 echo"<br/> <b>After sorting: </b>";
 for($i=0;$i<$n;$i++)
  echo $array1[$i]." ";
 echo"<br/>";

 $arraysum = array_sum($array1);  // Calculating sum of the elements in the array 
 echo"<br/><b> Sum of the elements : </b>$arraysum";
 echo"<br/>";
 
 echo "<br/><b>Checking whether element is present in the array or not...</b>";
 if(in_array(5,$array1))      // Checking whether element is present in the array or not
  echo "<br/>5 is present in the array... ";
 else 
  echo "<br/>5 is not present in the array... ";
 echo"<br/>";

 echo "<br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>



Output:






PHP Examples - Echo - PHP Program

Program:
<html >
<head>

<title>PHP Example 2</title>
</head>

<body>
<?php
 
 echo "PHP Example 2";
 echo"<br/>"; // line break
 echo"<h1>";
 echo"ECHO";
 echo"</h1>";
 echo"<br/><li>";
 echo"Displays the text or values of a variables.";
 echo"</li><br/><li>"; // line break & list item
 
 $x="HELLO PHP..."; //Variable x
 echo $x;
 echo"</li><br/><li>"; 
 
 $y= 2;
 echo 'PHP Example:'.$y; 
 echo"</li><br/><li>"; 
 
 echo'PHP'; //single quotes
 echo"</li><br/><li>";
 
 echo"'PHP'"; //to display string in single quotes
 echo"</li><br/><li>";
 
 echo"\"PHP\""; //to display string in double quotes
 echo"</li>";

 echo "<br/><b>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</b>";
?>


</body>
</html>
Output:





A Simple PHP Program - PHP Examples

Program:

<html >
<head>

<title>PHP Example 1</title>
</head>

<body>
<?php
// comments

/* multiline
 comments
 examples
 */
 
 echo "PHP Example 1";
 echo"<br/>";
 echo"<h1>";
 echo"WWW.2K8618.BLOGSPOT.COM";
 echo"</h1>";
 echo"<br/>";
 // Making text bold
 echo "<b>";
 echo  "www.2k8cse.tk";
 echo"</b>";
?>


</body>
</html>

Output:






Kannur University Exam Results - Semester 7 - BTech


Kannur University Examination Results - Btech -2012
Semester 7 - Regular/Supplimentary/Improvement
  
Kannur university has announced the seventh semester btech results on 12th may 2012. The students can obtain their results from the website of kannur university.



E-Tendering - Computer Science & Engg. - Miniproject

Computer Science & Engineering - Miniproject
Electronic Tendering (E-Tendering)
ASP.Net - SQL Server - C#
Abstract:
 
Electronic Tendering is carrying out the traditional tendering process in an electronic form, using the internet. E-Tendering (Electronic Tendering System) is an online service. It provide everyone involved in the Business industry, especially Suppliers and companies, with an efficient, secure, simple and cost-effective tools to facilitate the best use of Tender Information and to enhance our business outcomes - anywhere, anytime.
It is created with following missions in mind.
  • To provide rapid calling of Tender and to reach a huge number of Suppliers, and receive large number of bids from suppliers from anywhere at any time.  All the Tender information is at a single button click.
  • It also organizes all of the Tender history and bid information that they typically provide to the website at the time of service.
  • It also allows the Suppliers to know whether the Tender submitted selected or not in a few seconds.

The proposed System is an online service system. Here the companies who have a work or need some good, create a Tender online. The company is a registered User of the portal. He can manage the tender using the username and password. The company can create more than one tender at a time. Anybody who visit the site can see the tender, if supplier satisfy with the tender create a bid to the tender. Applying to the tender is a simple process. Supplier login into the site and create a bid in online. The bid reach the company in a second. The company can evaluate different bids and release the contract to the appropriate supplier Using E-Tendering the users can:
  • Raise Indents as per the requirement ·
  • Approve indents online
  • Sell Tenders
  • Receive Bids
  • Award Contract / PO
  • Evaluate Tenders
  • Create and publish NIT
  • Includes a variety of off techniques such as RFPs, quotes, auctions and reverse auctions.

Using E-Tendering, the suppliers can
  • Receive notification of the relevant tenders
  • Purchase tenders document
  • Submit Bids Online
  • Track the status of their bids

The tenders are published by the companies who are in demand of the goods. Using the E-Tendering System, the users of the participating companies will:
  • Raise indents as per the requirements
  • Approve Indents online
  • Create Tender
  • Approve Tender and
  • Publish Tender online

The users who registered as suppliers of this system will:
  • Receive tender notification
  • Submit Tenders

The system will auto evaluate the bids of the suppliers and guide the user to select its apt supplier.

The system can be developed using ASP.NET and MSSQL Server or any other web application developer.







Content Management System - Miniproject - Computer Science & Engineering


Computer Science & Engineering - Miniproject  
CONTENT MANAGEMENT SYSTEM
php - mysql
Abstract:
Content management systems nowadays are used to manage complex publications far more often than some years ago. The basic principles are the separation of structure, content and presentation, an exactly defined workflow management and the management of content in the form of small units, so called assets. This leads to improved quality, better reusability and reduced costs.
The Web Content Management System (Web CMS) is content management system software, implemented as a Web application, for creating and managing HTML content. It is used to manage and control a large, dynamic collection of Web material (HTML documents and their associated images). The Web CMS facilitates content creation, content control, editing, and many essential Web maintenance functions.
A content management system (CMS) is a system providing a collection of procedures used to manage work flow in a collaborative environment. These procedures can be manual or computer-based. The procedures are designed to do the following:
  •  Allow a large number of people to contribute and to share stored data
  •  Control access to data, based on user roles (defining which information users or user groups can view, edit, publish, etc.)
  •  Aid in easy storage and retrieval of data
  •  Control of data validity and compliance
  •  Reduce repetitive duplicate input
  • Improve the ease of report writing
  • Improve communication between users






Network Monitoring and Controlling System - Miniproject - Computer Science & Engineering - Java


Computer Science & Engineering - Miniproject 
Networking Monitoring and Controlling System
Java - NetBeans 



ABSTRACT

Network Monitoring and Controlling Software are exclusively designed for monitoring and controlling systems/users present in a Local Area Network of an organization. NMCS is a client server based system and utilizes the possibilities of Remote Method Invocation (RMI). NMCS is designed in such a way that the administrator can monitor  and control  the systems present in the network. There are two levels of privileges viz. administrator and user.. In the proposed system each user is provided with a unique Id and password. The system maintains a database of this information’s. The user can change their password, if required.
The PC Controlling module displays the remote PC's desktop on the screen of your local PC just like a surveillance camera. The remote connection could be established on LAN. In this module the administrator can view all the PC’s in his Office with details of the user logged in. The administrator and users/staffs can chat or send private messages to a particular staff. Similarly an user can send messages to another user with the administrators permission Remote Power Management allows you to ON, shutdown and restart remote computers. Administrator can send a common message like meeting or asking to logoff the system for some particular reason, something like that to all Online Users or Administrator can select particular users and send the common message to them.

Student Management System Using SMS - Miniproject - Computer Science & Engineering - Java - NetBeans

Computer Science & Engineering - Miniproject
Student Management System Using SMS
Java - MySQL - NetBeans



ABSTRACT
The Student Management System using SMS is designed to automate the  Student Management System using text messages. It can handle details of a student such as marks, attendance, etc. The system is based on the text messages sent from a GSM mobile phone. The proposed system is to computerize the various processes of the student management system by sending sms to the server from any remote location. The system has two types of accessing modes, the administrator and the user. The administrator manages the student management system. The user access the data in the system using sms. The main objective is to automate the easy storing & retrieval of data through text messages by an authenticated person. Data regarding the users such as personal details, academic details, complaints, etc. are collected and maintained in the student management system for secured process. The project uses JAVA as front-end and mysql as back end in Windows XP platform. NetBeans IDE is used for the development of the system.

The main features includes:

  • Registration of new students
  • Information of marks, attendance, etc.
  • Complaint Registration/status
  • Notification to parents.
  • Result publishing, hall tickets.
  • Notification from students,teachers, principal, or other staff...
  • Fee details
  • Other due status notification


Sum of First n Numbers - Java Swing - JProgressBar, JOptionPane Example - NetBeans - Internet & Web Programming Lab


Java Swing - JProgressBar, JOptionPane Example 
Sum of First n Numbers 
NetBeans - Internet & Web Programming Lab


Design:




Source code:
/*
 * sw13.java
 *
 * Created on 19 Oct, 2011, 6:57:22 PM
 */

package swingexamples;

import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author gcecse
 */
public class sw13 extends javax.swing.JFrame {

    /** Creates new form sw13 */
    public sw13() {
        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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jProgressBar1.setStringPainted(true);

        jLabel1.setText("Enter the limit:");

        jButton1.setText("Start");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(36, 36, 36)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(140, 140, 140)
                        .addComponent(jButton1))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(65, 65, 65)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 260, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(75, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(56, 56, 56)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 67, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(36, 36, 36)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(50, 50, 50))
        );

        pack();
    }// </editor-fold>                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        double limit=Double.parseDouble(jTextField1.getText());
        double sum=0;
        for(int i=0;i<=limit;i++)
        {
            try {
                sum += i;
                Thread.sleep(1000);
                jProgressBar1.setValue((int) (i / limit * 100));
            } catch (InterruptedException ex) {
                Logger.getLogger(sw13.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        JOptionPane.showMessageDialog(null,"The sum is:"+sum);
    }                                        

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

    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration                   

}

Area Calculation - Java Swing - JInternalFrame, JMenu Example - NetBeans - Internet & Web Programming Lab


Java Swing - JInternalFrame, JMenu Example 
Area Calculation 
NetBeans - Internet & Web Programming Lab

Design:





Source code:

/*
 * sw12.java
 *
 * Created on 19 Oct, 2011, 3:54:50 PM
 */

package swingexamples;

import javax.swing.JDesktopPane;

/**
 *
 * @author gcecse
 */
public class sw12 extends javax.swing.JFrame {

    /** Creates new form sw12 */
    public sw12() {
        initComponents();
        add(jInternalFrame1);
        jInternalFrame1.setSize(400, 400);
        jInternalFrame1.hide();
        add(jInternalFrame2);
        jInternalFrame2.setSize(400,400);
        jInternalFrame2.hide();
    }

    /** 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jInternalFrame1 = new javax.swing.JInternalFrame();
        jLabel1 = new javax.swing.JLabel();
        jTextField1 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel8 = new javax.swing.JLabel();
        jInternalFrame2 = new javax.swing.JInternalFrame();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jTextField2 = new javax.swing.JTextField();
        jTextField3 = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel3 = new javax.swing.JLabel();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem2 = new javax.swing.JMenuItem();

        jInternalFrame1.setClosable(true);
        jInternalFrame1.setIconifiable(true);
        jInternalFrame1.setMaximizable(true);
        jInternalFrame1.setResizable(true);
        jInternalFrame1.setTitle("Circle Area");
        jInternalFrame1.setVisible(true);

        jLabel1.setText("Enter the radius:");

        jButton1.setText("Calculate");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

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

        jLabel8.setText("Circle");

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addGap(148, 148, 148)
                        .addComponent(jLabel2))
                    .addGroup(jInternalFrame1Layout.createSequentialGroup()
                        .addGap(71, 71, 71)
                        .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addGap(79, 79, 79)
                                .addComponent(jButton2))
                            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel8)
                                    .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 138, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 91, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(93, Short.MAX_VALUE))
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel8)
                .addGap(34, 34, 34)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addGap(52, 52, 52)
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addContainerGap(151, Short.MAX_VALUE))
        );

        jInternalFrame2.setClosable(true);
        jInternalFrame2.setIconifiable(true);
        jInternalFrame2.setMaximizable(true);
        jInternalFrame2.setResizable(true);
        jInternalFrame2.setTitle("Rectangle Area");
        jInternalFrame2.setVisible(true);

        jLabel4.setText("Rectangle");

        jLabel5.setText("Length");

        jLabel6.setText("Breadth");

        jTextField3.setText(" ");

        jButton3.setText("Calculate");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Clear");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jInternalFrame2Layout = new javax.swing.GroupLayout(jInternalFrame2.getContentPane());
        jInternalFrame2.getContentPane().setLayout(jInternalFrame2Layout);
        jInternalFrame2Layout.setHorizontalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGap(173, 173, 173)
                        .addComponent(jLabel4))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGap(85, 85, 85)
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                .addComponent(jLabel5)
                                .addComponent(jButton3, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, 111, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(jLabel6))
                        .addGap(27, 27, 27)
                        .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jTextField3)
                                .addComponent(jTextField2, javax.swing.GroupLayout.DEFAULT_SIZE, 112, Short.MAX_VALUE))
                            .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 118, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(jInternalFrame2Layout.createSequentialGroup()
                        .addGap(186, 186, 186)
                        .addComponent(jLabel7)))
                .addContainerGap(117, Short.MAX_VALUE))
        );
        jInternalFrame2Layout.setVerticalGroup(
            jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel4)
                .addGap(49, 49, 49)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel5)
                    .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(39, 39, 39)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6))
                .addGap(36, 36, 36)
                .addComponent(jLabel7)
                .addGap(31, 31, 31)
                .addGroup(jInternalFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton3)
                    .addComponent(jButton4))
                .addContainerGap(76, Short.MAX_VALUE))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Area Calculation");

        jLabel3.setFont(new java.awt.Font("DejaVu Sans", 1, 24)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("JInternal Frame Demonstration");

        jMenuBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.RAISED, java.awt.Color.pink, null));

        jMenu1.setBorder(null);
        jMenu1.setText("Select Shape");

        jMenuItem1.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem1.setMnemonic('C');
        jMenuItem1.setText("Circle");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem1);

        jMenuItem2.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        jMenuItem2.setMnemonic('r');
        jMenuItem2.setText("Rectangle");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem2);

        jMenuBar1.add(jMenu1);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap(31, Short.MAX_VALUE)
                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 574, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(73, 73, 73))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(171, 171, 171)
                .addComponent(jLabel3)
                .addContainerGap(195, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {                                           
        // TODO add your handling code here:
        this.remove(jLabel3);
        jInternalFrame1.show();
    }                                          

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        float rd= Float.parseFloat(jTextField1.getText().trim());
        double area= 3.14*rd*rd;
        jLabel2.setText("Area "+Double.toString(area));
        
    }                                        

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        this.remove(jLabel3);
        jInternalFrame2.show();
    }

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        float len = Float.parseFloat(jTextField2.getText().trim());
         float br = Float.parseFloat(jTextField3.getText().trim());
        double area=len*br;
        jLabel7.setText("Area "+Double.toString(area));
    }

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        jTextField2.setText("");
        jTextField3.setText("");
        jLabel7.setText("");
        
    }

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        jTextField1.setText("");
        jLabel2.setText("");
    }

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

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JInternalFrame jInternalFrame2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    private javax.swing.JTextField jTextField3;
    // End of variables declaration

}


File Copier - Java Swing - JProgressBar, JFileChooser Example - NetBeans - Internet & Web Programming Lab

Java Swing - JProgressBar, JFileChooser Example 
File Copier
NetBeans - Internet & Web Programming Lab

Design :


Sourcecode:
sw11.java

/*
 * sw11.java
 *
 * Created on 18 Oct, 2011, 10:31:32 PM
 */

package swingexamples;

import java.io.File;
import javax.swing.JFileChooser;

/**
 *
 * @author gcecse
 */
public class sw11 extends javax.swing.JFrame {
    JFileChooser fc=new JFileChooser();
    File from,to;
    /** Creates new form sw11 */
    public sw11() {
        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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jButton1 = new javax.swing.JButton();
        jTextField2 = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jProgressBar1 = new javax.swing.JProgressBar();
        jLabel3 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jLabel1.setText("From");

        jButton1.setText("Browse");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jLabel2.setText("To");

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

        jButton3.setText("Copy");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jProgressBar1.setStringPainted(true);

        jLabel3.setFont(new java.awt.Font("DejaVu Sans", 1, 18)); // NOI18N
        jLabel3.setText("File Copier");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(6, 6, 6)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 309, Short.MAX_VALUE))
                            .addGroup(layout.createSequentialGroup()
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jTextField2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)
                                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(30, 30, 30)))
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jButton1)
                            .addComponent(jButton2))
                        .addGap(54, 54, 54))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addContainerGap(409, Short.MAX_VALUE))))
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(192, 192, 192)
                        .addComponent(jLabel3))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(43, 43, 43)
                        .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)))
                .addContainerGap(54, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGroup(layout.createSequentialGroup()
                .addGap(148, 148, 148)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 164, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(165, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(47, 47, 47)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 56, Short.MAX_VALUE)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .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(jButton1))
                .addGap(26, 26, 26)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .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(jButton2))
                .addGap(28, 28, 28)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(32, 32, 32))
        );

        pack();
    }// </editor-fold>

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
       task t=new task(this,from,to);
       t.start();
    }                                        

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
      if(JFileChooser.APPROVE_OPTION==fc.showOpenDialog(null))
      {
          from=fc.getSelectedFile();
          jTextField1.setText(from.getAbsolutePath());
      }
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
      fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
      if(JFileChooser.APPROVE_OPTION==fc.showSaveDialog(null))
      {
          to=fc.getSelectedFile();
          jTextField2.setText(to.getAbsolutePath());
      }
    }                                        


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

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    public javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration

}



task.java

package swingexamples;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;


public class task extends Thread{
    sw11 fr;
    File src,tg;
    FileInputStream in;
    FileOutputStream out;
    task(sw11 s,File from,File to) {
      fr=s;
      src=from;
      tg=to;
    }

    @Override
    public void run() {
        int len,total,cur;
        try {
            super.run();
            byte b[]=new byte[1024];
            in = new FileInputStream(src);
            total=in.available();
            out=new FileOutputStream(tg+"/"+src.getName());
            while((len=in.read(b))>0)
            {
             out.write(b);
             cur=in.available();
             fr.jProgressBar1.setValue(100-(int)(cur/(float)total*100));
             Thread.sleep(1000);
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(task.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(task.class.getName()).log(Level.SEVERE, null, ex);
        }



    }

}


Phonebook - Java Swing - JTable Example - NetBeans - Internet & Web Programming Lab


Java Swing - JTable Example
Phonebook
NetBeans - Internet & Web Programming Lab


Design & Output:



Source code:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * sw10.java
 *
 * Created on 18 Oct, 2011, 2:28:35 PM
 */

package swingexamples;

import java.util.Enumeration;
import java.util.Vector;
import javax.swing.JOptionPane;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author gcecse
 */
public class sw10 extends javax.swing.JFrame {
      /** Creates new form sw10 */
    DefaultTableModel dtm;
    public sw10() {
        initComponents();
        jTable1.setModel(dtm=new DefaultTableModel());
        dtm.addColumn("Name");
        dtm.addColumn("Phone no");
    }

    /** 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")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        jScrollPane1.setViewportView(jTable1);

        jButton1.setText("Add Contact");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

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

        jButton3.setText("Delete Rows");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("Search");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 1, 18)); // NOI18N
        jLabel1.setText("Phonebook");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 404, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(172, 172, 172)
                        .addComponent(jLabel1))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jButton1, javax.swing.GroupLayout.DEFAULT_SIZE, 184, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 203, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 238, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(90, 90, 90)
                        .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 235, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(28, 28, 28)
                .addComponent(jLabel1)
                .addGap(18, 18, 18)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 160, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(43, 43, 43)
                .addComponent(jButton4, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jButton3)
                .addContainerGap(20, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
     Object row[]=new Object[2];
     while((row[0]=JOptionPane.showInputDialog("Enter the name:")).equals(""));
     while((row[1]=JOptionPane.showInputDialog("Enter the phone no:")).equals(""));
      dtm.addRow(row);
    }                                        

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        int t[]=jTable1.getSelectedRows();
        if(t.length>1)
           JOptionPane.showMessageDialog(null, "Please select only one row");
        else if(t.length==0)
            JOptionPane.showMessageDialog(null,"Please select a row");
        else
           dtm.removeRow(t[0]);
    }                                        

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
        int t[]=jTable1.getSelectedRows();
        if(t.length==0)
            JOptionPane.showMessageDialog(null,"Please select a row");
        else
        {
          for(int i=t.length-1;i>=0;i--)
            dtm.removeRow(t[i]);
        }
    }                                        

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {                                         
        // TODO add your handling code here:
    int count=0;
    String s=JOptionPane.showInputDialog("Enter the name:");
    Enumeration rows=dtm.getDataVector().elements();
    while(rows.hasMoreElements())
    {
       if(((Vector)rows.nextElement()).elementAt(0).equals(s))
       {
           jTable1.getSelectionModel().setSelectionInterval(count,count);
       }
     count++;
    }
    }                                        

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

    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTable jTable1;
    // End of variables declaration

}

Related Posts Plugin for WordPress, Blogger...