Lab Manual Advanced Java Programming: Sinhgad College of Engineering, Pune - 41
Lab Manual Advanced Java Programming: Sinhgad College of Engineering, Pune - 41
Lab Manual
Advanced Java Programming
List of Experiments
Class: T.E. (E&TC) Subject: Advanced Java Programming Year: 2021-22 Sem.: II
4. Write a program to insert and retrieve the data from the database using JDBC.
Develop an RMI application which accepts a string or a number and checks that string or number is
5.
palindrome or not.
6. Write a program to demonstrate the use of InetAddress class and its factory methods.
A) Write Servlet (procedure for client side) to display username and password accepted from the client.
7.
B) Write Servlet (procedure for server side) to display username and password accepted from the client.
9. Write a simple JSP page to display a simple message (It may be a simple html page).
Create a registration servlet in Java using JDBC. Accept the details such as Username, Password, Email,
10. and Country from the user using HTML Form and store the registration details in the database.
11. Write java program that stores marks of 5 subjects in database & generate result sheet.
Advanced JAVA Programming
EXPERIMENT NO: 03
TITLE: Develop a GUI which accepts the information regarding the marks for all the subjects
of a student in the examination. Display the result for a student in a separate window.
CLASS:
BATCH:
DATE:
ROLL NO:
AIM: To develop GUI which accepts the information regarding the marks for all the subjects of a
student in the examination and to show the result in separate window.
OBJECTIVES: To design GUI to accept the student information regarding the marks and display
result in separate window.
THEORY:
To develop GUI which accepts the information regarding the marks for all the subjects of a student
in the examination and to show the result in separate window following basic methods are needed:
• JPanel
• JLabel
• JFrame()
• JButton
• JTextField
• ActionListener()
• JPanel:
Fundamental to Swing is the JApplet class, which extends Applet. Applets that use Swing must be
subclasses of JApplet. JApplet is rich with functionality that is not found in Applet. For example,
JApplet supports various “panes,” such as the content pane, the glass pane, and the root pane.
When adding a component to an instance of JApplet, do not invoke the add() method of the
applet. Instead, call add( ) for the content pane of the JApplet object. The content pane can be
obtained via the method shown here:
Container getContentPane()
The add() method of Container can be used to add a component to a content pane. Its form is
shown here:
void add(comp)
Here, comp is the component to be added to the content pane.
JTextField:
The Swing text field is encapsulated by the JTextComponent class, which extends JComponent. It
provides functionality that is common to Swing text components. One of its subclasses is
JTextField, which allows us to edit one line of text. Some of its constructors are shown here:
Here, s is the string to be presented, and cols is the number of columns in the text field. The
following example illustrates how to create a text field. The applet begins by getting its content
pane, and then a flow layout is assigned as its layout manager. Next, a JTextField object is
created and is added to the content pane
• Buttons
Swing buttons provide features that are not found in the Button class defined by the AWT. For
example, we can associate an icon with a Swing button. Swing buttons are subclasses of the
AbstractButton class, which extends JComponent. AbstractButton contains many methods that
allow us to control the behavior of buttons, check box and radio buttons. For example, we can
define different icons that are displayed for the component when it is disabled, pressed, or selected.
Another icon can be used as rollover icon, which is displayed when the mouse is positioned over
that component. The following are the methods that control this behavior:
void setDisabledIcon(Icon di) void setPressedIcon(Icon pi)
void setSelectedIcon(Icon si) void setRolloverIcon(Icon ri)
Here, di, pi, si, and ri are the icons to be used for these different conditions. The
text associated with a button can be read and written via the following methods:
removeActionListener(ActionListener al)
Here, al is the action listener. AbstractButton is a superclass for push buttons, check boxes, and radio
buttons.
• JButton
The JButton class provides the functionality of a push button. JButton allows an icon string, or
both to be associated with the push button. Some of its constructors are shown here:
JButton(Icon i) JButton(String s) JButton(String s, Icon i)
Here, s and i are the string and icon used for the button. The following example displays four push
buttons and a text field. Each button displays an icon that represents the flag of a country. When a
button is pressed, the name of that country is displayed in the text field. The applet begins by
getting its content pane and setting the layout manager of that pane. Four image buttons are created
and added to the content pane. Next, the applet is registered to receive action events that are
generated by the buttons. A text field is then created and added to the applet. Finally, a handler for
action events displays the command string that is associated with the button. The text field is used
to present this string.
JFrame:
JFrame is a top-level container that provides a window on the screen. A frame is actually a base
window on which other components rely, namely the menu bar, panels, labels, text fields, buttons,
etc. Almost every other Swing application starts with the JFrame window. Unlike a frame,
JFrame has the option to hide or close the window with the help of the method
setDefaultCloseOperation(int).
JFrame class has many constructors that are used to create a new JFrame. You can create a
JFrame using these methods:
• ActionListener:
The Java ActionListener is notified whenever you click on the button or menu item. It is notified
against ActionEvent. The ActionListener interface is found in java.awt.event package. It
has only one method:
actionPerformed().
ALGORITHM:
CONCLUSIONS: