Advanced Java Programming Lab Report
Advanced Java Programming Lab Report
DEPARTMENT OF COMPUTER APPLICATIONS SRM UNIVERSITY NCR CAMPUS, MODI NAGAR, GHAZIABAD-201204.
1
SRM INSTITUTE OF MANAGEMENT & TECHNOLOGY (SRM UNIVERSITY) MODINAGAR, GHAZIABAD 201204
Department of Master of Computer Application Register No: 3521130023
BONAFIDE CERTIFICATE
This is to certify that NITESH KUMAR of II nd year MCA completed the Advanced Java Programming Lab in the SRM Institute of Management & Technology, Modinagar during the academic year 2012-13.
LAB INCHARGE
Submitted for the examination held on in SRM Institute of management & technology, Modinagar - 201204
EXAMINER- 1
EXAMINER -2
Exp No.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
DATE
09-01-2012 09-01-2012 10-01-2012 10-01-2012 17-01-2012 17-01-2012 23-01-2012 23-01-2012 23-01-2012 22-02-2012 27-02-2012 05-03-2012 13-03-2012 19-03-2012 20-03-2012 21-01-2012 21-01-2012 30-01-2012 30-01-2012 13-02-2012 13-02-2012 14-02-2012 14-02-2012 15-02-2012 21-02-2012
Experiment Title
Tabbed Pane using Java Swing Scroll Pane using Java Swing Table using Java Swing Tree using Java Swing Jbutton using Java Swing Text Field using Java Swing Combobox using Java Swing Client/Server using RMI Server Content using RMI Applet Factorial using JSP Palindrome using JSP Prime Number using JSP Temperature Conversion using JSP Simple Array using JSP Display Week Days using JSP Personal Information using Java Bean Enrollment Form Using Java Bean Calendar using Java Bean Table using Java Bean Date and Time using Servlet Servlet getRequest() method Servlet postRequest() method Insert Student Data using JDBC Retrieve Student Data using JDBC Delete Student Data using JDBC
Page No
5 8 10 12 14 16 18 20 22 25 28 30 34 37 42 40 52 75 77 81 83 86 88 90 92
Aim: To write a program to display a tabbed pane using java swing. Algorithm: Step 1: Start Step 2: Create a JTabbedPane object. Step 3: Call addTab( ) to add a tab to the pane. (The arguments to this method define the title of the tab and the component it contains.) Step 4: Repeat step 2 for each tab. Step 5: Add the tabbed pane to the content pane of the applet. Step 6: End Program: import [Link].*; /* <applet code="JTabbedPaneDemo" width=400 height=100> </applet> */ public class JTabbedPaneDemo extends JApplet { public void init() { JTabbedPane jtp = new JTabbedPane(); [Link]("Cities", new CitiesPanel()); [Link]("Colors", new ColorsPanel()); [Link]("Flavors", new FlavorsPanel()); getContentPane().add(jtp); } } class CitiesPanel extends JPanel { public CitiesPanel() { JButton b1 = new JButton("New York"); add(b1); JButton b2 = new JButton("London"); add(b2); JButton b3 = new JButton("Hong Kong"); add(b3); JButton b4 = new JButton("Tokyo"); add(b4); 5
} } class ColorsPanel extends JPanel { public ColorsPanel() { JCheckBox cb1 = new JCheckBox("Red"); add(cb1); JCheckBox cb2 = new JCheckBox("Green"); add(cb2); JCheckBox cb3 = new JCheckBox("Blue"); add(cb3); } } class FlavorsPanel extends JPanel { public FlavorsPanel() { JComboBox jcb = new JComboBox(); [Link]("Vanilla"); [Link]("Chocolate"); [Link]("Strawberry"); add(jcb); } }
Aim: To write a program to display Scroll Pane using java swing. Algorithm: Step 1: Start Step 2: Create a JComponent object. Step 3: Create a JScrollPane object. (The arguments to the constructor specify the component and the policies for vertical and horizontal scroll bars.) Step 4: Add the scroll pane to the content pane of the applet. Step 5: End Program: import [Link].*; import [Link].*; /* <applet code="JScrollPaneDemo" width=300 height=250> </applet> */ public class JScrollPaneDemo extends JApplet { public void init() { // Get content pane Container contentPane = getContentPane(); [Link](new BorderLayout()); // Add 400 buttons to a panel JPanel jp = new JPanel(); [Link](new GridLayout(20, 20)); int b = 0; for(int i = 0; i < 20; i++) { for(int j = 0; j < 20; j++) { [Link](new JButton("Button " + b)); ++b; } }// Add panel to a scroll pane int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(jp, v, h); // Add scroll pane to the content pane [Link](jsp, [Link]); 8
} } Result: The program for the Scroll Pane is successfully executed. Output:
Aim: To write a program to print table with 3 column using java swing
Algorithm: Step 1: Create a JTable object. Step 2 : Create a JScrollPane object. Step 3: Add the table to the scroll pane. Step 4 : Add the scroll pane to the content pane of the applet. Program: import [Link].*; import [Link].*; /* <applet code="JTableDemo" width=400 height=200> </applet> */ public class JTableDemo extends JApplet { public void init() { // Get content pane Container contentPane = getContentPane(); // Set layout manager [Link](new BorderLayout()); // Initialize column headings final String[] colHeads = { "Name", "Phone", "Fax" }; // Initialize data final Object[][] data = { { "Gail", "4567", "8675" }, { "Ken", "7566", "5555" }, { "Viviane", "5634", "5887" }, { "Melanie", "7345", "9222" }, { "Anne", "1237", "3333" }, { "John", "5656", "3144" }, { "Matt", "5672", "2176" }, { "Claire", "6741", "4244" }, { "Erwin", "9023", "5159" }, { "Ellen", "1134", "5332" }, { "Jennifer", "5689", "1212" }, { "Ed", "9030", "1313" }, 10
{ "Helen", "6751", "1415" } }; // Create the table JTable table = new JTable(data, colHeads); // Add table to a scroll pane int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(table, v, h); // Add scroll pane to the content pane [Link](jsp, [Link]); } }
Result: The program for the Table using swing is successfully executed.
Output
11
EXP. NO/DATE TREE USING JAVA JTREE Demo SWING 4/10-01-2012 Aim: To write a program to display tree using java swing. Algorithm: Step 1: Create a JTree object. Step 2: Create a JScrollPane object. Step 3: Add the tree to the scroll pane. Step 4: Add the scroll pane to the content pane of the applet. Program: import [Link].*; import [Link].*; import [Link].*; import [Link].*; /* <applet code="JTreeDemo" width=400 height=200> </applet> */ public class JTreeDemo extends JApplet { JTree tree; JTextField jtf; public void init() { // Get content pane Container contentPane = getContentPane(); // Set layout manager [Link](new BorderLayout()); // Create top node of tree DefaultMutableTreeNode top = new DefaultMutableTreeNode("Options"); // Create subtree of "A" DefaultMutableTreeNode a = new DefaultMutableTreeNode("A"); [Link](a); DefaultMutableTreeNode a1 = new DefaultMutableTreeNode("A1"); [Link](a1); DefaultMutableTreeNode a2 = new DefaultMutableTreeNode("A2"); [Link](a2); // Create subtree of "B" DefaultMutableTreeNode b = new DefaultMutableTreeNode("B"); [Link](b); DefaultMutableTreeNode b1 = new DefaultMutableTreeNode("B1"); [Link](b1); 12
DefaultMutableTreeNode b2 = new DefaultMutableTreeNode("B2"); [Link](b2); DefaultMutableTreeNode b3 = new DefaultMutableTreeNode("B3"); [Link](b3); // Create tree tree = new JTree(top); // Add tree to a scroll pane int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED; int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED; JScrollPane jsp = new JScrollPane(tree, v, h); // Add scroll pane to the content pane [Link](jsp, [Link]); // Add text field to applet jtf = new JTextField("", 20); [Link](jtf, [Link]); // Anonymous inner class to handle mouse clicks [Link](new MouseAdapter() { public void mouseClicked(MouseEvent me) { doMouseClicked(me); } }); } void doMouseClicked(MouseEvent me) { TreePath tp = [Link]([Link](), [Link]()); if(tp != null) [Link]([Link]()); else [Link](""); } } Result: The program for the Tree using java swing is successfully executed. Output:
13
Algorithm: Step 1: Create a JComponent object. Step 2: Create a JButton object. Step 3: Add the ActionListener event to the Jbutton. Step 4: Add the button to the content pane of the applet.
Program: import [Link].*; import [Link].*; import [Link].*; /* <applet code="JButtonDemo" width=570 height=400> 14
</applet> */ public class JButtonDemo extends JApplet implements ActionListener { JTextField jtf; public void init() { setSize(300, 300); Container con = getContentPane(); [Link](new FlowLayout()); JButton jb1 = new JButton("Apple", new ImageIcon("[Link]")); [Link](this); JButton jb2 = new JButton("India", new ImageIcon("[Link]")); [Link](this); JButton jb3 = new JButton("Love", new ImageIcon("[Link]")); [Link](this); JButton jb4 = new JButton("VAIO", new ImageIcon("[Link]")); [Link](this); [Link](jb1); [Link](jb2); [Link](jb3); [Link](jb4); jtf = new JTextField(15); [Link](false); [Link](jtf); } @Override public void actionPerformed(ActionEvent e) { [Link]([Link]()); } } Result: The program for the JButton using java swing is successfully executed. Output 15
Algorithm: Step 1: Create a JComponent object. Step 2: Create a JTextField object.. Step 3: Add text field to the content pane of the applet Program: import [Link].*; 16
import [Link].*; /* <applet code="JTextFieldDemo" width=300 height=50> </applet> */ public class JTextFieldDemo extends JApplet { JTextField jtf; public void init() { // Get content pane Container contentPane = getContentPane(); [Link](new FlowLayout()); // Add text field to content pane jtf = new JTextField(15); [Link](jtf); } }
Result: The program for the TextField using java swing is successfully executed. Output:
17
Aim: To write a program to find the factorial of a given number and display its result.
Algorithm: Step 1: Create a JComponent object. Step 2: Create a JComboBox object.. Step 3: Add items to the ComboBox Step 4: Add ComboBox to the content pane of the applet Program: import [Link].*; import [Link].*; import [Link].*; /*<applet code="JComboBoxDemo" width=300 height=100> </applet>*/ public class JComboBoxDemo extends JApplet implements ItemListener { JLabel jl; ImageIcon france, germany, italy, japan; public void init() { // Get content pane Container contentPane = getContentPane(); [Link](new FlowLayout()); JComboBox jc = new JComboBox(); [Link]("Apple"); [Link]("India"); [Link]("Love"); [Link]("VAIO"); 18
[Link](this); [Link](jc); // Create label jl = new JLabel(new ImageIcon("[Link]")); [Link](jl); } public void itemStateChanged(ItemEvent ie) { String s = (String) [Link](); [Link](new ImageIcon(s + ".jpg")); } } Result: The program for the ComboBox using java swing is successfully executed Output:
19
Aim: To write a program to display Product information in client/server program in RMI. Algorithm: Step 1: - Start the program Step 2: - Write a Remote Interface Program Step 3: - Write a Server Program Step 4: - Write a Client Program Step 5: - Compile the server and client program Step 6: - Run RMIC and create the stub and Skelton files Step 7: - Run the RMI registry server Step 8: - Run the server program Step 9: - Run the Client program Step 10: - End the program
Program1: [Link] import [Link]; import [Link]; public interface AddServerInt extends Remote{ public double add(double d1,double d2) throws RemoteException ; } Program2: [Link] import [Link]; import [Link]; public class AddServerImpl extends UnicastRemoteObject implements AddServerInt { protected AddServerImpl() throws RemoteException { } public double add(double d1, double d2) throws RemoteException { return d1 + d2; } } Program3 : [Link] import [Link]; public class AddServer { 20
public static void main(String[] args) { try { AddServerImpl addServerImpl=new AddServerImpl(); [Link]("AddServer", addServerImpl); } catch (Exception e) { [Link]("Exception"+e); } } } Program4: [Link] import [Link]; public class AddClient { public static void main(String[] args) { try { String addserverurl="rmi://"+args[0]+"/AddServer"; AddServerInt addServerInt=(AddServerInt)[Link](addserverurl); [Link]("1st number is: " +args[1]); double d1= [Link](args[1]).doubleValue(); [Link]("2nd number is: " +args[2]); double d2= [Link](args[2]).doubleValue(); [Link]("The sum is : "+[Link](d1, d2)); } catch (Exception e) { [Link]("Exception : "+e); } } } Result: The program for the Client/Server using RMI is successfully executed Run: java AddClient localhost 35 67 Output: 1st number is: 35 2nd number is: 67 The sum is : 102.0
21
Aim: To write a program to display the content of server by using RMI with Applet. Algorithm: Step 1: - Start the program Step 2: - Write a Remote Interface Program Step 3: - Write a Server Program Step 4: - Write a Client Program and create HTML file Step 5: - Compile the server and client program Step 6: - Run RMIC and create the stub and Skelton files Step 7: - Run the RMI registry server Step 8: - Run the server program Step 9: - Run the Client program with appletviewer command. Step 10: - End the program Program for Server side Program1: [Link] import [Link]; import [Link]; import [Link]; public class Server implements RemoteInterface { public String getMessage() { return "Current Date At server : "+new [Link](); } public static void main(String args[]) { try { Registry registry =[Link](RemoteInterface.REGISTRY_PORT) RemoteInterface remoteReference = (RemoteInterface)[Link](new Server()); [Link](RemoteInterface.REGISTRY_NAME, remoteReference); } catch (Exception e) 22
{ throw new RuntimeException(e); } } } Program2 : [Link] import [Link]; import [Link]; public interface RemoteInterface extends Remote { String REGISTRY_NAME = "RMI_Example"; int REGISTRY_PORT = 3273; String getMessage() throws RemoteException; } Program for client side Program3: [Link] import [Link]; import [Link]; import [Link]; import [Link]; /*<applet code="ClientApplet" height="50" width="150"></applet>*/ public class ClientApplet extends JApplet { public void init() { try { Registry registry = [Link](getCodeBase().getHost(), RemoteInterface.REGISTRY_PORT); RemoteInterface remoteReference = (RemoteInterface) [Link](RemoteInterface.REGISTRY_NAME); getContentPane().add(new JLabel([Link]())); } catch (Exception e) { throw new RuntimeException(e); } } }
23
Html file to run the applet Program4: [Link] <html> <head> <title>Current Date' via an Applet using Java RMI</title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <h1>'Hello World' via an Applet using Java RMI</h1> <p> If everything works correctly there should be an applet running below that says 'Hello World': </p> <p> <!-- Compatible with all modern browsers --> <applet code="ClientApplet" height="50" width="150"></applet> </p> </body> </html>
Result: The program to display the content of server by using RMI with [Link] successfully executed Output:
24
Aim: To write a program to find the factorial of a given number and display its result.
Algorithm: Step 1: Write the html code in the JSP file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the java code for factorial inside the JSP directives in the body section. Step 4: Run the program and enter number in the text field. Step 5: Click Submit and display output in the web browser. Program: <html> <head> <title>Factorial Calculator</title> </head> <body> <form action="[Link]" method="POST"> <table> <tr> <th>Factorial Calculator</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Factorial : </b><% if ([Link]("number") == null || [Link]("number") == "") { [Link](""); } else { try { int fact = 1; int n = [Link]([Link]("number")); if (n == 0) { [Link]("Facorial of 0=1"); } else { for (int i = n; i > 0; i--) { fact *= i; 25
} [Link]("Factorial of " + n + "=" + fact); } } catch (Exception e) { [Link]("Error" + e); } } %> </td> </tr> <tr> <th><input name="calculate" type="submit" value="Calculate" size="10"></th> </tr> </table> </form> </body> </html> Result: The program for the Factorial using JSP is successfully executed. Input:
26
Output:
27
Aim: To write a program to find whether a number is palindrome or not. Algorithm: Step 1: Write the html code in the JSP file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the java code for factorial inside the JSP directives in the body section. Step 4: Run the program and enter number in the text field. Step 5: Click Submit and display output in the web browser. Program: <html> <head> <title>Palindrome Number Checker</title> </head> <body> <form action="[Link]" method="POST"> <table> <tr> <th>Palindrome Number Checker</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Result : </b><% if ([Link]("number") == null || [Link]("number") == "") { [Link](""); } else { try { int num = [Link]([Link]("number")); int rev = 0; for (int i = num; i > 0;) { rev *= 10; rev += (i % 10); i /= 10; } if (num == rev) { 28
[Link](num + " is a Palindrome Number"); } else { [Link](num + " is Not a Palindrome Number"); } } catch (Exception e) { [Link]("Error : " + e); } } %> </td> </tr> <tr> <th><input name="check" type="submit" value="Check"></th> </tr> </table> </form> </body> </html> Result: The program for the Palindrome number using JSP is successfully executed. Input:
29
Output:
Aim: To write a program to find whether a number is prime or not. Algorithm: Step 1: Write the html code in the JSP file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the java code for finding prime number inside the JSP directives in the body section. Step 4: Run the program and display output in the web browser.
30
<html> <head> <title>Prime Number Checker</title> </head> <body> <form action="[Link]" method="POST"> <table> <tr> <th>Prime Number Checker</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Result : </b><% if ([Link]("number") == null || [Link]("number") == "") { [Link](""); } else { try { int num = [Link]([Link]("number")); if (isPrime(num)) { [Link](num + " is a Prime Number"); } else { [Link](num + " is Not a Prime Number"); } } catch (Exception e) { [Link]("Error : " + e); } } %> <%! boolean isPrime(int n) { for (int i = 2; i < n; i++) { if (n % i == 0) { return false; } } return true; } %> </td> </tr> <tr> 31
<th><input name="check" type="submit" value="Check"></th> </tr> </table> </form> </body> </html><html> <head> <title>Prime Number Checker</title> </head> <body> <form action="[Link]" method="POST"> <table> <tr> <th>Prime Number Checker</th> </tr> <tr> <td>Enter the number : <input type="text" name="number" id="number"> </td> </tr> <tr> <td> <b>Result : </b><% if ([Link]("number") == null || [Link]("number") == "") { [Link](""); } else { try { int num = [Link]([Link]("number")); if (isPrime(num)) { [Link](num + " is a Prime Number"); } else { [Link](num + " is Not a Prime Number"); } } catch (Exception e) { [Link]("Error : " + e); } } %> <%! boolean isPrime(int n) { for (int i = 2; i < n; i++) { if (n % i == 0) { return false; } 32
} return true; } %> </td> </tr> <tr> <th><input name="check" type="submit" value="Check"></th> </tr> </table> </form> </body> </html>
Result: The program for the prime number using JSP is successfully executed. Input:
Output: 33
Aim: To write a program to convert temperature from Celsius to Fahrenheit. Algorithm: Step 1: Write the html code in the JSP file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the java code for temperature conversion inside the JSP directives in the body section. Step 4: Run the program and display output in the web browser. Program: <html> <head> <title>Temperature Converter</title> </head> <body> <form action="[Link]" method="POST"> <table> <tr> <th>Temperature Converter</th> 34
</tr> <tr> <td>Enter Temperature in Celsius : <input type="text" name="temp" id="temp"> </td> </tr> <tr> <td> <b>Temperature in Fahrenheit : </b> <% if ([Link]("temp") == null || [Link]("temp") == "") { [Link](""); } else { try { double tempc = [Link]([Link]("temp")); double tempf =((9*tempc)/5)+32; [Link](tempf); } catch (Exception e) { [Link]("Error" + e); } } %> <sup>°</sup>F </td> </tr> <tr> <th><input name="Convert" type="submit" value="Convert"></th> </tr> </table> </form> </body> </html> Result: The program for the temperature conversion using JSP is successfully executed.
35
Input:
Output:
36
Aim: To write a program to print simple array using JSP. Algorithm: Step 1: Write the html code in the JSP file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the java code for simple array inside the JSP directives in the body section. Step 4: Run the program and display output in the web browser. Program: <html> <head> <title>Simple Array</title> </head> <body> <h3>Elements of Array</h3>> <ol> <% 37
String[] names = {"Ashish", "Ankur", "Nitesh", "Pandey", "Prabhat", "Nitin", "Sumit"}; for (String s : names) { [Link]("<li>" + s + "</li>"); } %> </ol> </body> </html> Result: The program for printing the array elements using JSP is successfully executed. Output:
Algorithm: Step 1: Write the html code in the JSP file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the java code for week days using array inside the JSP directives in the body section. Step 4: Run the program and display output in the web browser. Program: <html> <head> <title>Days in Week</title> </head> <body> <h3>Days of Week</h3> <ul> <% String[] days = {"Monday", "Tuesday", "Wednesday", "Thirsday", "Friday", "Saturday", "Sunday"}; for (String s : days) { [Link]("<li>" + s + "</li>"); } %> </ul> </body> </html> Result: The program for the Factorial using JSP is successfully executed. Output:
39
Aim: To write a program to display personal information form using java bean. Algorithm: Step 1: Create new java application using Netbeans, Step 2: Extends JFrame in the program. Step 3: Add JLabels, JButtons,JTextFields into the JFrame to enter information. Step 4: Run the program and display output in the appletviewer. Program: import [Link]; /** 40
* * @author Nitesh */ public class PerInfo extends [Link] { /** * Creates new form PerInfo */ public PerInfo() { initComponents(); initMyComponents(); } private void initMyComponents() { //Adding Data to Date of Birth Combo Box for (int i = 1; i <= 31; i++) { if (i < 10) { [Link]("0" + i); } else { [Link]("" + i); } } [Link]("Jan"); [Link]("Feb"); [Link]("Mar"); [Link]("Apr"); [Link]("May"); [Link]("Jun"); [Link]("Jul"); [Link]("Aug"); [Link]("Sep"); [Link]("Oct"); [Link]("Nov"); [Link]("Dec"); for (int i = 2014; i >= 1920; i--) { [Link]("" + i); } setLocationRelativeTo(null); } private boolean validateFormData() { if (([Link]()).equals("")) { [Link](this, "Enter name first!"); [Link](); return false; } 41
if (([Link]()).equals("")) { [Link](this, "Enter Father Name first!"); [Link](); return false; } // Date Of Birth if (((String) ([Link]())).equalsIgnoreCase("Date")) { [Link](this, "Select Date of Birth!"); [Link](); return false; } if (((String) ([Link]())).equalsIgnoreCase("Month")) { [Link](this, "Select Month of Birth!"); [Link](); return false; } if (((String) ([Link]())).equalsIgnoreCase("Month")) { [Link](this, "Select Year of Birth!"); [Link](); return false; } //////////////////////////////////////////////////////////////////////// if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Enter Mobile Number First!"); [Link](); return false; } if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Enter Email Address First!"); [Link](); return false; } if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Please Enter the Address!"); [Link](); return false; } return true; } /** * 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() { 42
RBG = new [Link](); Label = new [Link](); nameL = new [Link](); submitB = new [Link](); clearB = new [Link](); fnameL = new [Link](); sexL = new [Link](); dobL = new [Link](); occL = new [Link](); mobileL = new [Link](); emailL = new [Link](); addressL = new [Link](); nameT = new [Link](); fnameT = new [Link](); occT = new [Link](); mobileT = new [Link](); emailT = new [Link](); jScrollPane1 = new [Link](); addressT = new [Link](); sexMRadio = new [Link](); sexFRadio = new [Link](); dobddcmb = new [Link](); dobmmcmb = new [Link](); dobyycmb = new [Link](); exitB = new [Link](); [Link](sexMRadio); [Link](sexFRadio); setDefaultCloseOperation([Link].EXIT_ON_CLOSE); setTitle("Personal Information Management"); [Link](new [Link]("Times New Roman", 1, 24)); // NOI18N [Link](new [Link](0, 153, 153)); [Link]("Personal Infromation"); [Link]("Name"); [Link]("Submit"); [Link](new [Link]() { public void actionPerformed([Link] evt) { submitBActionPerformed(evt); } }); [Link]("Clear"); [Link](new [Link]() { 43
public void actionPerformed([Link] evt) { clearBActionPerformed(evt); } }); [Link]("Father Name"); [Link]("Sex"); [Link]("DOB"); [Link]("Occupation"); [Link]("Mobile"); [Link]("Email:"); [Link]("Address"); [Link](10); [Link](20); [Link](5); [Link](addressT); [Link](true); [Link]("Male"); [Link]("Female"); [Link](new [Link](new String[] { "Date" })); [Link](new [Link](new String[] { "Month" })); [Link](new [Link](new String[] { "Year" })); [Link]("Exit"); [Link](new [Link]() { public void actionPerformed([Link] evt) { exitBActionPerformed(evt); } }); [Link] layout = new [Link](getContentPane()); 44
getContentPane().setLayout(layout); [Link]( [Link]([Link]) .addGroup([Link]() .addGroup([Link]([Link]) .addGroup([Link]() .addGap(70, 70, 70) .addGroup([Link]([Link]) .addComponent(nameL) .addComponent(fnameL) .addComponent(sexL) .addComponent(dobL) .addComponent(occL) .addComponent(mobileL) .addComponent(emailL) .addComponent(addressL)) .addGap(42, 42, 42) .addGroup([Link]([Link], false) .addComponent(jScrollPane1) .addGroup([Link]([Link], false) .addComponent(nameT, [Link].DEFAULT_SIZE, 114, Short.MAX_VALUE) .addComponent(fnameT) .addComponent(occT) .addComponent(mobileT, [Link].PREFERRED_SIZE, 94, [Link].PREFERRED_SIZE)) .addGroup([Link]() .addComponent(sexMRadio) .addPreferredGap([Link]) .addComponent(sexFRadio)) .addGroup([Link]() .addComponent(dobddcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addPreferredGap([Link]) .addComponent(dobmmcmb, [Link].PREFERRED_SIZE, 45
[Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addPreferredGap([Link]) .addComponent(dobyycmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addComponent(emailT))) .addGroup([Link]() .addGap(90, 90, 90) .addComponent(Label)) .addGroup([Link]() .addGap(105, 105, 105) .addComponent(submitB) .addGap(18, 18, 18) .addComponent(clearB) .addPreferredGap([Link]) .addComponent(exitB))) .addContainerGap(82, Short.MAX_VALUE)) ); [Link]( [Link]([Link]) .addGroup([Link]() .addGap(19, 19, 19) .addComponent(Label) .addGap(18, 18, 18) .addGroup([Link]([Link] ) .addComponent(nameL) .addComponent(nameT, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link] ) .addComponent(fnameL) .addComponent(fnameT, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link] ) 46
.addComponent(sexL) .addComponent(sexMRadio) .addComponent(sexFRadio)) .addPreferredGap([Link]) .addGroup([Link]([Link] ) .addComponent(dobL) .addComponent(dobddcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(dobmmcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(dobyycmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link]) .addComponent(occL) .addComponent(occT, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link]) .addComponent(mobileL) .addComponent(mobileT, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link] ) .addComponent(emailL) .addComponent(emailT, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link]) .addComponent(addressL) 47
.addComponent(jScrollPane1, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(10, 10, 10) .addGroup([Link]([Link] ) .addComponent(clearB) .addComponent(exitB) .addComponent(submitB)) .addContainerGap(55, Short.MAX_VALUE)) ); pack(); }// </editor-fold> private void exitBActionPerformed([Link] evt) { dispose(); } private void clearBActionPerformed([Link] evt) { [Link](""); [Link](""); [Link](true); [Link]("Date"); [Link]("Month"); [Link]("Year"); [Link](""); [Link](""); [Link](""); [Link](""); [Link](); } private void submitBActionPerformed([Link] evt) { if(validateFormData()){ [Link](this, "Record Added Successfully!"); clearBActionPerformed(evt); } //Use data to save at any particular place } /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ 48
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see [Link] */ try { for ([Link] info : [Link]()) { if ("Nimbus".equals([Link]())) { [Link]([Link]()); break; } } } catch (ClassNotFoundException ex) { [Link]([Link]()).log([Link]. SEVERE, null, ex); } catch (InstantiationException ex) { [Link]([Link]()).log([Link]. SEVERE, null, ex); } catch (IllegalAccessException ex) { [Link]([Link]()).log([Link]. SEVERE, null, ex); } catch ([Link] ex) { [Link]([Link]()).log([Link]. SEVERE, null, ex); } //</editor-fold> /* Create and display the form */ [Link](new Runnable() { public void run() { new PerInfo().setVisible(true); } }); } // Variables declaration - do not modify private [Link] Label; private [Link] RBG; private [Link] addressL; private [Link] addressT; private [Link] clearB; private [Link] dobL; 49
private [Link] dobddcmb; private [Link] dobmmcmb; private [Link] dobyycmb; private [Link] emailL; private [Link] emailT; private [Link] exitB; private [Link] fnameL; private [Link] fnameT; private [Link] jScrollPane1; private [Link] mobileL; private [Link] mobileT; private [Link] nameL; private [Link] nameT; private [Link] occL; private [Link] occT; private [Link] sexFRadio; private [Link] sexL; private [Link] sexMRadio; private [Link] submitB; // End of variables declaration }
Result: The program to display personal information form using java bean is successfully executed. Output:
50
51
52
Aim: To write a program to design Enrollment form using java bean. Algorithm: Step 1: Create new java application using Netbeans, Step 2: Extends JFrame in the program. Step 3: Add JLabels, JButtons,JTextFields into the JFrame to enter information. Step 4: Run the program and display output in the appletviewer. Program: package bean; import [Link].*; public class Registration extends [Link] { public Registration() { initComponents(); initMyComponents(); } private boolean validateFormData() { if ((treg_no.getText()).equals("")) { [Link](this, "Enter Registration no. first!"); treg_no.requestFocus(); return false; } if (((String) ([Link]())).equalsIgnoreCase("Course")) { [Link](this, "Select Course first!"); [Link](); 53
return false; } if (((String) ([Link]())).equalsIgnoreCase("Semester")) { [Link](this, "Select semester first!"); [Link](); return false; } // if (((String) ([Link]())).equalsIgnoreCase("Date")) { [Link](this, "Select Date of Admission!"); [Link](); return false; } if (((String) ([Link]())).equalsIgnoreCase("Month")) { [Link](this, "Select Month of Admission!"); [Link](); return false; } if (((String) ([Link]())).equalsIgnoreCase("Month")) { [Link](this, "Select Year of Admission!"); [Link](); return false; } //////////////////////////////////////////////////////////////////////// if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Enter First Name!"); [Link](); return false; } if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Enter Last Name!"); [Link](); return false; } if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Enter Father Name!"); [Link](); return false; } // Date Of Birth 54
if (((String) ([Link]())).equalsIgnoreCase("Date")) { [Link](this, "Select Date of Birth!"); [Link](); return false; } if (((String) ([Link]())).equalsIgnoreCase("Month")) { [Link](this, "Select Month of Birth!"); [Link](); return false; } if (((String) ([Link]())).equalsIgnoreCase("Month")) { [Link](this, "Select Year of Birth!"); [Link](); return false; } //////////////////////////////////////////////////////////////////////// if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Enter Mobile Number First!"); [Link](); return false; } if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Enter Email Address First!"); [Link](); return false; } if (([Link]()).equalsIgnoreCase("")) { [Link](this, "Please Enter the Address!"); [Link](); return false; } return true; } private void initMyComponents() { setExtendedState([Link]() | this.MAXIMIZED_BOTH); //Adding Data to Date of Birth Combo Box for (int i = 1; i <= 30; i++) { if (i < 10) { [Link]("0" + i); } else { [Link]("" + i); 55
} } [Link]("Jan"); [Link]("Feb"); [Link]("Mar"); [Link]("Apr"); [Link]("May"); [Link]("Jun"); [Link]("Jul"); [Link]("Aug"); [Link]("Sep"); [Link]("Oct"); [Link]("Nov"); [Link]("Dec"); for (int i = 2014; i >= 1950; i--) { [Link]("" + i); } //Adding Data to Date of Birth Combo Box for (int i = 1; i <= 30; i++) { if (i < 10) { [Link]("0" + i); } else { [Link]("" + i); } } [Link]("Jan"); [Link]("Feb"); [Link]("Mar"); [Link]("Apr"); [Link]("May"); [Link]("Jun"); [Link]("Jul"); [Link]("Aug"); [Link]("Sep"); [Link]("Oct"); [Link]("Nov"); [Link]("Dec"); for (int i = 2014; i >= 1950; i--) { [Link]("" + i); } treg_no.requestFocus(); } 56
/** * 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() { [Link] sexBG = new [Link](); jPanel1 = new [Link](); jLabel13 = new [Link](); jPanel2 = new [Link](); jPanel3 = new [Link](); jLabel1 = new [Link](); treg_no = new [Link](); jLabel2 = new [Link](); tfirstname = new [Link](); jLabel3 = new [Link](); tlastname = new [Link](); jLabel4 = new [Link](); tfathername = new [Link](); jLabel5 = new [Link](); jLabel6 = new [Link](); tmobile = new [Link](); jLabel7 = new [Link](); temail = new [Link](); jLabel8 = new [Link](); jScrollPane1 = new [Link](); taddress = new [Link](); addB = new [Link](); clearB = new [Link](); cancelB = new [Link](); coursecmb = new [Link](); jLabel9 = new [Link](); dobpan = new [Link](); dobddcmb = new [Link](); dobmmcmb = new [Link](); dobyearcmb = new [Link](); jLabel10 = new [Link](); semestercmb = new [Link](); 57
jLabel11 = new [Link](); jLabel12 = new [Link](); doapan = new [Link](); doaddcmb = new [Link](); doammcmb = new [Link](); doayearcmb = new [Link](); exitB = new [Link](); femalerdb = new [Link](); malerdb = new [Link](); jPanel4 = new [Link](); setDefaultCloseOperation([Link].DISPOSE_ON_CLOSE); setTitle("Student Form"); [Link](new [Link](605, 205)); [Link](new [Link]() { public void ancestorMoved([Link] evt) { jPanel1AncestorMoved(evt); } public void ancestorAdded([Link] evt) { jPanel1AncestorAdded(evt); } public void ancestorRemoved([Link] evt) { } }); [Link](new [Link](getClass().getResource("/bean/[Link]"))); // NOI18N [Link](jLabel13); getContentPane().add(jPanel1, [Link].PAGE_START); [Link](new [Link](25, 10)); [Link] jPanel2Layout = new [Link](jPanel2); [Link](jPanel2Layout); [Link]( [Link]([Link]) .addGap(0, 25, Short.MAX_VALUE) ); [Link]( 58
[Link]([Link]([Link] [Link](new [Link](204, 0, 204), new [Link](0, 255, 153)), "Student Registration")); [Link]("Student Registration Form"); [Link]("Student Registration"); // NOI18N [Link](new [Link](1000, 400)); [Link]([Link]); [Link]("Registration No."); treg_no.setHorizontalAlignment([Link]); treg_no.setToolTipText("Enter Registration Number(10-Digits Only)"); [Link]([Link]); [Link]("First Name"); [Link]([Link]); [Link]("Enter First Name"); [Link]([Link]); [Link]("Last Name"); [Link]([Link]); [Link]("Enter Last Name"); [Link]([Link]); [Link]("Father Name"); [Link]([Link]); [Link]("Enter Father Name"); [Link]([Link]); [Link]("Course"); 59
[Link]([Link]); [Link]("Mobile"); [Link]([Link]); [Link]("10-Digits Only"); [Link](new [Link]() { public void actionPerformed([Link] evt) { tmobileActionPerformed(evt); } }); [Link]([Link]); [Link]("Email"); [Link]([Link]); [Link]("Must Contain Atleast '@'"); [Link]([Link]); [Link]("Address"); [Link](20); [Link](5); [Link]("Enter Current Address"); [Link](taddress); [Link]("ADD"); [Link]("badd"); // NOI18N [Link](new [Link]() { public void actionPerformed([Link] evt) { addBActionPerformed(evt); } }); [Link]("Clear"); [Link](new [Link]() { public void actionPerformed([Link] evt) { clearBActionPerformed(evt); } }); [Link]("Cancel"); [Link](new [Link]() { 60
public void actionPerformed([Link] evt) { cancelBActionPerformed(evt); } }); [Link](new [Link](new String[] { "Course", "BA", "BEd.", "BBA", "BCA", "BPT", "[Link].", "[Link]", "[Link].", "MA", "MBA", "MCA", "MPT", "[Link].", "[Link]", "[Link]." })); [Link]("Select Course"); [Link]("Date Of Birth"); [Link]([Link]()); [Link](new [Link](new String[] { "Date" })); [Link]("Select Date of Birth"); [Link](new [Link]() { public void actionPerformed([Link] evt) { dobddcmbActionPerformed(evt); } }); [Link](new [Link](new String[] { "Month" })); [Link]("Slect Month of Birth"); [Link](new [Link](new String[] { "Year" })); [Link]("Select Year of Birth"); [Link](new [Link]() { public void actionPerformed([Link] evt) { dobyearcmbActionPerformed(evt); } }); [Link] dobpanLayout = new [Link](dobpan); [Link](dobpanLayout); [Link]( [Link]([Link]) .addGroup([Link]() 61
.addComponent(dobddcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addPreferredGap([Link]) .addComponent(dobmmcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(dobyearcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addContainerGap([Link].DEFAULT_SIZE, Short.MAX_VALUE)) ); [Link]( [Link]([Link]) .addGroup([Link], [Link]() .addContainerGap([Link].DEFAULT_SIZE, Short.MAX_VALUE) .addGroup([Link]([Link] SELINE) .addComponent(dobddcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(dobmmcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(dobyearcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(37, 37, 37)) ); [Link]("Semester");
62
[Link](new [Link](new String[] { "Semester", "I", "II", "III", "IV", "V", "VI", "VII", "IIX" })); [Link]("Select semester"); [Link]("Sex"); [Link]("Date Of Admission"); [Link]([Link]()); [Link](new [Link](new String[] { "Date" })); [Link]("Select Date of Admission"); [Link](new [Link]() { public void actionPerformed([Link] evt) { doaddcmbActionPerformed(evt); } }); [Link](new [Link](new String[] { "Month" })); [Link]("Month of Admission"); [Link](new [Link](new String[] { "Year" })); [Link]("Year of Admission"); [Link](new [Link]() { public void actionPerformed([Link] evt) { doayearcmbActionPerformed(evt); } }); [Link] doapanLayout = new [Link](doapan); [Link](doapanLayout); [Link]( [Link]([Link]) .addGroup([Link]() .addComponent(doaddcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) 63
.addPreferredGap([Link]) .addComponent(doammcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addGap(18, 18, 18) .addComponent(doayearcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addContainerGap([Link].DEFAULT_SIZE, Short.MAX_VALUE)) ); [Link]( [Link]([Link]) .addGroup([Link], [Link]() .addContainerGap([Link].DEFAULT_SIZE, Short.MAX_VALUE) .addGroup([Link]([Link] SELINE) .addComponent(doaddcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(doammcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(doayearcmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addContainerGap()) ); [Link]("Exit"); [Link](new [Link]() { public void actionPerformed([Link] evt) { exitBActionPerformed(evt); } }); 64
[Link](femalerdb); [Link]("Female"); [Link](new [Link]() { public void actionPerformed([Link] evt) { femalerdbActionPerformed(evt); } }); [Link](malerdb); [Link](true); [Link]("Male"); [Link](new [Link]() { public void actionPerformed([Link] evt) { malerdbActionPerformed(evt); } }); [Link] jPanel3Layout = new [Link](jPanel3); [Link](jPanel3Layout); [Link]( [Link]([Link]) .addGroup([Link]() .addGroup([Link]([Link] ADING) .addGroup([Link]() .addGap(31, 31, 31) .addGroup([Link]([Link] ADING) .addComponent(jLabel1) .addComponent(jLabel10) .addComponent(jLabel5) .addComponent(jLabel12)) .addGap(45, 45, 45) .addGroup([Link]([Link] ADING)
65
.addComponent(treg_no, [Link].PREFERRED_SIZE, 103, [Link].PREFERRED_SIZE) .addComponent(coursecmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(semestercmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(doapan, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(52, 52, 52) .addGroup([Link]([Link] ADING) .addGroup([Link]() .addComponent(jLabel3) .addGap(46, 46, 46) .addComponent(tlastname, [Link].PREFERRED_SIZE, 103, [Link].PREFERRED_SIZE)) .addGroup([Link]() .addGroup([Link]([Link] ADING) .addGroup([Link]([Link] AILING) .addComponent(jLabel9) .addComponent(jLabel4)) .addComponent(jLabel11) .addComponent(jLabel6) .addComponent(jLabel7) .addComponent(jLabel8)) .addGap(34, 34, 34) .addGroup([Link]([Link] ADING) 66
.addComponent(tfathername, [Link].PREFERRED_SIZE, 103, [Link].PREFERRED_SIZE) .addComponent(jScrollPane1, [Link].PREFERRED_SIZE, 283, [Link].PREFERRED_SIZE) .addComponent(temail, [Link].PREFERRED_SIZE, 166, [Link].PREFERRED_SIZE) .addComponent(tmobile, [Link].PREFERRED_SIZE, 103, [Link].PREFERRED_SIZE) .addGroup([Link]() .addComponent(malerdb) .addGap(18, 18, 18) .addComponent(femalerdb)) .addComponent(dobpan, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE))) .addGroup([Link]() .addComponent(jLabel2) .addGap(45, 45, 45) .addComponent(tfirstname, [Link].PREFERRED_SIZE, 103, [Link].PREFERRED_SIZE)))) .addGroup([Link]() .addGap(284, 284, 284) .addComponent(addB, [Link].PREFERRED_SIZE, 70, [Link].PREFERRED_SIZE) .addGap(33, 33, 33) .addComponent(clearB, [Link].PREFERRED_SIZE, 67, [Link].PREFERRED_SIZE) .addGap(36, 36, 36) .addComponent(cancelB) .addGap(53, 53, 53) .addComponent(exitB, [Link].PREFERRED_SIZE, 64, [Link].PREFERRED_SIZE))) .addContainerGap(204, Short.MAX_VALUE)) ); [Link]( 67
[Link]([Link]) .addGroup([Link]() .addContainerGap() .addGroup([Link]([Link] ADING) .addGroup([Link]() .addGroup([Link]([Link] ADING) .addGroup([Link]() .addGap(3, 3, 3) .addComponent(jLabel2)) .addComponent(tfirstname, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(11, 11, 11) .addGroup([Link]([Link] ADING) .addGroup([Link]() .addGap(3, 3, 3) .addComponent(jLabel3)) .addComponent(tlastname, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(11, 11, 11) .addGroup([Link]([Link] SELINE) .addComponent(tfathername, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(jLabel4, [Link].PREFERRED_SIZE, 13, [Link].PREFERRED_SIZE))
68
.addGroup([Link]([Link] ADING) .addGroup([Link]() .addGap(22, 22, 22) .addComponent(jLabel9)) .addGroup([Link]() .addPreferredGap([Link]) .addGroup([Link]([Link] ADING) .addComponent(doapan, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE) .addComponent(dobpan, [Link].PREFERRED_SIZE, 38, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link] SELINE) .addComponent(malerdb) .addComponent(femalerdb) .addComponent(jLabel11)))) .addGap(25, 25, 25) .addGroup([Link]([Link] SELINE) .addComponent(jLabel6) .addComponent(tmobile, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link] SELINE) .addComponent(jLabel7) 69
.addComponent(temail, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addPreferredGap([Link]) .addGroup([Link]([Link] ADING) .addComponent(jLabel8) .addComponent(jScrollPane1, [Link].PREFERRED_SIZE, 67, [Link].PREFERRED_SIZE))) .addGroup([Link]() .addGroup([Link]([Link] ADING) .addGroup([Link]() .addGap(3, 3, 3) .addComponent(jLabel1)) .addComponent(treg_no, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(18, 18, 18) .addGroup([Link]([Link] SELINE) .addComponent(jLabel5) .addComponent(coursecmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(14, 14, 14) .addGroup([Link]([Link] ADING) .addComponent(jLabel10) .addComponent(semestercmb, [Link].PREFERRED_SIZE, [Link].DEFAULT_SIZE, [Link].PREFERRED_SIZE)) .addGap(18, 18, 18) 70
.addComponent(jLabel12))) .addPreferredGap([Link], 82, Short.MAX_VALUE) .addGroup([Link]([Link] SELINE) .addComponent(addB) .addComponent(clearB) .addComponent(cancelB) .addComponent(exitB)) .addGap(57, 57, 57)) ); [Link]().setAccessibleName(""); getContentPane().add(jPanel3, [Link]); [Link]().setAccessibleName(""); [Link](new [Link](605, 25)); [Link] jPanel4Layout = new [Link](jPanel4); [Link](jPanel4Layout); [Link]( [Link]([Link]) .addGap(0, 1025, Short.MAX_VALUE) ); [Link]( [Link]([Link]) .addGap(0, 25, Short.MAX_VALUE) ); getContentPane().add(jPanel4, [Link].PAGE_END); pack(); }// </editor-fold> private void jPanel1AncestorAdded([Link] evt) { // TODO add your handling code here: } 71
private void jPanel1AncestorMoved([Link] evt) { // TODO add your handling code here: } private void clearBActionPerformed([Link] evt) { treg_no.setText(""); [Link]("Course"); [Link]("Semester"); [Link]("Date"); [Link]("Month"); [Link]("Year"); [Link](""); [Link](""); [Link](""); [Link]("Date"); [Link]("Month"); [Link]("Year"); [Link](true); [Link](""); [Link](""); [Link](""); treg_no.requestFocus(); } private void addBActionPerformed([Link] evt) { //Validating Form Data if (validateFormData()) { [Link](this, "Record Added successfully"); } } private void tmobileActionPerformed([Link] evt) { } private void dobddcmbActionPerformed([Link] evt) { } private void femalerdbActionPerformed([Link] evt) { } private void malerdbActionPerformed([Link] evt) { } 72
private void dobyearcmbActionPerformed([Link] evt) { // TODO add your handling code here: } private void doaddcmbActionPerformed([Link] evt) { // TODO add your handling code here: } private void doayearcmbActionPerformed([Link] evt) { // TODO add your handling code here: } private void cancelBActionPerformed([Link] evt) { [Link](); } private void exitBActionPerformed([Link] evt) { [Link](); } /** * @param args the command line arguments */ public static void main(String args[]) { /* * Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* * If Nimbus (introduced in Java SE 6) is not available, stay with the * default look and feel. For details see * [Link] */ try { for ([Link] info : [Link]()) { if ("Nimbus".equals([Link]())) { [Link]([Link]()); break;
73
} } } catch (ClassNotFoundException ex) { [Link]([Link]()).log([Link].L [Link], null, ex); } catch (InstantiationException ex) { [Link]([Link]()).log([Link].L [Link], null, ex); } catch (IllegalAccessException ex) { [Link]([Link]()).log([Link].L [Link], null, ex); } catch ([Link] ex) { [Link]([Link]()).log([Link].L [Link], null, ex); } //</editor-fold> /* * Create and display the form */ [Link](new Runnable() { @Override public void run() { new Registration().setVisible(true); } }); } // Variables declaration - do not modify private [Link] addB; private [Link] cancelB; private [Link] clearB; private [Link] coursecmb; private [Link] doaddcmb; private [Link] doammcmb; private [Link] doapan; private [Link] doayearcmb; private [Link] dobddcmb; private [Link] dobmmcmb; 74
private [Link] dobpan; private [Link] dobyearcmb; private [Link] exitB; private [Link] femalerdb; private [Link] jLabel1; private [Link] jLabel10; private [Link] jLabel11; private [Link] jLabel12; private [Link] jLabel13; private [Link] jLabel2; private [Link] jLabel3; private [Link] jLabel4; private [Link] jLabel5; private [Link] jLabel6; private [Link] jLabel7; private [Link] jLabel8; private [Link] jLabel9; private [Link] jPanel1; private [Link] jPanel2; private [Link] jPanel3; private [Link] jPanel4; private [Link] jScrollPane1; private [Link] malerdb; private [Link] semestercmb; private [Link] taddress; private [Link] temail; private [Link] tfathername; private [Link] tfirstname; private [Link] tlastname; private [Link] tmobile; private [Link] treg_no; // End of variables declaration } Result: The program to design Enrollment form using java bean. is successfully executed. Output:
75
Aim: To write a program to display calendar using java bean. Algorithm: Step 1: Create new java application using Netbeans, Step 2: Create Date Chooser object. Step 3: Add JLabels, JTable, Calender using current date of the system. Step 4: Run the program and display output. Program: import [Link].*; import [Link].*; public class DateChooser { public final static String[] months = { "January" , "February" , "March", "April" , "May" , "June", "July" , "August" , "September", "October" , "November" , "December" }; 76
/** days in each month */ public final static int dom[] = { 31, 28, 31, /* jan, feb, mar */ 30, 31, 30, /* apr, may, jun */ 31, 31, 30, /* jul, aug, sep */ 31, 30, 31 /* oct, nov, dec */ }; private void printMonth(int mm, int yy) { int leadSpaces = 0; [Link](); [Link](" " + months[mm] + " " + yy); if (mm < 0 || mm > 11) { throw new IllegalArgumentException( "Month " + mm + " bad, must be 0-11"); } GregorianCalendar cal = new GregorianCalendar(yy, mm, 1); [Link]("Su Mo Tu We Th Fr Sa"); // can change to "M T W T F S S" leadSpaces = [Link](Calendar.DAY_OF_WEEK)-1; // adjust for "M T W T F S S" if desired int daysInMonth = dom[mm]; if ([Link]([Link]([Link])) && mm == 1) daysInMonth++; for (int i = 0; i < leadSpaces; i++) { [Link](" "); } for (int i = 1; i <= daysInMonth; i++) { if (i<=9) [Link](" "); [Link](i); if ((leadSpaces + i) % 7 == 0) { // Wrap if EOL [Link](); } else { [Link](" "); } } [Link](); } public static void main(String[] args) { int month, year; DateChooser mv = new DateChooser(); Calendar today = [Link](); [Link]( [Link]( [Link]), [Link]( [Link])); } }
Result: The program to display calendar using java bean has been successfully executed. 77
Output:
Aim: To write a program to display Table using Java Bean. Algorithm: Step 1: Create new java application using Netbeans, Step 2: Extends JFrame in the program. Step 3: Add JLabels, JTable into the JFrame to enter information. Step 4: Run the program and display output in the appletviewer. Program: public class TableDemo extends [Link] { public TableDemo() { 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() { 78
jScrollPane1 = new [Link](); jTable1 = new [Link](); jLabel1 = new [Link](); setDefaultCloseOperation([Link].EXIT_ON_CLOSE); setTitle("Table using Bean"); [Link](new [Link]( new Object [][] { {null, null, null, null}, {null, null, null, null}, {null, null, null, null}, {null, null, null, null} }, new String [] { "Reg no.", "Name", "Course", "Year of Admission" } )); [Link](jTable1); [Link](new [Link]("Times New Roman", 1, 24)); // NOI18N [Link](new [Link](51, 0, 255)); [Link]("Table using Bean"); [Link] layout = new [Link](getContentPane()); getContentPane().setLayout(layout); [Link]( [Link]([Link]) .addGroup([Link]() .addContainerGap() .addComponent(jScrollPane1, [Link].DEFAULT_SIZE, 450, Short.MAX_VALUE) .addContainerGap()) .addGroup([Link]() .addGap(134, 134, 134) .addComponent(jLabel1) .addContainerGap([Link].DEFAULT_SIZE, Short.MAX_VALUE)) ); [Link]( 79
[Link]([Link]) .addGroup([Link], [Link]() .addGap(28, 28, 28) .addComponent(jLabel1) .addPreferredGap([Link], 31, Short.MAX_VALUE) .addComponent(jScrollPane1, [Link].PREFERRED_SIZE, 202, [Link].PREFERRED_SIZE) .addContainerGap()) ); pack(); }// </editor-fold> /** * @param args the command line arguments */ public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see [Link] */ try { for ([Link] info : [Link]()) { if ("Nimbus".equals([Link]())) { [Link]([Link]()); break; } } } catch (ClassNotFoundException ex) { [Link]([Link]()).log([Link] [Link], null, ex); } catch (InstantiationException ex) {
80
[Link]([Link]()).log([Link] [Link], null, ex); } catch (IllegalAccessException ex) { [Link]([Link]()).log([Link] [Link], null, ex); } catch ([Link] ex) { [Link]([Link]()).log([Link] [Link], null, ex); } //</editor-fold> /* Create and display the form */ [Link](new Runnable() { public void run() { new TableDemo().setVisible(true); } }); } // Variables declaration - do not modify private [Link] jLabel1; private [Link] jScrollPane1; private [Link] jTable1; // End of variables declaration } Result: The program to display Table using Java [Link] successfully executed. Output:
81
Aim: To write a program to display date and time using Servlet. Algorithm: Step 1: Write the html code in the java file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the java code for date and time in the body section. Step 4: Run the program and display output in the web browser. Program: import [Link]; import [Link]; import [Link]; import [Link]; import [Link]; 82
import [Link]; import [Link]; public class ShowDate extends HttpServlet { @Override public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { PrintWriter out = [Link](); [Link]("<html>"); [Link]("<head>"); [Link]("<title>Date and Time using Servlet</title>"); [Link]("</head>"); [Link]("<body bgcolor=\"00FFCC\">"); [Link]("<h2>Date and Time on Server using Servlet</h2>"); [Link]("<p>"+new [Link]()+"</p>"); [Link]("</body>"); [Link]("</html>"); [Link](); } }
Result: The program for date and time using Servlet is successfully executed. Output:
83
Aim: To write a program to display date and time using Servlet. Algorithm: Step 1: Write the html code in the html file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the servlet code inside java program. Step 4: Compile the servlet program/ Step 5: Start Tomcat, if it is not already running. Step 6: Display the Web page in a browser and Select a color. Step 7: Submit the Web page. Program: [Link] <body> <center> <form name="Form1" method="get"action="/SRMAdvanceJSP/ShowFruit"> <B>Fruit:</B><select name="fruit" size="1"> 84
<option value="Apple">Apple</option> <option value="Banana">Banana</option> <option value="Dry Fruit">Dry Fruit</option> <option value="Guava">Guava</option> <option value="Mango">Mango</option> <option value="Orange">Orange</option> <option value="Pineapple">Pineapple</option> </select><br><br> <input type=submit value="Submit"> </form></body> </html> [Link] import [Link].*; import [Link].*; import [Link].*; public class ShowFruit extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fruit = [Link]("fruit"); [Link]("text/html"); PrintWriter pw = [Link](); [Link]("<B>The selected Fruit is: "); [Link](fruit); [Link](); } } Result: The program Servlet get request() method is successfully executed. Input:
85
Output:
86
Aim: To write a program to display date and time using Servlet. Algorithm: Step 1: Write the html code in the html file. Step 2: Write the title of the program inside the head section of html code. Step 3: Write the servlet code inside java program. Step 4: Compile the servlet program/ Step 5: Start Tomcat, if it is not already running. Step 6: Display the Web page in a browser and Select a color. Step 7: Submit the Web page. Program: [Link] <body> <center> <form name="Form1" method="post" action="/SRMAdvanceJSP/ShowCourse"> <B>Course:</B><select name="course" size="1"> <option value="BA">BA</option> <option value="BBA">BBA</option> <option value="BCA">BCA</option> <option value="[Link]">[Link]</option> <option value="[Link](Biotech)">[Link](Biotech)</option> <option value="[Link].">[Link].</option> <option value="MA">MA</option> <option value="MBA">MBA</option> <option value="MCA">MCA</option> <option value="[Link]">[Link]</option> <option value="[Link](Bioech)">[Link](Biotech)</option> <option value="[Link].">[Link].</option> </select><br><br> <input type=submit value="Submit"> </form></body> </html> [Link] //doPost method import [Link].*; 87
import [Link].*; import [Link].*; public class ShowCourse extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String fruit = [Link]("course"); [Link]("text/html"); PrintWriter pw = [Link](); [Link]("<B>The selected Course is: "); [Link](fruit); [Link](); } } Result: The program for date and time using Servlet is successfully executed. Input:
88
Output:
Aim: To write a program to insert a student record using JDBC. Algorithm: Step 1: Create DSN for the database and load the JDBC Driver using [Link](). Step 2: Create Connection using [Link](). Step 3: Create Statement using Connection [Link](). Step 4: Create Insert query and write execute statement using executeUpdate(). Step 5: Run the program and enter Student information to store into the database. Program: import [Link].*; /** * @author Yadu */ public class DataInsertion { 89
public static void main(String[] args) { Connection con = null; try { [Link]("[Link]"); con = [Link]("jdbc:odbc:srm", "swt", "swt"); Statement stmt = [Link](); int n = [Link]("INSERT INTO stu VALUES('3521130001','ashish','MCA','2011')"); if (n > 0) { [Link]("Record inserted successfully!"); } else { [Link]("Unable to Insert!"); } [Link](); } catch (Exception e) { [Link](); } finally { if (con != null) { try { [Link](); } catch (Exception e) { [Link](); } } } } } Result: The program to insert student information from the database has been successfully executed. Output: Record inserted successfully!
90
Aim: To write a program to retrieve a student record using JDBC. Algorithm: Step 1: Create DSN for the database. Step 2: Load the JDBC Driver using [Link](). Step 3: Create Connection using [Link](). Step 4: Create Statement using Connection [Link](). Step 5: Create ResultSet and also create retrieve query and write execute statement using executeQuery(). Step 6: Run the program and enter Student Registration number to retrieve his information. Program: import [Link].*; /** * @author Nitesh */ public class DataRetrieval { public static void main(String[] args) { Connection con = null; try { [Link]("[Link]"); con = [Link]("jdbc:odbc:srm", "swt", "swt"); Statement stmt = [Link](); ResultSet rs = [Link]("SELECT * FROM stu"); [Link]("Reg no. while ([Link]()) { Name Course Year of Admission");
91
[Link]("%-15s%-20s%-10s%-10s\n", [Link](1), [Link](2), [Link](3), [Link](4)); } [Link](); } catch (Exception e) { [Link](); } finally { if (con != null) { try { [Link](); } catch (Exception e) { [Link](); } } } } }
Result: The program to delete student information from the database has been successfully executed. Output: Reg no. 3521130004 3521130008 3521130011 3521130023 3521130024 3521130026 3521130050 3521130002 Name ankur shubham nitesh prabhat pandey nitin ashish Course MCA MCA MCA MCA MCA MCA MCA 92 Year of Admission 2011 2011 2011 2011 2011 2011 2011 2011 ashish pandey MCA
Aim: To write a program to delete a student record using JDBC. Algorithm: Step 1: Create DSN for the database. Step 2: Load the JDBC Driver using [Link](). Step 3: Create Connection using [Link](). Step 4: Create Statement using Connection [Link](). Step 5: Create Delete query and write execute statement using executeUpdate(). Step 6: Run the program and enter Student Registration number to delete. Program: import [Link].*; /** * @author Nitesh */ public class DataDeletion { public static void main(String[] args) { Connection con = null; try { [Link]("[Link]"); con = [Link]("jdbc:odbc:srm", "swt", "swt"); Statement stmt = [Link](); int n = [Link]("DELETE FROM stu WHERE regno='3521130001'"); if (n > 0) { [Link](n + " rows DELETED!"); } else { [Link]("Unable to delete"); 93
} [Link](); } catch (Exception e) { [Link](); } finally { if (con != null) { try { [Link](); } catch (Exception e) { [Link](); } } } } } Result: The program to delete student information from the database has been successfully executed. Output: 1 rows DELETED!
94