SIDDHARTHA Institute of Engineering and Technology

Size: px
Start display at page:

Download "SIDDHARTHA Institute of Engineering and Technology"

Transcription

1 SIDDHARTHA Institute of Engineering and Technology Department of Computer Science &Engineering JAVA Programming Lab Manual [Subject Code: A40585] For the Academic year II B Tech II Semester

2 List of Experiments 1. Use eclipse or Netbean platform and acquaint with the various menus, create a test project, add a test class and run it see how you can use auto suggestions, auto fill. Try code formatter and code refactoring like renaming variables, methods and classes. Try debug step by step with a small program of about 10 to 15 lines which contains at least one if else condition and a for loop. 2. Write a Java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the +, -,*, % operations. Add a text field to display the result. Handle any possible exceptions like divide by zero. 3. a. Develop an applet that displays a simple message b. Develop an Applet that receives an integer in one text field & compute its factorial value & returns it in another text filed when the button Compute is clicked 4. Write a program that creates a user interface to perform integer divisions. The user enters two numbers in the text fields, Num1 and Num2. The division of Num1 and Num2 is displayed in the Result field when the Divide button is clicked. If Num1 or Num2 were not an integer, the program would throw a NumberFormatException. If Num2 were Zero, the program would throw an Arithmetic Exception Display the exception in a message dialog box 5. Write a java program that implements a multi-thread application that has three threads. First thread generates random integer every 1 second and if the value is even, second thread computes the square of the number and prints. If the value is odd, the third thread will print the value of cube of the number. 6. Write a java program that connects to a database using JDBC and does add, deletes, modify and retrieve operations 7. Write a java program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green with radio buttons. On selecting a button, an appropriate message with stop or ready or go should appear above the buttons in a selected color. Initially there is no message shown. 8. Write a java program to create an abstract class named Shape that contains two integers and an empty method named printarea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printarea( ) that prints the area of the given shape.

3 9. Suppose that a table named Table.txt is stored in a text file. The first line in the file header and the remaining lines correspond to row in the table. The elements are separated by commas. Write a Java program to display the table using labels in grid layout. 10. Write a Java program that handles all mouse events and shows the event name at the center of the window when a mouse event is fired. (Use adapter classes). 11. Write a java program that loads names and phone numbers from a text file where the data is organized as one line per record and each field in a record are separated by a tab (\t).it takes a name or phone number as input and prints the corresponding other value from the hash table(hint: use hash tables) 12. Implement the above program with database instead of a text file. 13. Write a java program that takes tab separated data (one record per line) from a text file and inserts them into a database 14. Write a java program that prints the meta-data of a given table.

4 1. Use eclipse or Net bean platform and acquaint with the various menus, create a test project, add a test class and run it see how you can use auto suggestions, auto fill. Try code formatter and code refactoring like renaming variables, methods and classes. Try debug step by step with a small program of about 10 to 15 lines which contains at least one if else condition and a for loop. Aim: Implement sample java program using eclipse or Netbeans & use its code formatter code refactoring (renaming variable) & debug step by step. Program: import java.util.*; public class Testp public static void main(string[] args) System.out.println("Welcome to Siddhartha Engineering College"); Scanner sc = new Scanner(System.in); System.out.println("Enter valid Number"); int n = sc.nextint(); int c = 0; for (int i = 1; i <= n; i++) if (n % i == 0) c++; if (c == 2) System.out.println(n + "is Prime Number"); else System.out.println(n + "is not Prime Number"); Output: E:\java>javac Testp.java E:\java>java Testp Welcome to Siddhartha Engineering College Enter valid Number 7 7 is Prime Number

5 2. Write a Java program that works as a simple calculator. Use a grid layout to arrange buttons for the digits and for the +, -,*, % operations. Add a text field to display the result. Handle any possible exceptions like divide by zero. Aim: Implement simple calculator using grid layout. ALGORITHM: Input: Press the values and operation in the calculator Output: Displays the values in the text field 1 Start 2 take applet 3 add new Labels 4 call action performed method. 5 Check the type of operation. 6 Compute the Result. 7 Display the Result. 8 Stop Program: import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; class A extends JFrame implements ActionListener public JButton b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16; public JTextField tf1; public JPanel p; public String v = ""; public String v1 = "0"; public String op = ""; public A() setdefaultcloseoperation(jframe.exit_on_close); setsize(400, 400); p = new JPanel(new FlowLayout()); tf1 = new JTextField(10); p.add(tf1); add(p); setlayout(new GridLayout(0, 3)); b1 = new JButton("1"); b1.addactionlistener(this); add(b1); b2 = new JButton("2"); b2.addactionlistener(this); add(b2); b3 = new JButton("3"); b3.addactionlistener(this); add(b3); b4 = new JButton("4"); b4.addactionlistener(this);

6 add(b4); b5 = new JButton("5"); b5.addactionlistener(this); add(b5); b6 = new JButton("6"); b6.addactionlistener(this); add(b6); b7 = new JButton("7"); b7.addactionlistener(this); add(b7); b8 = new JButton("8"); b8.addactionlistener(this); add(b8); b9 = new JButton("9"); b9.addactionlistener(this); add(b9); b10 = new JButton("0"); b10.addactionlistener(this); add(b10); b11 = new JButton("+"); b11.addactionlistener(this); add(b11); b12 = new JButton("-"); b12.addactionlistener(this); add(b12); b13 = new JButton("*"); b13.addactionlistener(this); add(b13); b14 = new JButton("/"); b14.addactionlistener(this); add(b14); b16 = new JButton("%"); b16.addactionlistener(this); add(b16); b15 = new JButton("="); b15.addactionlistener(this); add(b15); setvisible(true); public void actionperformed(actionevent ae) String b = ae.getactioncommand(); switch (b) case "1":

7 v = v + "1"; tf1.settext(v); case "2": v = v + "2"; tf1.settext(v); case "3": v = v + "3"; tf1.settext(v); case "4": v = v + "4"; tf1.settext(v); case "5": v = v + "5"; tf1.settext(v); case "6": v = v + "6"; tf1.settext(v); case "7": v = v + "7"; tf1.settext(v); case "8": v = v + "8"; tf1.settext(v); case "9": v = v + "9"; tf1.settext(v);

8 case "0": v = v + "0"; tf1.settext(v); case "+": op = "+"; v1 = tf1.gettext(); v = ""; case "-": op = "-"; v1 = tf1.gettext(); v = ""; case "*": op = "*"; v1 = tf1.gettext(); v = ""; case "/": op = "/"; v1 = tf1.gettext(); v = ""; case "%": op = "%"; v1 = tf1.gettext(); v = ""; case "=": switch (op) case "+": v = tf1.gettext(); if (v.equals("")) v = "0"; long i = Long.parseLong(v1) + Long.parseLong(v); tf1.settext(string.valueof(i)); v="";

9 case "-": v = tf1.gettext(); if (v.equals("")) v = "0"; long i = Long.parseLong(v1) - Long.parseLong(v); tf1.settext(string.valueof(i)); v=""; case "*": v = tf1.gettext(); if (v.equals("")) v = "0"; long i = Long.parseLong(v1) * Long.parseLong(v); tf1.settext(string.valueof(i)); v=""; case "/": try v = tf1.gettext(); if (v.equals("")) v = "0"; long i = Long.parseLong(v1) / Long.parseLong(v); tf1.settext(string.valueof(i)); v=""; catch (Exception ex) JOptionPane.showMessageDialog(this, ex.getmessage()); case "%": try v = tf1.gettext(); if (v.equals("")) v = "0"; long i = Long.parseLong(v1) % Long.parseLong(v); tf1.settext(string.valueof(i)); v="";

10 catch (Exception ex) JOptionPane.showMessageDialog(this, ex.getmessage()); public class Calc public static void main(string[] args) A a = new A(); Output:

11 3. a) Develop an applet that displays a simple message. Aim: Implement Applet to display a simple message. Algorithm: Input: Enter the Message Output: Displays the message in applet Step1: start Step 2: Create one class with Simple Applet Step3: compute the data Step 4: Display the Data Step 5: Stop PROGRAM: import java.applet.applet; import java.awt.*; public class Sms extends Applet public void init() public void paint(graphics g) g.setcolor(color.blue); Font font = new Font("verdana", Font.BOLD, 15); g.setfont(font); g.drawstring("welcome To Siddhartha Eng College", 50, 50); /* <applet code=sms.class height=300 width=400> </applet> */ output:

12 3.b) Develop an Applet that receives an integer in one text field & compute its factorial value & returns it in another text filed when the button Compute is clicked. Aim: Implement an Applet program that calculates the factorial of a given number. Algorithm: Input: Value of T1 Output: Compute the factorial value Step1: Start. Step2: Import java.awt pack, and relevant packages. Step3: Import java.lang.string,awt. event,applet.applet packages. Step4: Create Class that extends Applet implements Action Listener Step5: Create Buttons and Text Fields. Step6: Create the Data. To set variables in the fields. Step7: Compute the data. Step8: Print the Data.(display) Step9: Stop. PROGRAM import java.applet.applet; import java.awt.*; import java.awt.event.*; public class Fact extends Applet implements ActionListener Label l1, l2, l3; TextField tf1, tf2; Button b1; public void init() setsize(400, 200); FlowLayout g = new FlowLayout(); setlayout(g); l1 = new Label("Enter Value"); l1.setforeground(color.blue); add(l1); tf1 = new TextField(5); tf1.settext("0"); add(tf1); b1 = new Button("Compute"); b1.addactionlistener(this); add(b1); l3 = new Label(); add(l3); l2 = new Label("factorial: "); l2.setforeground(color.blue); add(l2); tf2 = new TextField(5); add(tf2);

13 public void actionperformed(actionevent ae) long n = Integer.parseInt(tf1.getText()); long f = 1; while (n!= 0) f = f * n; n--; tf2.settext(string.valueof(f)); /* <applet code=fact.class height=300 width=400> </applet> */ Output:

14 4. Write a program that creates a user interface to perform integer divisions. The user enters two numbers in the text fields, Num1 and Num2. The division of Num1 and Num2 is displayed in the Result field when the Divide button is clicked. If Num1 or Num2 were not an integer, the program would throw a NumberFormatException. If Num2 were Zero, the program would throw an Arithmetic Exception Display the exception in a message dialog box. Aim: Implement a user interface to perform integer division and handle Arithmetic Exception. Algorithm: Input: Values of Text field T1, T2 Output: Displays the result in Text field T3 Step1: Start. Step2: Import java.awt package Step3: Import java.lang.string,awt. event,applet.applet packages. Step4: Create Class Step5: Create Buttons and Text Fields. Step6: Create the Data. Step7: Perform the division. Step8: Print the Data. Step9: Stop. PROGRAM: import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class A extends JFrame implements ActionListener JLabel l1, l2, l3; JTextField tf1, tf2, tf3; JButton b1; A() setdefaultcloseoperation(jframe.exit_on_close); setlayout(new FlowLayout()); l1 = new JLabel("Welcome"); setsize(800, 400); l1 = new JLabel("Enter Number1"); add(l1); tf1 = new JTextField(10); add(tf1); l2 = new JLabel("Enter Number2"); add(l2); tf2 = new JTextField(10); add(tf2); l3 = new JLabel("Result"); add(l3); tf3 = new JTextField(10); add(tf3);

15 b1 = new JButton("Divide"); add(b1); b1.addactionlistener(this); setvisible(true); public void actionperformed(actionevent ae) try int a = Integer.parseInt(tf1.getText()); int b = Integer.parseInt(tf2.getText()); if(b==0) throw new ArithmeticException(" Divide by Zero Error"); float c = (float) a / b; tf3.settext(string.valueof(c)); catch (NumberFormatException ex) JOptionPane.showMessageDialog(this, ex.getmessage()); catch (ArithmeticException ex) JOptionPane.showMessageDialog(this, ex.getmessage()); public class JavaApplication public static void main(string[] args) A a = new A(); Output:

16 5.Write a java program that implements a multi-thread application that has three threads. First thread generates random integer every 1 second and if the value is even, second thread computes the square of the number and prints. If the value is odd, the third thread will print the value of cube of the number. Aim: Implement multithreading concept using a simple application. Algorithm: Input: Enter the threads Output: Displays multiple threads Step1: Start. Step2: Import the packages. Step3: Create multiple threads class. Step4: Create Multiple thread Implements Runnable. Step5: Initialize the threads. Step6: Creating entry point for the thread. Step7: Use exceptions. Step8: Create multiple thread demo, Create main() Start threads. Step9: Display the threads (Three threads) Step10: Stop. PROGRAM import java.util.*; class even implements Runnable public int x; public even(int x) this.x = x; public void run() System.out.println("Thread Name:Even Thread and " + x + "is even Number and Square of " + x + " is: " + x * x); class odd implements Runnable public int x; public odd(int x) this.x = x; public void run()

17 System.out.println("Thread Name:ODD Thread and " + x + " is odd number and Cube of " + x + " is: " + x * x * x); class A extends Thread public String tname; public Random r; public Thread t1, t2; public A(String s) tname = s; public void run() int num = 0; r = new Random(); try for (int i = 0; i < 50; i++) num = r.nextint(100); System.out.println("Main Thread and Generated Number is " + num); if (num % 2 == 0) t1 = new Thread(new even(num)); t1.start(); else t2 = new Thread(new odd(num)); t2.start(); Thread.sleep(1000); System.out.println(" "); catch (Exception ex) System.out.println(ex.getMessage()); public class Mthread public static void main(string[] args) A a = new A("One"); a.start();

18 Output:

19 6).Write a java program that connects to a database using JDBC and does add, deletes, modify and retrieve operations Aim: Implement the Database connectivity program using JDBC to perform add, delete and modify. Algorithm: Input: Enter the connection detail. Output: Perform add, delete, modify and retrieve operation. 1: Start. 2: Import the packages. 3: Make the connection. 4: Create another class for making operations. 5: Another class for retrieve the operation. 6: Display the output. 9: Stop. PROGRAM import java.sql.*; import javax.sql.*; import java.util.*; class CRUD public static void main(string[] args) Connection cn; Statement st; ResultSet rs; try Class.forName("oracle.jdbc.driver.OracleDriver"); con = DriverManager. getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","system"); st = cn.createstatement(); System.out.println("------MENU------"); System.out.println("1.Insert"); System.out.println("2.EDIT"); System.out.println("3.Delete"); System.out.println("4.Display"); System.out.println("5.Exit"); System.out.println(" "); String opt = ""; String htno = "", sname = "", mobile = "", sql = ""; Scanner sc = new Scanner(System.in); while (opt!= "5") System.out.println("Enter Your Option"); opt = sc.next(); switch (opt) case "1": System.out.println("Enter Htno");

20 htno = sc.next(); System.out.println("Enter Name"); sname = sc.next(); System.out.println("Enter Mobile"); mobile = sc.next(); sql = "insert into stu values(" + "'" + htno + "'" + "," + "'" + sname + "'" + "," + "'" + mobile + "'" + ")"; if (st.executeupdate(sql) > 0) System.out.println("Record Inserted"); case "2": System.out.println("Enter Htno to Update"); htno = sc.next(); System.out.println("Enter Name"); sname = sc.next(); System.out.println("Enter Mobile"); mobile = sc.next(); sql = "update stu set sname=" + "'" + sname + "'" + "," + "mobile=" + "'" + mobile + "'" + " where htno='" + htno + "'"; if (st.executeupdate(sql) > 0) System.out.println("Record Updated"); else System.out.println("Operation Failed"); case "3": System.out.println("Enter Htno to delete"); htno = sc.next(); sql = "delete from stu where Htno=" + "'" + htno + "'"; if (st.executeupdate(sql) > 0) System.out.println("Record deleted"); else System.out.println("Operation Failed"); case "4": sql = "select * from stu"; rs = st.executequery(sql); System.out.println("Htno\tSname\tMobile"); while (rs.next()) System.out.println(rs.getString("Htno") + "\t" + rs.getstring("sname") + "\t" + rs.getstring("mobile"));

21 rs.close(); case "5": opt = "5"; System.out.println("Thank You"); st.close(); cn.close(); default: System.out.println("Choose Option between 1 and 5 only"); catch (Exception ex) System.out.println(ex.getMessage());

22 Output:

23 7) Write a java program that simulates a traffic light. The program lets the user select one of three lights: red, yellow, or green with radio buttons. On selecting a button, an appropriate message with stop or ready or go should appear above the buttons in a selected color. Initially there is no message shown. Aim: Implement traffic light using AWT layouts. Algorithm: Input: Create the traffic light GUI Output: Perform the traffic light operation Step1: Start. Step2: Import all relevant packages. Step3: Create a Class that Extends ItemListener. Step4: Create Check boxes. Step5: Create init() process to initialize checkboxes. Step6: Create a panel and Set the Layout for Grid(). Step7: Initialize the boxes and add the data ( colours). Step8: Call method paint to colour using Graphics Step9: Set the colour and draw. Step10: Display. Step11: Stop PROGRAM import javax.swing.*; import javax.swing.event.*; import java.awt.*; import java.awt.event.*; class A extends JFrame implements ItemListener public JLabel l1, l2; public JRadioButton r1, r2, r3; public ButtonGroup bg; public JPanel p, p1; public A() setdefaultcloseoperation(jframe.exit_on_close); setlayout(new GridLayout(2, 1)); setsize(800, 400); p = new JPanel(new FlowLayout()); p1 = new JPanel(new FlowLayout()); l1 = new JLabel(); Font f = new Font("Verdana", Font.BOLD, 60); l1.setfont(f); add(l1); p.add(l1); add(p); l2 = new JLabel("Select Lights"); p1.add(l2); JRadioButton r1 = new JRadioButton("Red Light");

24 r1.setbackground(color.red); p1.add(r1); r1.additemlistener(this); JRadioButton r2 = new JRadioButton("Yellow Light"); r2.setbackground(color.yellow); p1.add(r2); r2.additemlistener(this); JRadioButton r3 = new JRadioButton("Green Light"); r3.setbackground(color.green); p1.add(r3); r3.additemlistener(this); add(p1); bg = new ButtonGroup(); bg.add(r1); bg.add(r2); bg.add(r3); setvisible(true); public void itemstatechanged(itemevent i) JRadioButton jb = (JRadioButton) i.getsource(); switch (jb.gettext()) case "Red Light": l1.settext("stop"); l1.setforeground(color.red); case "Yellow Light": l1.settext("ready"); l1.setforeground(color.yellow); case "Green Light": l1.settext("go"); l1.setforeground(color.green); public class Tlights public static void main(string[] args) A a = new A();

25 Output:

26 8) Write a java program to create an abstract class named Shape that contains two integers and an empty method named printarea(). Provide three classes named Rectangle, Triangle and Circle such that each one of the classes extends the class Shape. Each one of the classes contain only the method printarea( ) that prints the area of the given shape. Aim: Implement abstract class using the concept of inheritance. Algorithm: Input: Creates GUI Output: number of sides a triangle, trapezoid and Hexagon 1: Start. 2: Create one abstract Class Shape with method numberofsides(). 3: Create classes triangle, trapezoid and Hexagon which will extend Shape. 4: Implement the method numberofsides() in each class. 5: Create class cointating main(). 6: Display each class method. 7: Stop the Program. PROGRAM abstract class Shape public int x, y; public abstract void printarea(); class Rectangle extends Shape public void printarea() System.out.println("Area of Rectangle is " + x * y); class Triangle extends Shape public void printarea() System.out.println("Area of Triangle is " + (x * y) / 2); class Circle extends Shape public void printarea() System.out.println("Area of Circle is " + (22 * x * x) / 7); public class Abstex public static void main(string[] args) // TODO code application logic here Rectangle r = new Rectangle(); r.x = 10; r.y = 20; r.printarea(); System.out.println(" ");

27 Triangle t = new Triangle(); t.x = 30; t.y = 35; t.printarea(); System.out.println(" "); Circle c = new Circle(); c.x = 2; c.printarea(); System.out.println(" "); Output:

28 9) Suppose that a table named Table.txt is stored in a text file. The first line in the file header and the remaining lines correspond to row in the table. The elements are separated by commas. Write a Java program to display the table using labels in grid layout. Aim: Display the content of a text file using tables in grid layout. Algorithm: Input: Enter the text file Output: Displays the text file information in Table 1: Start. 2: Import all relevant packages 3: Create a Class which extends JFrame class. 4: Create init process for initialization 5: Create and initialize column headings 6: Initialize the data 7: create the table 8: Add the table to a scroll pane 9: add the scroll pane to the content pane 10: Display the table contents 11: Stop PROGRAM: import java.io.*; import java.util.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class A extends JFrame public A() setsize(400, 400); setdefaultcloseoperation(jframe.exit_on_close); GridLayout g = new GridLayout(0, 3); setlayout(g); try FileInputStream fin = new FileInputStream("E:\\emp.txt"); Scanner sc = new Scanner(fin).useDelimiter(","); String[] arraylist; String a; while (sc.hasnextline()) a = sc.nextline(); arraylist = a.split(","); for (String i : arraylist) add(new JLabel(i)); catch (Exception ex)

29 setdefaultlookandfeeldecorated(true); pack(); setvisible(true); public class Tbl public static void main(string[] args) A a = new A(); Output:

30 10. Write a Java program that handles all mouse events and shows the event name at the center of the window when a mouse event is fired. (Use adapter classes). Aim: Implement all mouse events using adapter classes. ALGORITHM: Input: Mouse Operation Output: Displays the all mouse functions 1. Start the program. 2. Import the packages of applet, awt, awt.event. 3. Create a class, methods. 4. Mouse moments, mouse Clicked, mouse Pressed, mouse Released, mouse Entered, mouse Exited, mouse Dragged events args. 5. Write g.drawstring() application of Graphical User Interface. 6. While rotating mouse event args. 7. The mouse event arguments execution. 8. Printing in the separated Applet viewer window. 9. Stop the program. PROGRAM: import java.awt.*; import java.applet.*; import java.awt.event.*; /*<applet code="mousedemo" width=300 height=300> </applet>*/ public class MouseDemo extends Applet implements MouseListener,MouseMotionListener int mx=0; int my=0; String msg=""; public void init() addmouselistener(this); addmousemotionlistener(this); public void mouseclicked(mouseevent me) mx=20; my=40; msg="mouse Clicked"; repaint(); public void mousepressed(mouseevent me) mx=30; my=60;

31 msg="mouse Pressed"; repaint(); public void mousereleased(mouseevent me) mx=30; my=60; msg="mouse Released"; repaint(); public void mouseentered(mouseevent me) mx=40; my=80; msg="mouse Entered"; repaint(); public void mouseexited(mouseevent me) mx=40; my=80; msg="mouse Exited"; repaint(); public void mousedragged(mouseevent me) mx=me.getx(); my=me.gety(); showstatus("currently mouse dragged"+mx+" "+my); repaint(); public void mousemoved(mouseevent me) mx=me.getx(); my=me.gety(); showstatus("currently mouse is at"+mx+" "+my); repaint(); public void paint(graphics g) g.drawstring("handling Mouse Events",30,20); g.drawstring(msg,60,40);

32 Output:

33 11).Write a java program that loads names and phone numbers from a text file where the data is organized as one line per record and each field in a record are separated by a tab (\t).it takes a name or phone number as input and prints the corresponding other value from the hash table(hint: use hash tables) Aim: Implement a program to display the content of a text file using hash tables. ALGORITHM: Input: Enter the text file Output: Displays all the data using hash table 1. Start the program. 2. Import the packages of Io.BufferdReader, io.file, io.filenotfoundexception, io.filereader, IOException, util.hashtable, utiliterator, util.set. 3. Create classes, methods. 4. Create Hash Table and store the data in Hash table from file. 5. Use Iterator interface to search the value. 6. After getting the input value print the other value from Hash Table. 7. Print the output. 8. Stop the Program. Program: import java.util.*; import java.io.*; public class Hashtbl public static void main(string[] args) try FileInputStream fs = new FileInputStream("E:\\ph.txt"); Scanner sc = new Scanner(fs).useDelimiter("\\s+"); Hashtable<String, String> ht = new Hashtable<String, String>(); String[] arraylist; String a; System.out.println("HASH TABLE IS"); System.out.println(" "); System.out.println("KEY : VALUE"); while (sc.hasnext()) a = sc.nextline(); arraylist = a.split("\\s+"); ht.put(arraylist[0], arraylist[1]); System.out.println(arrayList[0] + ":" + arraylist[1]); System.out.println("----MENU------"); System.out.println("----1.Search by Name------"); System.out.println("----2.Search by Mobile------"); System.out.println("----3.Exit------"); String opt = ""; String name, mobile; Scanner s = new Scanner(System.in);

34 while (opt!= "3") System.out.println("Enter Your Option 1,2,3"); opt = s.next(); switch (opt) case "1": System.out.println("Enter Name"); name = s.next(); if (ht.containskey(name)) System.out.println("Mobile is " + ht.get(name)); else System.out.println("Not Found"); case "2": System.out.println("Enter mobile"); mobile = s.next(); if (ht.containsvalue(mobile)) for (@SuppressWarnings("rawtypes") Map.Entry e : ht.entryset()) if (mobile.equals(e.getvalue())) System.out.println("Name is " + e.getkey()); else System.out.println("Not Found"); case "3": opt = "3"; System.out.println("Menu Successfully Exited"); default: System.out.println("Choose Option betwen 1 and Three"); catch (Exception ex) System.out.println(ex.getMessage());

35 Output:

36 12).Implement the above program with database instead of a text file. Aim: Implement the program to display the content of database using hash table. ALGORITHM: Input: Enter data in database using java program. Output: Displays the data from database using java program. 1. Start the program. 2. Import the packages of Io.BufferdReader, io.file, io.filenotfoundexception, io.filereader, IOException, util.hashtable, utiliterator, util.set. 3. Create classes, methods. 4. Create Hash Table and store the data in Hash table from file. 5. Use Iterator interface to search the value. 6. After getting the input value print the other value from Hash Table. 7. Print the output. 8. Stop the Program. Program: import java.sql.*; import java.util.*; public class Hashtbl2 public static void main(string[] args) Connection cn; Statement st; ResultSet rs; try Class.forName("oracle.jdbc.driver.OracleDriver"); cn = DriverManager. getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","system"); st = cn.createstatement(); rs = st.executequery("select * from phone"); Hashtable<String, String> ht = new Hashtable<String, String>(); System.out.println("HASH TABLE IS"); System.out.println(" "); System.out.println("KEY : VALUE"); while (rs.next()) ht.put(rs.getstring("name"), rs.getstring("mobile")); System.out.println(rs.getString("Name") + ":" + rs.getstring("mobile")); rs.close(); st.close(); cn.close(); System.out.println("Welcome TO Siddhartha Eng College"); System.out.println("----MENU------"); System.out.println("----1.Search by Name------"); System.out.println("----2.Search by Mobile------"); System.out.println("----3.Exit------"); String opt = ""; String name, mobile; Scanner s = new Scanner(System.in); while (opt!= "3") System.out.println("Enter Your Option 1,2,3"); opt = s.next();

37 switch (opt) case "1": System.out.println("Enter Name"); name = s.next(); if (ht.containskey(name)) System.out.println("Mobile is " + ht.get(name)); else System.out.println("Not Found"); case "2": System.out.println("Enter mobile"); mobile = s.next(); if (ht.containsvalue(mobile)) for (Map.Entry e : ht.entryset()) if (mobile.equals(e.getvalue())) System.out.println("Name is " + e.getkey()); else System.out.println("Not Found"); case "3": opt = "3"; System.out.println("Menu Successfully Exited"); default: System.out.println("Choose Option betwen 1 and Three"); catch (Exception ex) System.out.println(ex.getMessage()); Program Output:

38

39 13).Write a java program that takes tab separated data (one record per line) from a text file and inserts them into a database. Aim: Implement a program to read data from text file and insert in the database. ALGORITHM: Input: Enter data in database using java program. Output: Displays the data from database using java program. 1. Start the program. 2. Import the packages of BufferedReader,File,FileNotFoundException, FileReader,Exception, Connection,PreparedStatement,ResultSet,SQLException,Statement,Hashtable,util.Iterator. 3. Create classes, methods. 4. Create Hash Table and store the data in Hash table from file. 5. Use ConnectionUtil class and writedatatodatabase method. 6. After getting the input value print the other value from Hash Table. 7. Print the output. 8. Stop the Program. Program: import java.sql.*; import java.io.*; import java.util.*; public class Tbltodb public static void main(string[] args) Connection cn; Statement st; try Class.forName("oracle.jdbc.driver.OracleDriver"); cn = DriverManager. getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","system"); st=cn.createstatement(); String sql=""; FileInputStream fin=new FileInputStream("E:\\emp1.txt"); Scanner sc=new Scanner(fin); String[] arraylist; String a=""; int i=0; while(sc.hasnext()) a=sc.nextline(); arraylist =a.split("\\s+"); sql="insert into emp1 values("+"'"+arraylist[0]+"','"+arraylist[1]+"','"+arraylist[2]+"')"; st.execute(sql); i++; System.out.println(arrayList[0]+":"+arrayList[1]+":"+arrayList[2]); System.out.println(i+" Records are inserted"); st.close(); cn.close(); catch(exception ex) System.out.println(ex.getMessage());

40 Output:

41 14).Write a java program that prints the meta-data of a given table. Aim: Implement a program to display metadata of a given table. ALGORITHM: Input: Enter the text file Output: Displays all the data using hash table 1. Start the program. 2. Import the packages of sql.connection, sql.resultsetmetadata, sql.sqlexception, sql.statement; 3. Create classes, methods. 4. Create connection object and ResultSet object. 5. Use printmetadata method to extract the metadata of table. 6. Print the output. 7. Stop the Program. Program: import java.sql.*; import java.util.*; public class Tblmdata public static void main(string[] args) Connection cn; Statement st; ResultSet rs, rs1; ResultSetMetaData rsmd; try Scanner sc = new Scanner(System.in); System.out.println("Enter Database Name"); String dbname = sc.next(); System.out.println("Enter Password"); String pass = sc.next(); Class.forName("oracle.jdbc.driver.OracleDriver"); cn = DriverManager. getconnection("jdbc:oracle:thin:@localhost:1521:xe","system","system"); st = cn.createstatement(); DatabaseMetaData dm = cn.getmetadata(); rs = dm.gettables(cn.getcatalog(), "%", "%", null); String s = ""; String sql = "select * from ", sql1 = ""; System.out.println(" Database is " + dbname); System.out.println(" "); System.out.println("Tables are"); System.out.println(" "); while (rs.next()) sql1 = ""; System.out.println(" Table Name: " + rs.getstring(3) + " "); sql1 = sql + rs.getstring(3); rs1 = st.executequery(sql1); rsmd = rs1.getmetadata(); System.out.println("Columns are "); System.out.println("Column Name\tColumn Type\tSize"); for (int i = 1; i <= rsmd.getcolumncount(); i++) System.out.println(rsmd.getColumnLabel(i) + "\t" + rsmd.getcolumntypename(i) + "\t" + rsmd.getcolumndisplaysize(i));

42 System.out.println(" "); rs.close(); cn.close(); catch (Exception ex) System.out.println(ex.getMessage()); Output:

Week -1. Try debug step by step with small program of about 10 to 15 lines which contains at least one if else condition and a for loop.

Week -1. Try debug step by step with small program of about 10 to 15 lines which contains at least one if else condition and a for loop. Week -1 Try debug step by step with small program of about 10 to 15 lines which contains at least one if else condition and a for loop. Java Code import java.util.scanner; public class TestPrime public

More information

Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*;

Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*; Program 20: //Design an Applet program to handle Mouse Events. import java.awt.*; import java.applet.*; import java.awt.event.*; /* */ public

More information

JRadioButton account_type_radio_button2 = new JRadioButton("Current"); ButtonGroup account_type_button_group = new ButtonGroup();

JRadioButton account_type_radio_button2 = new JRadioButton(Current); ButtonGroup account_type_button_group = new ButtonGroup(); Q)Write a program to design an interface containing fields User ID, Password and Account type, and buttons login, cancel, edit by mixing border layout and flow layout. Add events handling to the button

More information

Computer Science 210: Data Structures. Intro to Java Graphics

Computer Science 210: Data Structures. Intro to Java Graphics Computer Science 210: Data Structures Intro to Java Graphics Summary Today GUIs in Java using Swing in-class: a Scribbler program READING: browse Java online Docs, Swing tutorials GUIs in Java Java comes

More information

GUI in Java TalentHome Solutions

GUI in Java TalentHome Solutions GUI in Java TalentHome Solutions AWT Stands for Abstract Window Toolkit API to develop GUI in java Has some predefined components Platform Dependent Heavy weight To use AWT, import java.awt.* Calculator

More information

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks)

Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) M257 MTA Spring2010 Multiple Choice Questions: Identify the choice that best completes the statement or answers the question. (15 marks) 1. If we need various objects that are similar in structure, but

More information

H212 Introduction to Software Systems Honors

H212 Introduction to Software Systems Honors Introduction to Software Systems Honors Lecture #19: November 4, 2015 1/14 Third Exam The third, Checkpoint Exam, will be on: Wednesday, November 11, 2:30 to 3:45 pm You will have 3 questions, out of 9,

More information

PESIT Bangalore South Campus

PESIT Bangalore South Campus INTERNAL ASSESSMENT TEST II Date : 20-09-2016 Max Marks: 50 Subject & Code: JAVA & J2EE (10IS752) Section : A & B Name of faculty: Sreenath M V Time : 8.30-10.00 AM Note: Answer all five questions 1) a)

More information

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2,

Java Mouse Actions. C&G criteria: 5.2.1, 5.4.1, 5.4.2, Java Mouse Actions C&G criteria: 5.2.1, 5.4.1, 5.4.2, 5.6.2. The events so far have depended on creating Objects and detecting when they receive the event. The position of the mouse on the screen can also

More information

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4.

Virtualians.ning.pk. 2 - Java program code is compiled into form called 1. Machine code 2. native Code 3. Byte Code (From Lectuer # 2) 4. 1 - What if the main method is declared as private? 1. The program does not compile 2. The program compiles but does not run 3. The program compiles and runs properly ( From Lectuer # 2) 4. The program

More information

G51PRG: Introduction to Programming Second semester Applets and graphics

G51PRG: Introduction to Programming Second semester Applets and graphics G51PRG: Introduction to Programming Second semester Applets and graphics Natasha Alechina School of Computer Science & IT nza@cs.nott.ac.uk Previous two lectures AWT and Swing Creating components and putting

More information

Java Programming Lecture 6

Java Programming Lecture 6 Java Programming Lecture 6 Alice E. Fischer Feb 15, 2013 Java Programming - L6... 1/32 Dialog Boxes Class Derivation The First Swing Programs: Snow and Moving The Second Swing Program: Smile Swing Components

More information

Chapter #1. Program to demonstrate applet life cycle

Chapter #1. Program to demonstrate applet life cycle Chapter #1. Program to demonstrate applet life cycle import java.applet.applet; import java.awt.*; public class LifeCycle extends Applet{ public void init(){ System.out.println(" init()"); public void

More information

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like:

OOP Assignment V. For example, the scrolling text (moving banner) problem without a thread looks like: OOP Assignment V If we don t use multithreading, or a timer, and update the contents of the applet continuously by calling the repaint() method, the processor has to update frames at a blinding rate. Too

More information

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics

Outline. Topic 9: Swing. GUIs Up to now: line-by-line programs: computer displays text user types text AWT. A. Basics Topic 9: Swing Outline Swing = Java's GUI library Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 7: Expand moving shapes from Assignment 4 into game. "Programming

More information

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008

Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Introduction to Graphical User Interfaces (GUIs) Lecture 10 CS2110 Fall 2008 Announcements A3 is up, due Friday, Oct 10 Prelim 1 scheduled for Oct 16 if you have a conflict, let us know now 2 Interactive

More information

User interfaces and Swing

User interfaces and Swing User interfaces and Swing Overview, applets, drawing, action listening, layout managers. APIs: java.awt.*, javax.swing.*, classes names start with a J. Java Lectures 1 2 Applets public class Simple extends

More information

navlakhi.com / navlakhi.education / navlakhi.mobi / navlakhi.org 1

navlakhi.com / navlakhi.education / navlakhi.mobi / navlakhi.org 1 Example 1 public class ex1 extends JApplet public void init() Container c=getcontentpane(); c.setlayout(new GridLayout(5,2)); JButton b1=new JButton("Add"); JButton b2=new JButton("Search"); JLabel l1=new

More information

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing

CSEN401 Computer Programming Lab. Topics: Graphical User Interface Window Interfaces using Swing CSEN401 Computer Programming Lab Topics: Graphical User Interface Window Interfaces using Swing Prof. Dr. Slim Abdennadher 22.3.2015 c S. Abdennadher 1 Swing c S. Abdennadher 2 AWT versus Swing Two basic

More information

Graphical User Interfaces 2

Graphical User Interfaces 2 Graphical User Interfaces 2 CSCI 136: Fundamentals CSCI 136: Fundamentals of Computer of Science Computer II Science Keith II Vertanen Keith Vertanen Copyright 2011 Extending JFrame Dialog boxes Overview

More information

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords

Goals. Lecture 7 More GUI programming. The application. The application D&D 12. CompSci 230: Semester JFrame subclass: ListOWords Goals By the end of this lesson, you should: Lecture 7 More GUI programming 1. Be able to write Java s with JTextField, JList, JCheckBox and JRadioButton components 2. Be able to implement a ButtonGroup

More information

AP CS Unit 11: Graphics and Events

AP CS Unit 11: Graphics and Events AP CS Unit 11: Graphics and Events This packet shows how to create programs with a graphical interface in a way that is consistent with the approach used in the Elevens program. Copy the following two

More information

Java. GUI building with the AWT

Java. GUI building with the AWT Java GUI building with the AWT AWT (Abstract Window Toolkit) Present in all Java implementations Described in most Java textbooks Adequate for many applications Uses the controls defined by your OS therefore

More information

Packages: Putting Classes Together

Packages: Putting Classes Together Packages: Putting Classes Together 1 Introduction 2 The main feature of OOP is its ability to support the reuse of code: Extending the classes (via inheritance) Extending interfaces The features in basic

More information

1 GUI GUI GUI GUI GUI. GUI(Graphical User Interface) JDK java.awt. ? Component

1 GUI GUI GUI GUI GUI. GUI(Graphical User Interface) JDK java.awt. ? Component 99 6 1999.10.13 0 GUI GUI JDK 1.1 GUI 1 GUI GUI GUI(Graphical User Interface) GUI (GUI ) / ( GUI ) Java GUI JDK 1.1 1.2 1.2 Swing 1.1 java.awt GUI? Component setbounds(int, int, int, int) (x,y) setforeground(color)

More information

Chapter 12 Advanced GUIs and Graphics

Chapter 12 Advanced GUIs and Graphics Chapter 12 Advanced GUIs and Graphics Chapter Objectives Learn about applets Explore the class Graphics Learn about the classfont Explore the classcolor Java Programming: From Problem Analysis to Program

More information

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling

Frames, GUI and events. Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Frames, GUI and events Introduction to Swing Structure of Frame based applications Graphical User Interface (GUI) Events and event handling Introduction to Swing The Java AWT (Abstract Window Toolkit)

More information

Java - Applets. public class Buttons extends Applet implements ActionListener

Java - Applets. public class Buttons extends Applet implements ActionListener Java - Applets Java code here will not use swing but will support the 1.1 event model. Legacy code from the 1.0 event model will not be used. This code sets up a button to be pushed: import java.applet.*;

More information

Come & Join Us at VUSTUDENTS.net

Come & Join Us at VUSTUDENTS.net Come & Join Us at VUSTUDENTS.net For Assignment Solution, GDB, Online Quizzes, Helping Study material, Past Solved Papers, Solved MCQs, Current Papers, E-Books & more. Go to http://www.vustudents.net and

More information

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more

Topic 9: Swing. Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Assignment 5: Will be an open-ended Swing project. "Programming Contest"

More information

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun!

Topic 9: Swing. Why are we studying Swing? GUIs Up to now: line-by-line programs: computer displays text user types text. Outline. 1. Useful & fun! Swing = Java's GUI library Topic 9: Swing Swing is a BIG library Goal: cover basics give you concepts & tools for learning more Why are we studying Swing? 1. Useful & fun! 2. Good application of OOP techniques

More information

Graphic User Interfaces. - GUI concepts - Swing - AWT

Graphic User Interfaces. - GUI concepts - Swing - AWT Graphic User Interfaces - GUI concepts - Swing - AWT 1 What is GUI Graphic User Interfaces are used in programs to communicate more efficiently with computer users MacOS MS Windows X Windows etc 2 Considerations

More information

Chapter 1 GUI Applications

Chapter 1 GUI Applications Chapter 1 GUI Applications 1. GUI Applications So far we've seen GUI programs only in the context of Applets. But we can have GUI applications too. A GUI application will not have any of the security limitations

More information

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1

CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 P a g e 1 CS506 Web Programming and Development Solved Subjective Questions With Reference For Final Term Lecture No 1 Q1 Describe some Characteristics/Advantages of Java Language? (P#12, 13, 14) 1. Java

More information

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1,

Java - Applets. C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, Java - Applets C&G criteria: 1.2.2, 1.2.3, 1.2.4, 1.3.4, 1.2.4, 1.3.4, 1.3.5, 2.2.5, 2.4.5, 5.1.2, 5.2.1, 5.3.2. Java is not confined to a DOS environment. It can run with buttons and boxes in a Windows

More information

Aim: Write a java program to demonstrate the use of following layouts. 1.FlowLayout 2.BorderLayout 3.GridLayout 4.GridBagLayout 5.

Aim: Write a java program to demonstrate the use of following layouts. 1.FlowLayout 2.BorderLayout 3.GridLayout 4.GridBagLayout 5. DEMONSTRATION OF LAYOUT MANAGERS DATE:09.07.11 Aim: Write a java program to demonstrate the use of following layouts. 1.FlowLayout 2.BorderLayout 3.GridLayout 4.GridBagLayout 5.CardLayout Hardware requirements:

More information

Lecture 5: Java Graphics

Lecture 5: Java Graphics Lecture 5: Java Graphics CS 62 Spring 2019 William Devanny & Alexandra Papoutsaki 1 New Unit Overview Graphical User Interfaces (GUI) Components, e.g., JButton, JTextField, JSlider, JChooser, Containers,

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CISC124, WINTER TERM, 2011 FINAL EXAMINATION 7pm to 10pm, 26 APRIL 2011, Ross Gym Instructor: Alan McLeod If the instructor

More information

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering

PESIT Bangalore South Campus Hosur road, 1km before Electronic City, Bengaluru -100 Department of Information Science and Engineering INTERNAL ASSESSMENT TEST 2 Date : 28-09-15 Max Marks :50 Subject & Code : JAVA&J2EE(10IS753) Section: VII A&B Name of faculty : Mr.Sreenath M V Time : 11.30-1.00 PM Note: Answer any five questions 1) a)

More information

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13

CONTENTS. Chapter 1 Getting Started with Java SE 6 1. Chapter 2 Exploring Variables, Data Types, Operators and Arrays 13 CONTENTS Chapter 1 Getting Started with Java SE 6 1 Introduction of Java SE 6... 3 Desktop Improvements... 3 Core Improvements... 4 Getting and Installing Java... 5 A Simple Java Program... 10 Compiling

More information

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a

An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a CBOP3203 An applet is a program written in the Java programming language that can be included in an HTML page, much in the same way an image is included in a page. When you use a Java technology-enabled

More information

Java Applet Basics. Life cycle of an applet:

Java Applet Basics. Life cycle of an applet: Java Applet Basics Applet is a Java program that can be embedded into a web page. It runs inside the web browser and works at client side. Applet is embedded in a HTML page using the APPLET or OBJECT tag

More information

Java Applet & its life Cycle. By Iqtidar Ali

Java Applet & its life Cycle. By Iqtidar Ali Java Applet & its life Cycle By Iqtidar Ali Java Applet Basic An applet is a java program that runs in a Web browser. An applet can be said as a fully functional java application. When browsing the Web,

More information

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts

SE1021 Exam 2. When returning your exam, place your note-sheet on top. Page 1: This cover. Page 2 (Multiple choice): 10pts SE1021 Exam 2 Name: You may use a note-sheet for this exam. But all answers should be your own, not from slides or text. Review all questions before you get started. The exam is printed single-sided. Write

More information

Contents Chapter 1 Introduction to Programming and the Java Language

Contents Chapter 1 Introduction to Programming and the Java Language Chapter 1 Introduction to Programming and the Java Language 1.1 Basic Computer Concepts 5 1.1.1 Hardware 5 1.1.2 Operating Systems 8 1.1.3 Application Software 9 1.1.4 Computer Networks and the Internet

More information

Midterm assessment - MAKEUP Fall 2010

Midterm assessment - MAKEUP Fall 2010 M257 MTA Faculty of Computer Studies Information Technology and Computing Date: /1/2011 Duration: 60 minutes 1-Version 1 M 257: Putting Java to Work Midterm assessment - MAKEUP Fall 2010 Student Name:

More information

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling

Handout 14 Graphical User Interface (GUI) with Swing, Event Handling Handout 12 CS603 Object-Oriented Programming Fall 15 Page 1 of 12 Handout 14 Graphical User Interface (GUI) with Swing, Event Handling The Swing library (javax.swing.*) Contains classes that implement

More information

CHAPTER 2. Java Overview

CHAPTER 2. Java Overview Networks and Internet Programming (0907522) CHAPTER 2 Java Overview Instructor: Dr. Khalid A. Darabkh Objectives The objectives of this chapter are: To discuss the classes present in the java.awt package

More information

Swing Programming Example Number 2

Swing Programming Example Number 2 1 Swing Programming Example Number 2 Problem Statement (Part 1 and 2 (H/w- assignment) 2 Demonstrate the use of swing Label, TextField, RadioButton, CheckBox, Listbox,Combo Box, Toggle button,image Icon

More information

First Name: AITI 2004: Exam 2 July 19, 2004

First Name: AITI 2004: Exam 2 July 19, 2004 First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: JSP Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand

More information

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali

GUI and its COmponent Textfield, Button & Label. By Iqtidar Ali GUI and its COmponent Textfield, Button & Label By Iqtidar Ali GUI (Graphical User Interface) GUI is a visual interface to a program. GUI are built from GUI components. A GUI component is an object with

More information

RAIK 183H Examination 2 Solution. November 10, 2014

RAIK 183H Examination 2 Solution. November 10, 2014 RAIK 183H Examination 2 Solution November 10, 2014 Name: NUID: This examination consists of 5 questions and you have 110 minutes to complete the test. Show all steps (including any computations/explanations)

More information

Attempt FOUR questions Marking Scheme Time: 120 mins

Attempt FOUR questions Marking Scheme Time: 120 mins Ahmadu Bello University Department of Computer Science Second Semester Examinations August 2017 COSC212: Object Oriented Programming II Marking Scheme Attempt FOUR questions Marking Scheme Time: 120 mins

More information

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7

PROGRAMMING DESIGN USING JAVA (ITT 303) Unit 7 PROGRAMMING DESIGN USING JAVA (ITT 303) Graphical User Interface Unit 7 Learning Objectives At the end of this unit students should be able to: Build graphical user interfaces Create and manipulate buttons,

More information

CMP-326 Exam 2 Spring 2018 Solutions Question 1. Version 1. Version 2

CMP-326 Exam 2 Spring 2018 Solutions Question 1. Version 1. Version 2 Question 1 30 30 60 60 90 20 20 40 40 60 Question 2 a. b. public Song(String title, String artist, int length, String composer) { this.title = title; this.artist = artist; this.length = length; this.composer

More information

RAIK 183H Examination 2 Solution. November 11, 2013

RAIK 183H Examination 2 Solution. November 11, 2013 RAIK 183H Examination 2 Solution November 11, 2013 Name: NUID: This examination consists of 5 questions and you have 110 minutes to complete the test. Show all steps (including any computations/explanations)

More information

MODEL UPDATES MANIPULATES USER

MODEL UPDATES MANIPULATES USER 1) What do you mean by MVC architecture? Explain its role in modern applications and list its advantages(may-2013,jan-2013,nov-2011). In addition to dividing the application into three kinds of components,

More information

MIT AITI Swing Event Model Lecture 17

MIT AITI Swing Event Model Lecture 17 MIT AITI 2004 Swing Event Model Lecture 17 The Java Event Model In the last lecture, we learned how to construct a GUI to present information to the user. But how do GUIs interact with users? How do applications

More information

An array is a type of variable that is able to hold more than one piece of information under a single variable name.

An array is a type of variable that is able to hold more than one piece of information under a single variable name. Arrays An array is a type of variable that is able to hold more than one piece of information under a single variable name. Basically you are sub-dividing a memory box into many numbered slots that can

More information

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1 Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1 Introducing Object Oriented Programming... 2 Explaining OOP concepts... 2 Objects...3

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1

Datenbank-Praktikum. Universität zu Lübeck Sommersemester 2006 Lecture: Swing. Ho Ngoc Duc 1 Datenbank-Praktikum Universität zu Lübeck Sommersemester 2006 Lecture: Swing Ho Ngoc Duc 1 Learning objectives GUI applications Font, Color, Image Running Applets as applications Swing Components q q Text

More information

MYcsvtu Notes. Java Programming Lab Manual

MYcsvtu Notes. Java Programming Lab Manual Java Programming Lab Manual LIST OF EXPERIMENTS 1. Write a Program to add two numbers using Command Line Arguments. 2. Write a Program to find the factorial of a given number using while statement. 3.

More information

J.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination.

J.73 J.74 THE I/O PACKAGE. Java I/O is defined in terms of streams. Streams are ordered sequences of data that have a source and a destination. THE I/O PACKAGE Java I/O is defined in terms of streams. J.73 import java.io.*; class Translate { public static void main(string[] args) { InputStream in = System.in; OutputStream out = System.out; J.74

More information

Introduction to the JAVA UI classes Advanced HCI IAT351

Introduction to the JAVA UI classes Advanced HCI IAT351 Introduction to the JAVA UI classes Advanced HCI IAT351 Week 3 Lecture 1 17.09.2012 Lyn Bartram lyn@sfu.ca About JFC and Swing JFC Java TM Foundation Classes Encompass a group of features for constructing

More information

Lecture 3: Java Graphics & Events

Lecture 3: Java Graphics & Events Lecture 3: Java Graphics & Events CS 62 Fall 2017 Kim Bruce & Alexandra Papoutsaki Text Input Scanner class Constructor: myscanner = new Scanner(System.in); can use file instead of System.in new Scanner(new

More information

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread

G51PGP Programming Paradigms. Lecture 008 Inner classes, anonymous classes, Swing worker thread G51PGP Programming Paradigms Lecture 008 Inner classes, anonymous classes, Swing worker thread 1 Reminder subtype polymorphism public class TestAnimals public static void main(string[] args) Animal[] animals

More information

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { }

What Is an Event? Some event handler. ActionEvent. actionperformed(actionevent e) { } CBOP3203 What Is an Event? Events Objects that describe what happened Event Sources The generator of an event Event Handlers A method that receives an event object, deciphers it, and processes the user

More information

CSIS 10A Assignment 7 SOLUTIONS

CSIS 10A Assignment 7 SOLUTIONS CSIS 10A Assignment 7 SOLUTIONS Read: Chapter 7 Choose and complete any 10 points from the problems below, which are all included in the download file on the website. Use BlueJ to complete the assignment,

More information

Practical 1 Date : Statement: Write a program to find a factorial of given number by user. Program:

Practical 1 Date : Statement: Write a program to find a factorial of given number by user. Program: Practical 1 Date : Statement: Write a program to find a factorial of given number by user. Program: class Pract1 public static void main(string s[]) int n,a1; n=integer.parseint(s[0]); A a = new A(); a1

More information

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver

Building a GUI in Java with Swing. CITS1001 extension notes Rachel Cardell-Oliver Building a GUI in Java with Swing CITS1001 extension notes Rachel Cardell-Oliver Lecture Outline 1. Swing components 2. Building a GUI 3. Animating the GUI 2 Swing A collection of classes of GUI components

More information

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing

Introduction to Graphical Interface Programming in Java. Introduction to AWT and Swing Introduction to Graphical Interface Programming in Java Introduction to AWT and Swing GUI versus Graphics Programming Graphical User Interface (GUI) Graphics Programming Purpose is to display info and

More information

Window Interfaces Using Swing Objects

Window Interfaces Using Swing Objects Chapter 12 Window Interfaces Using Swing Objects Event-Driven Programming and GUIs Swing Basics and a Simple Demo Program Layout Managers Buttons and Action Listeners Container Classes Text I/O for GUIs

More information

FirstSwingFrame.java Page 1 of 1

FirstSwingFrame.java Page 1 of 1 FirstSwingFrame.java Page 1 of 1 2: * A first example of using Swing. A JFrame is created with 3: * a label and buttons (which don t yet respond to events). 4: * 5: * @author Andrew Vardy 6: */ 7: import

More information

Information Technology for Industrial Engineers 15 November ISE 582: Information Technology for Industrial Engineers

Information Technology for Industrial Engineers 15 November ISE 582: Information Technology for Industrial Engineers ISE 582: Information Technology for Industrial Engineers University of Southern California Department of Industrial and Systems Engineering Lecture 10 JAVA Cup 9: Images, Interactive Forms Handouts & Announcements

More information

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal

EXCEPTIONS & GUI. Errors are signals that things are beyond help. Review Session for. -Ankur Agarwal Review Session for EXCEPTIONS & GUI -Ankur Agarwal An Exception is an event, which occurs during the execution of a program, that disrupts the normal flow of the program's instructions. Errors are signals

More information

Part 3: Graphical User Interface (GUI) & Java Applets

Part 3: Graphical User Interface (GUI) & Java Applets 1,QWURGXFWLRQWR-DYD3URJUDPPLQJ (( Part 3: Graphical User Interface (GUI) & Java Applets EE905-GUI 7RSLFV Creating a Window Panels Event Handling Swing GUI Components ƒ Layout Management ƒ Text Field ƒ

More information

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT

CSE 143. Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT CSE 143 Event-driven Programming and Graphical User Interfaces (GUIs) with Swing/AWT slides created by Marty Stepp based on materials by M. Ernst, S. Reges, D. Notkin, R. Mercer, Wikipedia http://www.cs.washington.edu/331/

More information

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage)

+! Today. Lecture 3: ArrayList & Standard Java Graphics 1/26/14! n Reading. n Objectives. n Reminders. n Standard Java Graphics (on course webpage) +! Lecture 3: ArrayList & Standard Java Graphics +! Today n Reading n Standard Java Graphics (on course webpage) n Objectives n Review for this week s lab and homework assignment n Miscellanea (Random,

More information

protected void printserial() { System.out.println("> NO." + this.serialno); this.serialno++; }

protected void printserial() { System.out.println(> NO. + this.serialno); this.serialno++; } NumberedTicketGenerator.java package j2.exam.ex01; public abstract class NumberedTicketGenerator { protected int serialno; public NumberedTicketGenerator() { super(); this.serialno = 1000; public void

More information

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in

Lab 4. D0010E Object-Oriented Programming and Design. Today s lecture. GUI programming in Lab 4 D0010E Object-Oriented Programming and Design Lecture 9 Lab 4: You will implement a game that can be played over the Internet. The networking part has already been written. Among other things, the

More information

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam

Name Section. CS 21a Introduction to Computing I 1 st Semester Final Exam CS a Introduction to Computing I st Semester 00-00 Final Exam Write your name on each sheet. I. Multiple Choice. Encircle the letter of the best answer. ( points each) Answer questions and based on the

More information

First Name: AITI 2004: Exam 2 July 19, 2004

First Name: AITI 2004: Exam 2 July 19, 2004 First Name: AITI 2004: Exam 2 July 19, 2004 Last Name: Standard Track Read Instructions Carefully! This is a 3 hour closed book exam. No calculators are allowed. Please write clearly if we cannot understand

More information

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011

GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI DYNAMICS Lecture July 26 CS2110 Summer 2011 GUI Statics and GUI Dynamics 2 Statics: what s drawn on the screen Components buttons, labels, lists, sliders, menus,... Containers: components that contain

More information

PART1: Choose the correct answer and write it on the answer sheet:

PART1: Choose the correct answer and write it on the answer sheet: PART1: Choose the correct answer and write it on the answer sheet: (15 marks 20 minutes) 1. Which of the following is included in Java SDK? a. Java interpreter c. Java disassembler b. Java debugger d.

More information

Advanced Java Unit 6: Review of Graphics and Events

Advanced Java Unit 6: Review of Graphics and Events Advanced Java Unit 6: Review of Graphics and Events This is a review of the basics of writing a java program that has a graphical interface. To keep things simple, all of the graphics programs will follow

More information

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI

Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI CBOP3203 Graphical User Interface (GUI) components in Java Applets. With Abstract Window Toolkit (AWT) we can build an applet that has the basic GUI components like button, text input, scroll bar and others.

More information

Gracefulness of TP-Tree with Five Levels Obtained by Java Programming

Gracefulness of TP-Tree with Five Levels Obtained by Java Programming International Journal of Scientific and Research Publications, Volume 2, Issue 12, December 2012 1 Gracefulness of TP-Tree with Five Levels Obtained by Java Programming A.Solairaju 1, N. Abdul Ali 2 and

More information

L4,5: Java Overview II

L4,5: Java Overview II L4,5: Java Overview II 1. METHODS Methods are defined within classes. Every method has an associated class; in other words, methods are defined only within classes, not standalone. Methods are usually

More information

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written.

Proctors are unable to respond to queries about the interpretation of exam questions. Do your best to answer exam questions as written. QUEEN'S UNIVERSITY SCHOOL OF COMPUTING HAND IN Answers Are Recorded on Question Paper CISC124, FALL TERM, 2013 FINAL EXAMINATION 7pm to 10pm, 18 DECEMBER 2013 Instructor: Alan McLeod If the instructor

More information

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday!

Lab & Assignment 1. Lecture 3: ArrayList & Standard Java Graphics. Random Number Generator. Read Lab & Assignment Before Lab Wednesday! Lab & Assignment 1 Lecture 3: ArrayList & Standard Java Graphics CS 62 Fall 2015 Kim Bruce & Michael Bannister Strip with 12 squares & 5 silver dollars placed randomly on the board. Move silver dollars

More information

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below.

Question 1. Show the steps that are involved in sorting the string SORTME using the quicksort algorithm given below. Name: 1.124 Quiz 2 Thursday November 9, 2000 Time: 1 hour 20 minutes Answer all questions. All questions carry equal marks. Question 1. Show the steps that are involved in sorting the string SORTME using

More information

Final Examination Semester 3 / Year 2008

Final Examination Semester 3 / Year 2008 Southern College Kolej Selatan 南方学院 Final Examination Semester 3 / Year 2008 COURSE : JAVA PROGRAMMING COURSE CODE : PROG1114 TIME : 2 1/2 HOURS DEPARTMENT : COMPUTER SCIENCE CLASS : CS08-A + CS08-B LECTURER

More information

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons

CompSci 125 Lecture 17. GUI: Graphics, Check Boxes, Radio Buttons CompSci 125 Lecture 17 GUI: Graphics, Check Boxes, Radio Buttons Announcements GUI Review Review: Inheritance Subclass is a Parent class Includes parent s features May Extend May Modify extends! Parent

More information

B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Lab Programs

B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Lab Programs B.Sc (Computer Science) Object Oriented Programming with Java and Data Structures Lab Programs 1 1. Write a java program to determine the sum of the following harmonic series for a given value of n. 1+1/2+1/3+...

More information

Applet. 1. init (): called once by the applet containers when an applet is loaded for execution.

Applet. 1. init (): called once by the applet containers when an applet is loaded for execution. )*(applet classes from class JApplet. Applet Applet : are Java programs that are typically embedded in HTML (Extensible Hyper- Text Markup Language) documents. 2.Life cycle method : 1-init () 2-start ()

More information

JAVA. A. Zakiuddin Ahmed. M.Sc.,M.Phil M.S.(Edn), PGDCSM, Professor in Computer Science, P. Rizwan Ahmed. MCA., M.Sc.,M.A., M.Phil.

JAVA. A. Zakiuddin Ahmed. M.Sc.,M.Phil M.S.(Edn), PGDCSM, Professor in Computer Science, P. Rizwan Ahmed. MCA., M.Sc.,M.A., M.Phil. 635 635 JAVA PROGRAMMING A. Zakiuddin Ahmed M.Sc.,M.Phil M.S.(Edn), PGDCSM, Professor in Computer Science, Mazharul Uloom College, Ambur - Vellore Dist, Tamil Nadu. 802 P. Rizwan Ahmed MCA., M.Sc.,M.A.,

More information

2IS45 Programming

2IS45 Programming Course Website Assignment Goals 2IS45 Programming http://www.win.tue.nl/~wsinswan/programmeren_2is45/ Rectangles Learn to use existing Abstract Data Types based on their contract (class Rectangle in Rectangle.

More information

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is

Method Of Key Event Key Listener must implement three methods, keypressed(), keyreleased() & keytyped(). 1) keypressed() : will run whenever a key is INDEX Event Handling. Key Event. Methods Of Key Event. Example Of Key Event. Mouse Event. Method Of Mouse Event. Mouse Motion Listener. Example of Mouse Event. Event Handling One of the key concept in

More information

Unit 7: Event driven programming

Unit 7: Event driven programming Faculty of Computer Science Programming Language 2 Object oriented design using JAVA Dr. Ayman Ezzat Email: ayman@fcih.net Web: www.fcih.net/ayman Unit 7: Event driven programming 1 1. Introduction 2.

More information