NRI INSTITUTE OF TECHNOLOGY

Size: px
Start display at page:

Download "NRI INSTITUTE OF TECHNOLOGY"

Transcription

1 NRI INSTITUTE OF TECHNOLOGY KOTHUR, NEAR GUDUR GATE, HYDERABAD, A.P Java Programming Lab Manual B. Tech, CSE, II Year II Sem DEPARTMENT OF COMPUTER SCIENCE &ENGINEERING

2 DEPARTMENT OF COMPUTER SCIENCE &ENGINEERING CERTIFICATE This is to certify that this is a bonafide work in Java Programming Lab Labaratory had done by Mr/Ms bearing of Roll No in the department of CSE of NRI Institute Of Technilogy during the II sem of B.tech IInd year for the academic year Number of Experiments Conducted:.. Number of experiments Attended:. Lab Incharge Head Of The Department External 2

3 INDEX S. No Contents Page. no s

4 1.program Use Eclipse or Netbean platform and acquaint with the various menus create the test project add a test class and run it see how you can use auto suggestions auto fill try the code formatter and code refactoring like renaming variables methods and classes. Try debug step by step one if else condition and a for loop. import javax.swing.*; import java.awt.graphics; /* <html> <body> <applet code="choice.class" width=500 height=500> </applet> </body> </html> */ public class choice extends JApplet int i,ch; public void init() String input; input=joptionpane.showinputdialog ("enter your choice( 1-lines,2-rectangles,3-ovals)"); ch=integer.parseint(input); public void paint(graphics g) switch(ch) case 1: for(i=1;i<=10;i++) g.drawline(10,10,250,10*i); break; case 2: for(i=1;i<=10;i++) g.drawrect(10*i,10*i,50+10*i,50+10*i); 4

5 break; case 3: for(i=1;i<=10;i++) g.drawoval(10*i,10*i,50+10*i,50+10*i); break; 5

6 2) program Write a java program that works as a simple calculator.use a grid layout to arrage buttons for the digits and for the +,-,*,% operations add a text field to display the result.handle any possible exceptions like divided by zero. import java.awt.*; import java.awt.event.*; import java.applet.*; /* <applet code="cal" width=300 height=300> </applet> */ public class Cal extends Applet implements ActionListener String msg=" "; int v1,v2,result; TextField t1; Button b[]=new Button[10]; Button add,sub,mul,div,clear,mod,eq; char OP; public void init() Color k=new Color(120,89,90); setbackground(k); t1=new TextField(10); GridLayout gl=new GridLayout(4,5); setlayout(gl); for(int i=0;i<10;i++) b[i]=new Button(""+i); add=new Button("add"); sub=new Button("sub"); mul=new Button("mul"); div=new Button("div"); mod=new Button("mod"); clear=new Button("clear"); EQ=new Button("EQ"); 6

7 t1.addactionlistener(this); add(t1); for(int i=0;i<10;i++) add(b[i]); add(add); add(sub); add(mul); add(div); add(mod); add(clear); add(eq); for(int i=0;i<10;i++) b[i].addactionlistener(this); add.addactionlistener(this); sub.addactionlistener(this); mul.addactionlistener(this); div.addactionlistener(this); mod.addactionlistener(this); clear.addactionlistener(this); EQ.addActionListener(this); public void actionperformed(actionevent ae) String str=ae.getactioncommand(); char ch=str.charat(0); if ( Character.isDigit(ch)) t1.settext(t1.gettext()+str); else if(str.equals("add")) v1=integer.parseint(t1.gettext()); OP='+'; t1.settext(""); else if(str.equals("sub")) v1=integer.parseint(t1.gettext()); OP='-'; t1.settext(""); 7

8 else if(str.equals("mul")) v1=integer.parseint(t1.gettext()); OP='*'; t1.settext(""); else if(str.equals("div")) v1=integer.parseint(t1.gettext()); OP='/'; t1.settext(""); else if(str.equals("mod")) v1=integer.parseint(t1.gettext()); OP='%'; t1.settext(""); if(str.equals("eq")) v2=integer.parseint(t1.gettext()); if(op=='+') result=v1+v2; else if(op=='-') result=v1-v2; else if(op=='*') result=v1*v2; else if(op=='/') result=v1/v2; else if(op=='%') result=v1%v2; t1.settext(""+result); if(str.equals("clear")) t1.settext("");

9 3A)program Develop an applet in java that display a simple message import java.awt.*; import java.applet.*; /*<applet code="hellojava" width=300 height=50> </applet>*/ public class Hellojava extends Applet public void paint(graphics g) g.drawstring("welcome to Applet",20,20); 9

10 3B) program Develop an applet in java that receives an integer in one text field and computes its factorial value and retuns it in another text field when the button named compute is clicked. /* <applet code="fact.java" width=300 height=100> </applet> */ import java.awt.*; import java.applet.*; import java.awt.event.*; public class Fact extends Applet implements ActionListener int n,f=1; Button compute; TextField t1; String s1,s2; public void init() t1=new TextField(); compute = new Button("compute"); add(t1); add(compute); t1.settext("0"); compute.addactionlistener(this); public void actionperformed(actionevent ae) String s=ae.getactioncommand(); if(s.equals("compute")) s1=t1.gettext(); n=integer.parseint(s1); while(n!=0) f*=n; n--; s2=string.valueof(f); 10

11 public void paint(graphics g) g.drawstring("factorial:"+s2,6,50); )program Write a java program that creats a user interface to perform integer division. import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet code="div"width=230 height=250> </applet>*/ public class Div extends Applet implements ActionListener String msg; TextField num1,num2,res;label l1,l2,l3; Button div; public void init() l1=new Label("Number 1"); l2=new Label("Number 2"); l3=new Label("result"); num1=new TextField(10); num2=new TextField(10); res=new TextField(10); div=new Button("DIV"); div.addactionlistener(this); add(l1); add(num1); add(l2); add(num2); add(l3); add(res); add(div); public void actionperformed(actionevent ae) 11

12 String arg=ae.getactioncommand(); if(arg.equals("div")) String s1=num1.gettext(); String s2=num2.gettext(); int num1=integer.parseint(s1); int num2=integer.parseint(s2); if(num2==0) try System.out.println(" "); catch(exception e) System.out.println("ArithematicException"+e); msg="arithemetic"; else if((num1<0) (num2<0)) try System.out.println(""); catch(exception e) System.out.println("NumberFormat"+e); msg="numberformat"; else int num3=num1/num2; res.settext(string.valueof(num3)); public void paint(graphics g) g.drawstring(msg,30,70); 12

13 ) program Write a java program that implement 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. class A extends Thread synchronized public void run() try while(true) sleep(1000); System.out.println("good morning"); catch(exception e) class B extends Thread synchronized public void run() try while(true) sleep(2000); System.out.println("hello"); catch(exception e) 13

14 class C extends Thread synchronized public void run() try while(true) sleep(3000); System.out.println("welcome"); catch(exception e) class ThreadDemo public static void main(string args[]) A t1=new A(); B t2=new B(); C t3=new C(); t1.start(); t2.start(); t3.start();

15 7) program Write a java program that simulates a traffic light.the program lets the user select one of three lights:red,yellow,green with radio buttons. import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet code="signal" width=300 height=100> </applet>*/ public class Signal extends Applet implements ItemListener Checkbox red,yellow,green; Light light; public void init() Panel p1=new Panel(); p1.setsize(200,200); p1.setlayout(new FlowLayout()); p1.add(light=new Light()); light.setsize(40,90); Panel p2=new Panel(); p2.setlayout(new FlowLayout()); CheckboxGroup g=new CheckboxGroup(); p2.add(red=new Checkbox("red",g,false)); p2.add(yellow=new Checkbox("yellow",g,false)); p2.add(green=new Checkbox("green",g,false)); add("center",p1); add("south",p2); red.additemlistener(this); yellow.additemlistener(this); green.additemlistener(this); public void itemstatechanged(itemevent ie) if(red.getstate()) light.red(); 15

16 if(yellow.getstate()) light.yellow(); if(green.getstate()) light.green(); class Light extends Canvas private boolean red; private boolean yellow; private boolean green; public Light() red=false; yellow=false; green=false; public void red() red=true; yellow=false; green=false; public void yellow() red=false; yellow=true; green=false; public void green() red=false; yellow=false; green=true; public void paint(graphics g) if(red) 16

17 g.setcolor(color.red); g.filloval(10,10,20,20); g.setcolor(color.black); g.drawoval(10,35,20,20); g.drawoval(10,60,20,20); g.drawrect(5,5,30,86); else if(yellow) g.setcolor(color.yellow); g.filloval(10,35,20,20); g.setcolor(color.black); g.drawrect(5,5,30,80); g.drawoval(10,10,20,20); g.drawoval(10,60,20,20); else if(green) g.setcolor(color.green); g.filloval(10,60,20,20); g.setcolor(color.black); g.drawrect(5,5,30,80); g.drawoval(10,10,20,20); g.drawoval(10,35,20,20); else g.setcolor(color.black); g.drawrect(5,5,30,80); g.drawoval(10,10,20,20); g.drawoval(10,35,20,20); g.drawoval(10,60,20,20);

18 8) program Write a java program to creat an abstract class named shape that contains two integrs and an empty method named printarea(). abstract class shape void numberofsides() System.out.println("This is for abstract class"); class Trapezoid extends shape void numberofsides() System.out.println("It is having 4 sides"); class Triangle extends shape void numberofsides() System.out.println("it is having 3 sides"); class Hexagonal extends shape void numberofsides() System.out.println("it is having 6 sides"); class AbstractDemo public static void main(string args[]) Trapezoid tz=new Trapezoid(); Triangle t=new Triangle(); Hexagonal h=new Hexagonal(); 18

19 tz.numberofsides(); t.numberofsides(); h.numberofsides(); ) program Write a java program that handles all mouse events and shows the vent name at the center of the window when a mouse event is fired.(use adapter class) import java.awt.*; import java.awt.event.*; import java.applet.*; /*<applet code="mouseeventdemo " width=300 height=100> </applet> */ public class MouseEventDemo extends Applet implements MouseListener, MouseMotionListener String msg=" "; int mousex=0,mousey=0; public void init() addmouselistener(this); addmousemotionlistener(this); public void mouseclicked(mouseevent me) mousex=0; mousey=10; msg="mouse clicked by me"; public void mouseentered(mouseevent me) mousex=0; mousey=10; msg="mouse entered by me"; 19

20 public void mouseexited(mouseevent me) mousex=0; mousey=10; msg="mouse exited by me"; public void mousepressed(mouseevent me) mousex=me.getx(); mousey=me.gety(); msg="down"; showstatus(msg+"at"+mousex+","+mousey); public void mousereleased(mouseevent me) mousex=me.getx(); mousey=me.gety(); msg="up"; showstatus(msg+"at"+mousex+" "+mousey); public void mousedragged(mouseevent me) mousex=me.getx(); mousey=me.gety(); msg="*"; showstatus("dragging the mouse at"+mousex+","+mousey); public void mousemoved(mouseevent me) msg="mouse moved"; showstatus("mouse moved at"+me.getx()+","+me.gety()); public void paint(graphics g) g.drawstring(msg,mousex,mousey); 20

21 11) program Write a java program that load names and phone numbers from a text file where tha data is organized as one line per record and each field in a record are separated by a tab(\t). import java.awt.*; import javax.swing.*; /* <applet code = "JTableDemo" width = 400 height=200> </applet> */ public class JTableDemo extends JApplet public void init() //Get Content Pane Container contentpane = getcontentpane(); //set layout manger contentpane.setlayout(new BorderLayout()); //Initialize column headings final String[] colheads = "Name", "Phone", "Fax" ; //Initialize data final Object[][] data = "Gail", "4567", "8675", "Keen", "7566", "5555", "Viviane", "5674", "5887", "Anne", "1237", "3333", "John", "5656", "3144", "Ellen", "1134", "5335", "Gail", "4567", "8675", "Keen", "7566", "5555", "Viviane", "5674", "5887", "Anne", "1237", "3333", "John", "5656", "3144", "Ellen", "1134", "5335" ; //Create the table JTable table = new JTable(data, colheads); //Add table to a scroll pane 21

22 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 contentpane.add(jsp, BorderLayout.CENTER); 22

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

DEPARTMENT VISION AND MISSION

DEPARTMENT VISION AND MISSION INSTITUTE VISION AND MISSION Vision To emerge as a destination for higher education by transforming learners into achievers by creating, encouraging and thus building a supportive academic environment.

More information

Java Lab Record By Ramesh Ponnala.java

Java Lab Record By Ramesh Ponnala.java 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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /*1 a) Write a Java program that prints all real solutions to the quadratic

More information

ASSIGNMENT NO 14. Objectives: To learn and demonstrated use of applet and swing components

ASSIGNMENT NO 14. Objectives: To learn and demonstrated use of applet and swing components Create an applet with three text Fields and four buttons add, subtract, multiply and divide. User will enter two values in the Text Fields. When any button is pressed, the corresponding operation is performed

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

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

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

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

JAVA PROGRAMMING LABORATORY MANUAL

JAVA PROGRAMMING LABORATORY MANUAL JAVA PROGRAMMING LABORATORY MANUAL B.TECH (II YEAR II SEM) (2018-19) DEPARTMENT OF INFORMATION TECHNOLOGY MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY (Autonomous Institution UGC, Govt. of India) Recognized

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

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

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

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

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

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

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

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

DEMONSTRATION OF AWT CONTROLS

DEMONSTRATION OF AWT CONTROLS Ex.No: 1(A) DATE: 02.07.11 DEMONSTRATION OF AWT CONTROLS Aim: To write a java program for demonstrating the following AWT controls 1. Button 2.Checkbox 3.Choice 4.List 5.TextField 6.Scrollbar Hardware

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

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

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

Vinayaka Missions University

Vinayaka Missions University Vinayaka Missions University VMKV Engineering College Salem - 636308. Department of Computer Science & Software Engineering [CSSE] LAB MANUAL JAVA PROGRAMMING (V Semester) Prepared by A.RAMESH KUMAR List

More information

JAVA PROGRAMMING LABORATORY MANUAL B.TECH (II YEAR II SEM) ( )

JAVA PROGRAMMING LABORATORY MANUAL B.TECH (II YEAR II SEM) ( ) JAVA PROGRAMMING LABORATORY MANUAL B.TECH (II YEAR II SEM) (2016-17) Department of Computer Science and Engineering MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY (Autonomous Institution UGC, Govt. of

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

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

JAVA PROGRAM EXAMPLE WITH OUTPUT PDF

JAVA PROGRAM EXAMPLE WITH OUTPUT PDF JAVA PROGRAM EXAMPLE WITH OUTPUT PDF Created By: Umar Farooque Khan 1 How to compile and run java programs Compile: - javac JavaFileName Run Java: - java JavaClassName Let s take an example of java program:

More information

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus

Chapter 13 Lab Advanced GUI Applications Lab Objectives. Introduction. Task #1 Creating a Menu with Submenus Chapter 13 Lab Advanced GUI Applications Lab Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the user the option of when they will be seen.

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

Introduction. Introduction

Introduction. Introduction Introduction Many Java application use a graphical user interface or GUI (pronounced gooey ). A GUI is a graphical window or windows that provide interaction with the user. GUI s accept input from: the

More information

1 Definitions & Short Answer (5 Points Each)

1 Definitions & Short Answer (5 Points Each) Fall 2013 Final Exam COSC 117 Name: Write all of your responses on these exam pages. If you need more space please use the backs. Make sure that you show all of your work, answers without supporting work

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 PROGRAMMIMG LABORATORY MANUAL

JAVA PROGRAMMIMG LABORATORY MANUAL JAVA PROGRAMMIMG LABORATORY MANUAL B.TECH (II YEAR II SEM) (2017-18) DEPARTMENT OF INFORMATION TECHNOLOGY MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY (Autonomous Institution UGC, Govt. of India) Recognized

More information

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI

(listener)... MouseListener, ActionLister. (adapter)... MouseAdapter, ActionAdapter. java.awt AWT Abstract Window Toolkit GUI 51 6!! GUI(Graphical User Interface) java.awt javax.swing (component) GUI... (container) (listener)... MouseListener, ActionLister (adapter)... MouseAdapter, ActionAdapter 6.1 GUI(Graphics User Interface

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

Programmierpraktikum

Programmierpraktikum Programmierpraktikum Claudius Gros, SS2012 Institut für theoretische Physik Goethe-University Frankfurt a.m. 1 of 18 17/01/13 11:46 Java Applets 2 of 18 17/01/13 11:46 Java applets embedding Java applications

More information

CSC 1214: Object-Oriented Programming

CSC 1214: Object-Oriented Programming CSC 1214: Object-Oriented Programming J. Kizito Makerere University e-mail: jkizito@cis.mak.ac.ug www: http://serval.ug/~jona materials: http://serval.ug/~jona/materials/csc1214 e-learning environment:

More information

Applet which displays a simulated trackball in the upper half of its window.

Applet which displays a simulated trackball in the upper half of its window. Example: Applet which displays a simulated trackball in the upper half of its window. By dragging the trackball using the mouse, you change its state, given by its x-y position relative to the window boundaries,

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

Windows and Events. created originally by Brian Bailey

Windows and Events. created originally by Brian Bailey Windows and Events created originally by Brian Bailey Announcements Review next time Midterm next Friday UI Architecture Applications UI Builders and Runtimes Frameworks Toolkits Windowing System Operating

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

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

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

CS2110. GUIS: Listening to Events

CS2110. GUIS: Listening to Events CS2110. GUIS: Listening to Events Also anonymous classes Download the demo zip file from course website and look at the demos of GUI things: sliders, scroll bars, combobox listener, etc 1 mainbox boardbox

More information

JAVA PROGRAMMING LABORATORY MANUAL. B.TECH (R-17 Regulation) (II YEAR II SEM) ( ) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

JAVA PROGRAMMING LABORATORY MANUAL. B.TECH (R-17 Regulation) (II YEAR II SEM) ( ) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING JAVA PROGRAMMING LABORATORY MANUAL B.TECH (R-17 Regulation) (II YEAR II SEM) (2018-19) DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY (Autonomous Institution

More information

BM214E Object Oriented Programming Lecture 13

BM214E Object Oriented Programming Lecture 13 BM214E Object Oriented Programming Lecture 13 Events To understand how events work in Java, we have to look closely at how we use GUIs. When you interact with a GUI, there are many events taking place

More information

CONTENTS S.No Topic Page. No

CONTENTS S.No Topic Page. No CONTENTS S.No Topic Page. No 1. Syllabus 3 2. Required Work 5 3. Course Objectives 6 4. Course Outcomes 6 5. Course Assessment 7 6. Program Outcomes 8 7. Program Objective / Outcome Matrix 9 8. Programs

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

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

ISO-2022-JP (JIS ) 1 2. (Windows95/98 MacOS ) Java UNICODE UNICODE. Java. .java.java.txt native2ascii. .java

ISO-2022-JP (JIS ) 1 2. (Windows95/98 MacOS ) Java UNICODE UNICODE. Java. .java.java.txt native2ascii. .java 2000 8 2000.1.24-27 0 4 1 ( (1 8 ) ASCII 1 8 1 1 8 2 ISO-2022-JP (JIS ) 1 2 EUC ( EUC) 8 Unix SJIS (MS ) EUC 8 ( (Windows95/98 MacOS Java UNICODE UNICODE ( Java.java.java.txt native2ascii.java native2ascii

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

Advanced Java Programming

Advanced Java Programming Advanced Java Programming Shmulik London Lecture #5 GUI Programming Part I AWT & Basics Advanced Java Programming / Shmulik London 2006 Interdisciplinary Center Herzeliza Israel 1 Agenda AWT & Swing AWT

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

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

) / Java ( )

) / Java ( ) 2002 3 2003.1.29 1 3 ( ) ( ) / Java ( ) 1 ( )? ( ) 2 (3 ) 3 Java Java Java (dynamic dispatch) ( ) import java.awt.*; import java.awt.event.*; public class Sample30 extends Frame { boolean go; double time;

More information

NITI NITI I PRIORITET

NITI NITI I PRIORITET NITI public class ThreadsTest { public static void main(string args[]) { BytePrinter bp1 = new BytePrinter(); BytePrinter bp2 = new BytePrinter(); BytePrinter bp3 = new BytePrinter(); bp1.start(); bp2.start();

More information

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each

CS 120 Fall 2008 Practice Final Exam v1.0m. Name: Model Solution. True/False Section, 20 points: 10 true/false, 2 points each CS 120 Fall 2008 Practice Final Exam v1.0m Name: Model Solution True/False Section, 20 points: 10 true/false, 2 points each Multiple Choice Section, 32 points: 8 multiple choice, 4 points each Code Tracing

More information

RobotPlanning.java Page 1

RobotPlanning.java Page 1 RobotPlanning.java Page 1 import java.awt.*; import java.awt.event.*; import java.awt.image.*; import javax.swing.*; import javax.swing.border.*; import java.util.*; * * RobotPlanning - 1030 GUI Demonstration.

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

Chapter 13 Lab Advanced GUI Applications

Chapter 13 Lab Advanced GUI Applications Gaddis_516907_Java 4/10/07 2:10 PM Page 113 Chapter 13 Lab Advanced GUI Applications Objectives Be able to add a menu to the menu bar Be able to use nested menus Be able to add scroll bars, giving the

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

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

CSIS 10A Assignment 14 SOLUTIONS

CSIS 10A Assignment 14 SOLUTIONS CSIS 10A Assignment 14 SOLUTIONS Read: Chapter 14 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

Building Java Programs

Building Java Programs Building Java Programs Supplement 3G: Graphics 1 drawing 2D graphics Chapter outline DrawingPanel and Graphics objects drawing and filling shapes coordinate system colors drawing with loops drawing with

More information

THE UNIVERSITY OF AUCKLAND

THE UNIVERSITY OF AUCKLAND CompSci 101 with answers THE UNIVERSITY OF AUCKLAND FIRST SEMESTER, 2012 Campus: City COMPUTER SCIENCE Principles of Programming (Time Allowed: TWO hours) NOTE: You must answer all questions in this test.

More information

CSIS 10A Practice Final Exam Solutions

CSIS 10A Practice Final Exam Solutions CSIS 10A Practice Final Exam Solutions 1) (5 points) What would be the output when the following code block executes? int a=3, b=8, c=2; if (a < b && b < c) b = b + 2; if ( b > 5 a < 3) a = a 1; if ( c!=

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

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

/* Write a Program implementing GUI based Calculator using Swing */

/* Write a Program implementing GUI based Calculator using Swing */ /* Write a Program implementing GUI based Calculator using Swing */ import java.awt.event.actionevent; import java.awt.event.actionlistener; import javax.swing.*; public class Calculator extends JFrame

More information

Maharashtra State Board of Technical Education

Maharashtra State Board of Technical Education Maharashtra State Board of Technical Education (Autonomous) (ISO 9001:2008) (ISO/IEC 27001:2005) Welcome M2001 [117.239.186.68] My Home Log Out e-exam Manage Questions for Advanced Java Programming (17625)

More information

News! Feedback after Lecture 4! About Java and OOP!

News! Feedback after Lecture 4! About Java and OOP! this Example: SignalGUI News Orphans Recursive References D0010E Object-Oriented Programming and Design Lecture 5 GUI Design Patterns Applets Model-View- Control Observer Hints for Lab 2 Use a Vector to

More information

The first version of the bank will look like this:

The first version of the bank will look like this: Lecture 16 The Bank The first version of the bank will look like this: The user will be able to make a deposit, and the result will be reflected in several fields. In addition if the user makes a second

More information

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet

Module 5 Applets About Applets Hierarchy of Applet Life Cycle of an Applet About Applets Module 5 Applets An applet is a little application. Prior to the World Wide Web, the built-in writing and drawing programs that came with Windows were sometimes called "applets." On the Web,

More information

CS 2113 Software Engineering

CS 2113 Software Engineering CS 2113 Software Engineering Java 5 - GUIs Import the code to intellij https://github.com/cs2113f18/template-j-5.git Professor Tim Wood - The George Washington University Class Hierarchies Abstract Classes

More information

Garfield AP CS. Graphics

Garfield AP CS. Graphics Garfield AP CS Graphics Assignment 3 Working in pairs Conditions: I set pairs, you have to show me a design before you code You have until tomorrow morning to tell me if you want to work alone Cumulative

More information

The AWT Event Model 9

The AWT Event Model 9 The AWT Event Model 9 Course Map This module covers the event-based GUI user input mechanism. Getting Started The Java Programming Language Basics Identifiers, Keywords, and Types Expressions and Flow

More information

EE219 - Semester /2009 Solutions Page 1 of 10

EE219 - Semester /2009 Solutions Page 1 of 10 EE219 Object Oriented Programming I (2008/2009) SEMESTER 1 SOLUTIONS Q1(a) Corrected code is: 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36

More information

Using Graphics. Building Java Programs Supplement 3G

Using Graphics. Building Java Programs Supplement 3G Using Graphics Building Java Programs Supplement 3G Introduction So far, you have learned how to: output to the console break classes/programs into static methods store and use data with variables write

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

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

Chapter 14: Applets and More

Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

More information

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More

8/23/2014. Chapter Topics. Introduction to Applets. Introduction to Applets. Introduction to Applets. Applet Limitations. Chapter 14: Applets and More Chapter 14: Applets and More Starting Out with Java: From Control Structures through Objects Fifth Edition by Tony Gaddis Chapter Topics Chapter 14 discusses the following main topics: Introduction to

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

Java Coordinate System

Java Coordinate System Java Graphics Drawing shapes in Java such as lines, rectangles, 3-D rectangles, a bar chart, or a clock utilize the Graphics class Drawing Strings Drawing Lines Drawing Rectangles Drawing Ovals Drawing

More information

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015

Higher National Diploma in Information Technology First Year, Second Semester Examination 2015 [All Rights Reserved] SLIATE SRI LANKA INSTITUTE OF ADVANCED TECHNOLOGICAL EDUCATION (Established in the Ministry of Higher Education, vide in Act No. 29 of 1995) Higher National Diploma in Information

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

Chapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1

Chapter 13. Applets and HTML. HTML Applets. Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Chapter 13 Applets and HTML HTML Applets Chapter 13 Java: an Introduction to Computer Science & Programming - Walter Savitch 1 Overview Applets: Java programs designed to run from a document on the Internet

More information

: 15. (x, y) (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1)

: 15. (x, y) (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1) 73 12 12.1 15 15 ( 12.1.1) 16 15 15 12.1.1: 15 15 (x, y) x y 0 3 0 0 (x, y ) (x, y) ( x x = 1 y = y ) (x = x y y = 1) (12.1.1) 74 12 Program 12.1.1 Piace.java import java.awt.*; public class Piece { private

More information

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn

Java & Graphical User Interface II. Wang Yang wyang AT njnet.edu.cn Java & Graphical User Interface II Wang Yang wyang AT njnet.edu.cn Outline Review of GUI (first part) What is Event Basic Elements of Event Programming Secret Weapon - Inner Class Full version of Event

More information

Day before tests of Java Final test. IDM institution of Bandarawela. Project for department of education

Day before tests of Java Final test. IDM institution of Bandarawela. Project for department of education Day before tests of Java Final test. IDM institution of Bandarawela Project for department of education import javax.swing.*; import java.awt.*; import java.awt.event.*; public class Doenets extends JApplet

More information

Introduction to Computer Science I

Introduction to Computer Science I Introduction to Computer Science I Graphics Janyl Jumadinova 7 February, 2018 Graphics Graphics can be simple or complex, but they are just data like a text document or sound. Java is pretty good at graphics,

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

Exp 6: Develop Java programs to implement Interfaces and Packages. Apply Exception handling and implement multithreaded programs.

Exp 6: Develop Java programs to implement Interfaces and Packages. Apply Exception handling and implement multithreaded programs. CO504.3 CO504.4 Develop Java programs to implement Interfaces and Packages. Apply Exception handling and implement multithreaded programs. CO504.5 CO504.6 Implement Graphics programs using Applet. Develop

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

Java Applets / Flash

Java Applets / Flash Java Applets / Flash Java Applet vs. Flash political problems with Microsoft highly portable more difficult development not a problem less so excellent visual development tool Applet / Flash good for:

More information

Handling Mouse and Keyboard Events

Handling Mouse and Keyboard Events Handling Mouse and Keyboard Events 605.481 1 Java Event Delegation Model EventListener handleevent(eventobject handleevent(eventobject e); e); EventListenerObject source.addlistener(this);

More information

Programming Mobile Devices J2SE GUI

Programming Mobile Devices J2SE GUI Programming Mobile Devices J2SE GUI University of Innsbruck WS 2009/2010 thomas.strang@sti2.at Graphical User Interface (GUI) Why is there more than one Java GUI toolkit? AWT write once, test everywhere

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

OBJECT ORIENTED PROGRAMMING. Java GUI part 1 Loredana STANCIU Room B616

OBJECT ORIENTED PROGRAMMING. Java GUI part 1 Loredana STANCIU Room B616 OBJECT ORIENTED PROGRAMMING Java GUI part 1 Loredana STANCIU loredana.stanciu@upt.ro Room B616 What is a user interface That part of a program that interacts with the user of the program: simple command-line

More information

Final Examination Semester 2 / Year 2011

Final Examination Semester 2 / Year 2011 Southern College Kolej Selatan 南方学院 Final Examination Semester 2 / Year 2011 COURSE COURSE CODE TIME DEPARTMENT LECTURER : JAVA PROGRAMMING : PROG1114 : 2 1/2 HOURS : COMPUTER SCIENCE : LIM PEI GEOK Student

More information

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application

Unit 1- Java Applets. Applet Programming. Local Applet and Remote Applet ** Applet and Application Applet Programming Applets are small Java applications that can be accessed on an Internet server, transported over Internet, and can be automatically installed and run as a part of a web document. An

More information