Javacase
Javacase
Javacase
INTRODUCTION
Online Exam Project was implemented using Java AWT and Java Swing
Java programming language was originally developed by Sun Microsystems which was initiated
by James Gosling and released in 1995 as core component of Sun Microsystems' Java platform
(Java 1.0 [J2SE]).
The latest release of the Java Standard Edition is Java SE 8. With the advancement of Java and
its widespread popularity, multiple configurations were built to suit various types of platforms.
For example: J2EE for Enterprise Applications, J2ME for Mobile Applications.
The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is
guaranteed to be Write Once, Run Anywhere.
Java is −
Object Oriented − In Java, everything is an Object. Java can be easily extended since it
is based on the Object model.
Simple − Java is designed to be easy to learn. If you understand the basic concept of
OOP Java, it would be easy to master.
1
Portable − Being architecture-neutral and having no implementation dependent aspects
of the specification makes Java portable. Compiler in Java is written in ANSI C with a
clean portability boundary, which is a POSIX subset.
Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly
on compile time error checking and runtime checking.
Interpreted − Java byte code is translated on the fly to native machine instructions and
is not stored anywhere. The development process is more rapid and analytical since the
linking is an incremental and light-weight process.
High Performance − With the use of Just-In-Time compilers, Java enables high
performance.
2
1.1 Java AWT
AWT stands for Abstract Window Toolkit. It is a platform dependent API for creating Graphical
User Interface (GUI) for java programs.
Java AWT calls native platform (Operating systems) subroutine for creating components such as
textbox, checkbox, button etc. For example an AWT GUI having a button would have a different
look and feel across platforms like windows, Mac OS & Unix, this is because these platforms
have different look and feel for their native buttons and AWT directly calls their native
subroutine that creates the button. In simple, an application build on AWT would look like a
windows application when it runs on Windows, but the same application would look like a Mac
application when runs on Mac OS.
AWT is rarely used now days because of its platform dependent and heavy-weight nature. AWT
components are considered heavy weight because they are being generated by underlying
operating system (OS). For example if you are instantiating a text box in AWT that means you
are actually asking OS to create a text box for you.
3
Components and containers
All the elements like buttons, text fields, scrollbars etc are known as components. In AWT we
have classes for each component as shown in the above diagram. To have everything placed on a
screen to a particular position, we have to add them to a container. A container is like a screen
wherein we are placing components like buttons, text fields, checkbox etc. In short a container
contains and controls the layout of components. A container itself is a component (shown in the
above hierarchy diagram) thus we can add a container inside container.
Types of containers:
As explained above, a container is a place wherein we add components like text field, button,
checkbox etc. There are four types of containers available in AWT: Window, Frame, Dialog and
Panel. As shown in the hierarchy diagram above, Frame and Dialog are subclasses of Window
class.
4
1.2 Java Swing
Swing is a part of Java Foundation classes (JFC), the other parts of JFC are java2D and Abstract
window toolkit (AWT). AWT, Swing & Java 2D are used for building graphical user interfaces
(GUIs) in java. In this tutorial we will mainly discuss about Swing API which is used for
building GUIs on the top of AWT and are much more light-weight compared to AWT.
JFrame – A frame is an instance of JFrame. Frame is a window that can have title, border,
menu, buttons, text fields and several other components. A Swing application must have a frame
to have the components added to it.
JPanel – A panel is an instance of JPanel. A frame can have more than one panels and each
panel can have several components. You can also call them parts of Frame. Panels are useful for
grouping components and placing them to appropriate locations in a frame.
JLabel – A label is an instance of JLabel class. A label is unselectable text and images. If you
want to display a string or an image on a frame, you can do so by using labels.
JTextField – Used for capturing user inputs, these are the text boxes where user enters the data.
JPasswordField – Similar to text fields but the entered data gets hidden and displayed as dots on
GUI.
5
1.3 Working of Online Exam
Online Exam Project in Java without database. In this project, there are given 10 questions to
play. User can bookmark any question for the reconsideration while going to result.We are using
here java array to store the questions, options and answers not database. You can use collection
framework or database in place of array.
6
2. HARDWARE AND SOFTWARE SPECIFICATION
HARDWARE SPECIFICATIONS
The selection of hardware configuration is very important task related to the software
development. Insufficient RAM may affect adversely on the speed and efficiency of the entire
system. The processor should be powerful to handle the entire operations. The hard disk should
have sufficient capacity to store the file applications.
RAM : 2 GB
Mouse : 3 Buttons
SOFTWARE SPECIFICATIONS
The software is desired for JAVA version 7 or later. It can also work in Windows 7 or later
version.
OS : Windows 7
7
3. SCREEN LAYOUT
8
9
10
11
12
13
14
15
16
17
18
19
4. CODING
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
JLabel l;
JButton b1,b2;
ButtonGroup bg;
int count=0,current=0,x=1,y=1,now=0;
OnlineTest(String s)
super(s);
l=new JLabel();
add(l);
bg=new ButtonGroup();
for(int i=0;i<5;i++)
20
jb[i]=new JRadioButton();
add(jb[i]);
bg.add(jb[i]);
b1=new JButton("Next");
b2=new JButton("Bookmark");
b1.addActionListener(this);
b2.addActionListener(this);
add(b1);add(b2);
set();
l.setBounds(30,40,450,20);
jb[0].setBounds(50,80,100,20);
jb[1].setBounds(50,110,100,20);
jb[2].setBounds(50,140,100,20);
jb[3].setBounds(50,170,100,20);
b1.setBounds(100,240,100,30);
b2.setBounds(270,240,100,30);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLayout(null);
setLocation(250,100);
setVisible(true);
21
setSize(600,350);
if(e.getSource()==b1)
if(check())
count=count+1;
current++;
set();
if(current==9)
b1.setEnabled(false);
b2.setText("Result");
if(e.getActionCommand().equals("Bookmark"))
bk.setBounds(480,20+30*x,100,30);
add(bk);
22
bk.addActionListener(this);
m[x]=current;
x++;
current++;
set();
if(current==9)
b2.setText("Result");
setVisible(false);
setVisible(true);
for(int i=0,y=1;i<x;i++,y++)
if(e.getActionCommand().equals("Bookmark"+y))
if(check())
count=count+1;
now=current;
current=m[y];
set();
((JButton)e.getSource()).setEnabled(false);
current=now;
23
}
if(e.getActionCommand().equals("Result"))
if(check())
count=count+1;
current++;
//System.out.println("correct ans="+count);
JOptionPane.showMessageDialog(this,"correct ans="+count);
System.exit(0);
void set()
jb[4].setSelected(true);
if(current==0)
jb[0].setText("int");jb[1].setText("Float");jb[2].setText("array");jb[3].setText("char");
24
if(current==1)
jb[0].setText("Swing");jb[1].setText("Applet");jb[2].setText("Object");jb[3].setText("ActionEve
nt");
if(current==2)
l.setText("Que3: Which package is directly available to our class without importing it?");
jb[0].setText("swing");jb[1].setText("applet");jb[2].setText("net");jb[3].setText("lang");
if(current==3)
jb[0].setText("lang");jb[1].setText("Swing");jb[2].setText("Applet");jb[3].setText("awt");
if(current==4)
25
jb[0].setText("Utek");jb[1].setText("Aptech");jb[2].setText("SSS
IT");jb[3].setText("jtek");
if(current==5)
jb[0].setText("class");jb[1].setText("int");jb[2].setText("get");jb[3].setText("if");
if(current==6)
jb[0].setText("Swing");jb[1].setText("Actionperformed");jb[2].setText("ActionEvent");
jb[3].setText("Button");
if(current==7)
jb[0].setText("toString");jb[1].setText("finalize");jb[2].setText("equals");
jb[3].setText("getDocumentBase");
if(current==8)
26
{
jb[0].setText("init");jb[1].setText("main");jb[2].setText("start");jb[3].setText("destroy");
if(current==9)
jb[0].setText("JButton");jb[1].setText("JList");jb[2].setText("JButtonGroup");
jb[3].setText("JTextArea");
l.setBounds(30,40,450,20);
for(int i=0,j=0;i<=90;i+=30,j++)
jb[j].setBounds(50,80+i,200,20);
boolean check()
if(current==0)
return(jb[2].isSelected());
if(current==1)
return(jb[2].isSelected());
if(current==2)
27
return(jb[3].isSelected());
if(current==3)
return(jb[0].isSelected());
if(current==4)
return(jb[2].isSelected());
if(current==5)
return(jb[2].isSelected());
if(current==6)
return(jb[1].isSelected());
if(current==7)
return(jb[3].isSelected());
if(current==8)
return(jb[1].isSelected());
if(current==9)
return(jb[2].isSelected());
return false;
28
}
29
5. CONCLUSION
The ONLINE EXAM aims at creating a aptitude test using Java. Proper system study has
been conducted and findings in critical area have been incorporated. The case study has
successfully completed and tested and implemented after giving necessary instructions to the
operator. This case study is well documented and validated.
Successful implementation of the system requires a lot of effort from customers and
developers side. Lack of awareness of computer and how the system operates will affect the
performance of the system. Proper system study is also required for the successful
completion of the Case study. The system design though it has met the user’s needs has its
own limitations.
30
6. BIBLIOGRAPHY & WEBLIOGRAPHY
Debashish Jana, Java and Object Oriented Programming Paradigm, Prentice Hall, 2008
www.codeproject.com
www.javatpoint.com
31