To delete a record from a database table using java swing application
Packages used:
1. javax.swing.* :
Provides a set of "lightweight" (all-Java language) components that,
to the maximum degree possible, work the same on all platforms.
2. java.awt.* :
Contains all of the classes for creating user interfaces and for painting
graphics and images.
3.
java.awt.event.* : Provides interfaces and
classes for dealing with different
types of events fired by AWT components
4.
java.sql.* : Provides the
API for accessing and processing data stored in a data source (usually a
relational database) using the Java programming language.
Classes
used:
·
JFrame : An extended version of
java.awt.Frame
that adds support for the JFC/Swing component architecture.
·
Container : A generic Abstract Window Toolkit(AWT)
container object is a component that can contain other AWT components.
Components added to a container are tracked in a list
·
JLabel : A display area for a short text string or an
image, or both
·
JButton : An implementation of a
"push" button.
·
JTextField
:
JTextField
is a
lightweight component that allows the editing of a single line of text.
·
Connection : A connection (session) with
a specific database. SQL statements are executed and results are returned
within the context of a connection. A
Connection
object's database is able to provide information describing its tables, its
supported SQL grammar, its stored procedures, the capabilities of this
connection, and so on.
·
Statement :
The object used for executing a static SQL statement and returning the results
it produces.
·
ResultSet : table of data
representing a database result set, which is usually generated by executing a
statement that queries the database.
Logical
flow of the program:
·
The swing
program extends JFrame class and implements ActionListener.
·
Container
object containing the JButtons,JTextFields are defined.
·
Connection
is established between the database and the swing program with the data source.
·
When the
“delete ” button is pressed the corresponding record is deleted through the
object of Statement class.
·
When
“next” or “previous” buttons are pressed corresponding navigation is
implemented.
·
Id text
field in the frame is not editable.
Important notes:
·
The swing
program must import the package “javax.swing.*”.
·
To stop
the execution of the program on closing frame,use the method setDefaultCloseOperation(EXIT_ON_CLOSE).
·
While
writing the code for JDBC-ODBC bridge enclose it in try-catch blocks.
·
For
backward mavigation, object of Statement should be initialized like this
stmt =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE
)
To update a database table using java swing application.
To update a database table using java swing application.
Packages used:
1.
javax.swing.* : Provides a set of
"lightweight" (all-Java language) components that, to the maximum
degree possible, work the same on all platforms.
2. java.awt.* :
Contains all of the classes for creating user interfaces and for painting
graphics and images.
3.
java.awt.event.* : Provides interfaces and
classes for dealing with different
types of events fired by AWT components
4.
java.sql.* : Provides the API for accessing and processing data
stored in a data source (usually a relational database) using the Java
programming language.
Classes
used:
·
JFrame : An extended version of
java.awt.Frame
that adds support for the JFC/Swing component
architecture.
·
Container : A generic Abstract Window Toolkit(AWT)
container object is a component that can contain other AWT components.
Components added to a container are tracked in a list
·
JLabel : A display area for a short text string or an
image, or both
·
JButton : An implementation of a
"push" button.
·
JTextField
:
JTextField
is a
lightweight component that allows the editing of a single line of text.
·
Connection : A connection (session) with
a specific database. SQL statements are executed and results are returned
within the context of a connection. A
Connection
object's database is able to provide
information describing its tables, its supported SQL grammar, its stored
procedures, the capabilities of this connection, and so on.
·
Statement : The object used for
executing a static SQL statement and returning the results it produces.
·
ResultSet : table of data
representing a database result set, which is usually generated by executing a
statement that queries the database.
Logical
flow of the program:
·
The swing
program extends JFrame class and implements ActionListener.
·
Container
object containing the JButtons,JTextFields are defined.
·
Connection
is established between the database and the swing program with the data source.
·
When the
“update ” button is pressed the corresponding record is updated through the
object of Statement class.
·
When
“next” or “previous” buttons are pressed corresponding navigation is
implemented.
·
Id text
field in the frame is not editable.
Important notes:
·
The swing
program must import the package “javax.swing.*”.
·
To stop
the execution of the program on closing frame,use the method setDefaultCloseOperation(EXIT_ON_CLOSE).
·
While
writing the code for JDBC-ODBC bridge enclose it in try-catch blocks.
·
For
backward mavigation, object of Statement should be initialized like this
stmt =
con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE
)
A JAVA program to find Fibanocci/cuberoot/square root/palindrome/factorial/odd-even/prime
A JAVA program to find Fibanocci/cuberoot/square root/palindrome/factorial/odd-even/prime.
Packages used:
1. java.io.* : Provides for system input and output through data
streams, serialization and the file system.
2. javax.swing.* :
Provides a set of "lightweight" (all-Java language) components that,
to the maximum degree possible, work the same on all platforms.
3. java.awt.* :
Contains all of the classes for creating user interfaces and for painting
graphics and images.
4. java.awt.event.* : Provides interfaces and classes for dealing with
different types of events fired by AWT components
5. java.math.* :
Provides classes for performing arbitrary-precision integer arithmetic
(BigInteger) and arbitrary-precision decimal arithmetic
Classes
used:
·
JFrame : Provides classes for performing
arbitrary-precision integer arithmetic (BigInteger) and arbitrary-precision
decimal arithmetic
·
Container : A generic Abstract Window Toolkit(AWT)
container object is a component that can contain other AWT components.
Components added to a container are tracked in a list
·
JLabel : A display area for a short text string or an
image, or both
·
JButton : An implementation of a
"push" button.
·
JTextField
:
Logical
flow of the program: JTextField
is a
lightweight component that allows the editing of a single line of text.
·
A class
inheriting JFrame and implementing ActionListener is created.
·
Container
holds components like JLabel,JButton,JTextField.
·
According
to the button clicked corresponding action is performed.
·
Result of
the corresponding operation is displayed on the text field.
Important
notes:
·
In all
swing program the package that should be imported is “javax.swing.*”.
·
If in the
program JApplet is inherited then
the “init()” method is used to
initialize the applet.
·
If in the
program JFrame is inherited then the
inheriting class’s constructor initializes the swing application.
1.If super() method is called ,it should be the first
line inside the constructor.
2.Frame’s visibility and size must be set.
Servlet Program in java
Write a servlet that reads the name of the servlet class and its initialisation parameters from a server file and then displays these parameters on the screen.
Packages used:
1. java.io.* : Provides for system input and output through data
streams, serialization and the file system.
2. java.util.* :
Provides for system input and output through data streams, serialization and
the file system.
3.
javax.servlet.*
:
contains a number of classes and interfaces that describe and define the contr
acts between a servlet class and the runtime environment provided for an insta
nce of such a class by a conforming servlet container.
4.
javax.servlet.http.*
: package contains a number of
classes and interfaces that describe and define the contracts between a servlet
class running under the HTTP protocol and the runtime environment provided for
an instance of such a class by a conforming servlet container.
Classes used:
·
HttpServlet : simplifies writing HTTP
servlets,provides an framework for handling the HTTP protocol. Because it is an
abstract class, servlet writers must subclass it and override at least one
method.
·
HttpServletRequest : gets data from the client to the servlet for
use in the
HttpServlet.service
method
·
HttpServletResponse : This interface allows a servlet's
service
method to manipulate HTTP-protocol specified
header information and return data to its client.
·
PrintWriter : Print formatted representations
of objects to a text-output stream. This class implements all of the print methods found in
PrintStream
·
HttpUtils : collection of static utility methods useful
to HTTP servlets.
Logical
flow of the program:
·
A public class that inherits HttpServlet is created.
·
Initialisation parameters from a server file is
obtained with the help of methods defined in HttpUtils class,object of
HttpServletRequest class is used to obtain different parameters of a server
file.
Important
notes:
·
The
servlet program must import the package “javax.servlet.*”.
·
If the servlet program is accessing database it
should import the package “java.sql.*”.
·
The
servlet class should be declared “public”.
·
The class
should extend “HttpServlet” class.
·
The class
should throw ServletException,IOException to avoid compilation error.
·
If the servlet class is extending
“GenericServlet” then the method used is “service()”.
·
If the servlet class is extending “HttpServlet”,
it should import the package “javax.servlet.http.*”.Also
the method used here is either “doGet()”
or “doPost()”.
Animation Program in java
Create an animation with a single line, which changes its position in a
clock-wise direction. This line should produce an effect of a spinning line. In
the same example give option for clock-wise or anti-clock-wise spinning. Also provide
start and stop buttons to start and stop the animation. Demonstrate the
animation on the screen.
Packages
used:
1.
javax.swing.* : Provides a set of
"lightweight" (all-Java language) components that, to the maximum
degree possible, work the same on all platforms.
2.
java.awt.* : Contains all of the classes for
creating user interfaces and for painting graphics and images.
3.
java.awt.event.* : Provides interfaces and classes for
dealing with different types of events fired by AWT components.
4.
java.lang.* : Provides classes that are
fundamental to the design of the Java programming language.
Classes used:
- Graphics : Provides classes that are
fundamental to the design of the Java programming language.
·
JButton : An implementation of a "push"
button.
·
Thread : A thread is a thread of execution
in a program. The Java Virtual Machine allows an application to have multiple
threads of execution running concurrently.
Logical flow of the program:
·
A class
that extends JApplet and implements Runnable contains a getContentPane
container JPanel which holds two buttons.
·
Since
this class implements Runnable interface it defines two methods:-init() and
run().
·
init() method initializes the thread.
·
Two
methods are defined for clockwise spinning line and an anticlockwise spinning
line.
·
Each
method defines a variable “theta”.By randomly obtaining the values of x & y
using Math.random() method,lines are drawn clock-wise as well as anticlockwise.
·
repaint() method is called whenever the
JApplet is refreshed.
Important notes :
·
In all
swing program the package that should be imported is “javax.swing.*”.
·
If in the
program JApplet is inherited then
the “init()” method is used to
initialize the applet.
·
If in the
program JFrame is inherited then the
inheriting class’s constructor initializes the swing application.
1.
If
super() method is called ,it should be the first line inside the constructor.
2.
Frame’s
visibility and size must be set.
Swing Form in Java
Create a form using JFrame having 2 fields namely Name
and Remarks. Also create a button called Insert. This button will insert these
data from the form in a text file and later on read the same data and print it.
If more number of records are entered it should be appended to the same file.
Assume that the text file is already present. Also notify the Exceptions thrown
by the above program and give appropriate messages there.
Packages
used:
1.
javax.swing.* :
Provides a set of "lightweight" (all-Java language) components that,
to the maximum degree possible, work the same on all platforms.
2.
java.awt.* :
Contains all of the classes for creating user interfaces and for painting
graphics and images.
3.
java.awt.event.* :
Provides interfaces and classes for dealing with different types of events
fired by AWT components.
4.
javax.swing.event.* : Provides for events fired by Swing
components. It contains event classes and corresponding event listener
interfaces for events fired by Swing components in addition to those events in
the java.awt.event package.
5. java.io.* :
Provides for system input and output through data streams, serialization and
the file system.
Classes
used:
·
Conatainer : component that can contain
other AWT components. Components added to a container are tracked in a list
·
JLabel : Object which can display text,image or both.
·
JTextField
: A lightweight
component that allows the editing of a single line of text
·
JButton :
An implementation of a "push" button
·
FileOutpustStream : A file output stream is an output stream
for writing data to a
File
or to a FileDescriptor
.
Whether or not a file is available or may be created depends upon the
underlying platform.
Logical flow of the program:
·
The frame
holds two textfields to accept the name and remarks from the user.
·
The text
file to which data is to inserted is opened with the object of the class
FileOutputStream.
·
To append
the data to the text file the object of FileOutputStream must be initialized
with the following constructor.
“public FileOutputStream(String name,boolean append)”.
If the second parameter which accepts a Boolean value is
“true”,then the data is added to end of the text file rather than at the
beginning.
·
Object of
DataOutputStream is defined to write the data obtained to the text file.
Important notes:
·
In all
swing program the package that should be imported is “javax.swing.*”.
·
“javax.swing.event.*” package is
imported to perform events in swing program.
·
If in the
program JFrame is inherited then the
inheriting class’s constructor initializes the swing application.
1.If super() method is called ,it should be the first
line inside the constructor.
2.Frame’s visibility and size must be set.
·
If the
objects of components are declared before the constructor,only initialization
of those objects are done inside the constructor.if the objects are declared
twice that would generate exception.
MDI Form in SWING
(Creating MDI Form in SWING)Design a
class, which extends JFrame and has three objects of three classes whose name
are ColorPanel, CitiesPanel, and FlavourPanel. All the three classes
(ColorPanel: Names of colors inside it, CitiesPanel: Names of cities inside it,
and FlavourPanel- Names of Icecream flavours) extend JInternalFrame and have a
method, which makes the Panel visible.
The main JFrame has an object of JDesktopPane and this object holds the
three panels, which are displayed on the click of the menu bar item.
Packages
used:
1.
javax.swing.* : Provides a set of
"lightweight" (all-Java language) components that, to the maximum
degree possible, work the same on all platforms.
2.
java.awt.* : Contains all of the classes for
creating user interfaces and for painting graphics and images.
3.
java.awt.event.* : Provides interfaces and classes for
dealing with different types of events fired by AWT components.
Classes used:
·
JMenuBar : An implementation of a menu bar.
JMenu
objects are added to the menu bar to
construct a menu
·
JMenu : An implementation of a menu -- a
popup window containing
JMenuItem
s
that is displayed when the user selects an item on the JMenuBar
.
·
JMenuItem : An implementation of an item in a menu. A
menu item is essentially a button sitting in a list.
·
JDesktopPane
: A container used to create a multiple-document interface or a virtual
desktop.
Logical flow of the program:
·
A menu is
created with an object of JMenuBar which holds a JMenu object.
·
This
JMenu object contains three JMenuItem objects,each attached to ActionListener.Clicking
on those menuitems will lead to an JInternalFrame object on the JDesktopPane.
·
Object of
JDesktopPane class is created which holds objects of JInternalFrame class.
·
Each
JInternalFrame object contains a JPanel container holding different components.
Important Notes :
·
In all
swing program the package that should be imported is “javax.swing.*”.
·
If in the
program JApplet is inherited then
the “init()” method is used to
initialize the applet.
·
If in the
program JFrame is inherited then the
inheriting class’s constructor initializes the swing application.
1. If super() method is called ,it should be the
first line inside the constructor.
2. Frame’s visibility and size must be set.
Free Hand In JAVA
Objective:
Define a class that enables the drawing of freehand lines on a screen
through mouse clicking and dragging. Use anonymous inner classes to implement
event listeners. The drawing should be cleared when a key is pressed and the
line colour should be selectable. Define a test class to demonstrate the
program.
Packages used:
- java.awt.*;
: Contains all of the classes for creating user interfaces and for
painting graphics and images.
- java.awt.event.* : Provides interfaces and classes for
dealing with different types of events fired by AWT components.
Classes used:
- Frame
: A
Frame
is a top-level window with a title and a border.The size of the frame includes any area designated for the border.
·
MenuBar : The
MenuBar
class encapsulates the platform's concept of a menu bar bound to a frame. In
order to associate the menu bar with a Frame
object, call the frame's setMenuBar
method.
·
Menu : A
Menu
object is a pull-down menu component that is
deployed from a menu bar. Each item in a menu must belong to the MenuItem
class. It can be an instance of MenuItem
, a submenu (an instance of Menu
), or a check box (an instance of CheckboxMenuItem
).
·
MenuItem
: All items in a menu must belong to the class
MenuItem
, or one of its subclasses. The default MenuItem
object embodies a simple labeled menu item.
·
Graphics : The
Graphics
class is the abstract base class for all graphics
contexts that allow an application to draw onto components that are realized on
various devices, as well as onto off-screen images.
·
Color : The
Color
class is used to encapsulate colors in the default sRGB
color space or colors in arbitrary color spaces identified by a ColorSpace
.
Logical flow of the program:
·
File Menu
contains clear and quit options
·
Colour
menu has blue, red and green options to change stroke colour
·
When the mouse
if first pressed, mousePressed event is called which sets the x1 and y1 to the current
mouse coords
·
When the mouse
is dragged in paint area, mouseDragged event is called which sets x2 and y2 as the
coordinates of the mouse pointer and passes it to a function called draw which
in turn draws a line between x1,y1 and x2,y2 . Then it sets x1 and y1 as current
mouse co-ords. So, the next drag event draws line between these cords and the
newly moved co-ords of the mouse. This goes on on every drag event.
·
When the mouse
is finally released, mouseReleased event is called which sets x2 and y2 as the
coordinates of the mouse pointer and passes it to a function called draw which
in turn draws a line between x1,y1 and x2,y2 . Then it sets x1 and y1 as
current mouse co-ords
Important notes :
·
Import
java.awt.event.* even if you have imported java.awt.*
·
If in the
program Frame is inherited then the
inheriting class’s constructor initializes the application.
1. If super() method is called ,it should be the
first line inside the constructor.
2. Frame’s visibility and size must be set.
Subscribe to:
Posts (Atom)
1 comments: