Javacase

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 31

1.

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.

 Platform Independent − Unlike many other programming languages including C and


C++, when Java is compiled, it is not compiled into platform specific machine, rather
into platform independent byte code. This byte code is distributed over the web and
interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.

 Simple − Java is designed to be easy to learn. If you understand the basic concept of
OOP Java, it would be easy to master.

 Secure − With Java's secure feature it enables to develop virus-free, tamper-free


systems. Authentication techniques are based on public-key encryption.

 Architecture-neutral − Java compiler generates an architecture-neutral object file


format, which makes the compiled code executable on many processors, with the
presence of Java runtime system.

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.

 Multithreaded − With Java's multithreaded feature it is possible to write programs that


can perform many tasks simultaneously. This design feature allows the developers to
construct interactive applications that can run smoothly.

 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.

 Distributed − Java is designed for the distributed environment of the internet.

 Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to


adapt to an evolving environment. Java programs can carry extensive amount of run-
time information that can be used to verify and resolve accesses to objects on run-time.

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.

Java AWT Hierarchy

The hierarchy of Java AWT classes are given below.

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.

Window: An instance of the Window class has no border and no title


Dialog: Dialog class has border and title. An instance of the Dialog class cannot exist without an
associated instance of the Frame class.
Panel: Panel does not contain title bar, menu bar or border. It is a generic container for holding
components. An instance of the Panel class provides a container to which to add components.
Frame: A frame has title, border and menu bars. It can contain several components like buttons,
text fields, scrollbars etc. This is most widely used container while developing an application in
AWT.

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.

In the above example we have used several components.

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.

JButton – A button is an instance of JButton class.

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.

Processor : Intel Pentium Processor

RAM : 2 GB

Hard disk capacity : 40 GB

Monitor : SVGA color monitor

Keyboard : 108 keys and above

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.

Front end : JAVA

OS : Windows 7

Back end : NETBEANS

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.*;

class OnlineTest extends JFrame implements ActionListener

JLabel l;

JRadioButton jb[]=new JRadioButton[5];

JButton b1,b2;

ButtonGroup bg;

int count=0,current=0,x=1,y=1,now=0;

int m[]=new int[10];

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);

public void actionPerformed(ActionEvent e)

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"))

JButton bk=new JButton("Bookmark"+x);

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)

l.setText("Que1: Which one among these is not a primitive datatype?");

jb[0].setText("int");jb[1].setText("Float");jb[2].setText("array");jb[3].setText("char");

24
if(current==1)

l.setText("Que2: Which class is available to all the class automatically?");

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)

l.setText("Que4: String class is defined in which package?");

jb[0].setText("lang");jb[1].setText("Swing");jb[2].setText("Applet");jb[3].setText("awt");

if(current==4)

l.setText("Que5: Which institute is best for java coaching?");

25
jb[0].setText("Utek");jb[1].setText("Aptech");jb[2].setText("SSS
IT");jb[3].setText("jtek");

if(current==5)

l.setText("Que6: Which one among these is not a keyword?");

jb[0].setText("class");jb[1].setText("int");jb[2].setText("get");jb[3].setText("if");

if(current==6)

l.setText("Que7: Which one among these is not a class? ");

jb[0].setText("Swing");jb[1].setText("Actionperformed");jb[2].setText("ActionEvent");

jb[3].setText("Button");

if(current==7)

l.setText("Que8: which one among these is not a function of Object class?");

jb[0].setText("toString");jb[1].setText("finalize");jb[2].setText("equals");

jb[3].setText("getDocumentBase");

if(current==8)

26
{

l.setText("Que9: which function is not present in Applet class?");

jb[0].setText("init");jb[1].setText("main");jb[2].setText("start");jb[3].setText("destroy");

if(current==9)

l.setText("Que10: Which one among these is not a valid component?");

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;

public static void main(String s[])

new OnlineTest("Online Test Of Java");

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

Bruce Eckel, Thinking in Java

J . Reynolds , Theories of Programming Languages, Cambridge University Press

www.codeproject.com

www.javatpoint.com

31

You might also like