100% found this document useful (1 vote)
258 views7 pages

Lab Manual Advanced Java Programming: Sinhgad College of Engineering, Pune - 41

This document provides instructions for Experiment 3 of the Advanced Java Programming lab manual. The experiment aims to develop a GUI that accepts student marks for various subjects, calculates the result, and displays it in a separate window. It discusses the key Java classes needed like JPanel, JLabel, JFrame, JButton, JTextField and the ActionListener interface. It provides the theory behind these concepts and presents an algorithm to implement the task. The conclusions section asks questions to check understanding of key concepts covered.

Uploaded by

Mini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
258 views7 pages

Lab Manual Advanced Java Programming: Sinhgad College of Engineering, Pune - 41

This document provides instructions for Experiment 3 of the Advanced Java Programming lab manual. The experiment aims to develop a GUI that accepts student marks for various subjects, calculates the result, and displays it in a separate window. It discusses the key Java classes needed like JPanel, JLabel, JFrame, JButton, JTextField and the ActionListener interface. It provides the theory behind these concepts and presents an algorithm to implement the task. The conclusions section asks questions to check understanding of key concepts covered.

Uploaded by

Mini
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Sinhgad College of Engineering, Pune – 41

Department of Electronics & Telecommunication Engineering

Lab Manual
Advanced Java Programming

Class: T.E (E&TC) Year: 2021-22 Sem.: II


Sinhgad College of Engineering, Pune – 41
Department of Electronics & Telecommunication Engineering

List of Experiments
Class: T.E. (E&TC) Subject: Advanced Java Programming Year: 2021-22 Sem.: II

Sr. No. Title of Experiment


Write a program to demonstrate status of key on an Applet window such as KeyPressed, KeyReleased,
1.
KeyUp, KeyDown.
Write a program to create a frame using AWT. Implement mouseClicked, mouseEntered() and
2.
mouseExited() events. Frame should become visible when the mouse enters it.
Develop a GUI which accepts the information regarding the marks for all the subjects of a student in the
3.
examination. Display the result for a student in a separate window.

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.

8. Write a database application that uses any JDBC driver.

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:

SCOE, DEPT. OF E&TC ENGG. TE E&TC 1


Advanced JAVA Programming

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.

APPRATUS: PC with Eclipse & JDK (version lesser than 8).

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:

JTextField( ) JTextField(int cols)


JTextField(String s, int cols) JTextField(String s)

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

SCOE, DEPT. OF E&TC ENGG. TE E&TC 2


Advanced JAVA Programming

• 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:

String getText( ) void setText(String s)

Here, s is the text to be associated with the button.


Concrete subclasses of AbstractButton generate action events when they are pressed. Listeners register
and un-register for these events via the methods shown here:

void addActionListener(ActionListener al) void

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.

SCOE, DEPT. OF E&TC ENGG. TE E&TC 3


Advanced JAVA Programming

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:

JFrame(): This helps in creating a frame which is invisible.


JFrame(String Title): Helps in creating a frame with a title.
JFrame(GraphicsConfiguration gc): Creates a frame with blank title and the graphics
configuration of screen.

• 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().

The actionPerformed() method is invoked automatically whenever you click on the


registered component.

public abstract void actionPerformed(ActionEvent e);

ALGORITHM:

1. Import the packages required for KeyEvent handling mechanism.


2. Create a class that public class ReportCard extends JFrame
3. Implement panels using JPanel with the label for student name, subject, names.
4. Create the text fields using JTextField() for taking name and subject marks of
respected subjects from user.
5. Create the button using Jbutton() with label “Submit” so that after entering name and
subject marks user will press to submit it.
6. Use ActionListener() to get notification whenever user click on the button.
7. Use actionPerformed() to implement the average calculation process.
8. Use getText() method to get the marks entered by user in textfields.
9. Calculate the average and display it on new frame created using JFrame() method.

SCOE, DEPT. OF E&TC ENGG. TE E&TC 4


Advanced JAVA Programming

CONCLUSIONS:

1. Distinguish between JFrame and JPanel?


2. Demonstrate with example how to give label to Jbutton, Jpanel.
3. Show the use of setEchoChar in Jtextfield with example.

SCOE, DEPT. OF E&TC ENGG. TE E&TC 5

You might also like