Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Scientific Calculator: Report Title

Download as pdf or txt
Download as pdf or txt
You are on page 1of 14

Report Title

Scientific Calculator

Student Name: Ismail Nasih Ahmed

Class: 2nd stage – Group A

Course Title: Scientific Calculator

Department: Software and informatics

College of Engineering

Salahaddin University-Erbil

Academic Year 2019-2020

1
ABSTRACT

The Java Calculator is a cross-platform, text-interpreting calculator written


in the Java Programming Language. The calculator provides basic
operations, common functions such as natural logarithms and square roots

Basic Controls The calculator graphical user interface (GUI) has four main
parts, the menu bar, the display, and the button panel. The display is where
problems and their solutions will be shown.

2
TABLE OF CONTENTS

Abstract 2

Table of Contents 3

Introduction 4

Class Hierarchy 5

Background and review 6


GUI components 6
Event Handler 11

Conclusion 13

References 14

3
INTRODUCTION

This Calculator Was Created with help of Java Swing.

4
Class Hierarchy:

object

main
Component

Container

Window

Frame

JFrame
Scientific_calculator

5
BACKGROUND & REVIEW

GUI components:

1. Button - has a textual label and is designed to invoke an action when


pushed. Button is a class in package java.awt which represents
buttons on the screen. The constructor is:

public Button (String label), which, when executed, creates a button


with "label" printed on it. Generally, the button is large enough to
display the label. There is also a parameter less constructor that
creates an unlabelled button. Buttons respond to a variety of
messages. For instance, you can add an "ActionListener" to a button
with the method:

public void addActionListener(ActionListener listener);

2. Label - is a component that displays a single line of read-only, non-


selectable text, or in another way graphical control element which
displays text on a form. It is usually a static control; having no
interactivity. A label is generally used to identify a nearby text box
or other widget.

6
3. TextField - is a component that implements a single line of text, and
is a part of javax.swing package. The class JTextField is a
component that allows editing of a single line of text. JTextField
inherits the JTextComponent class and uses the interface
SwingConstants.

4. JMenuBar, JMenu are a part of Java Swing package. JMenuBar is an


implementation of menu bar. the JMenuBar contains one or more JMenu
objects, when the JMenu objects are selected they display a popup
showing one or more JMenuItems . JMenu basically represents a menu

7
Some Methods of the JTextField :

1. setFont(Font f) : set the font of text displayed in text field.


2. setSize() : set the Size of text displayed in text field.
3. addActionListener(ActionListener l) : set an ActionListener to the
text field.

methods most used:


1. add (Component c): adds component to container.
2. addActionListenerListener(ActionListener d) : add actionListener
for specified component
3. setBackground(Color c) : sets the background color of the specified
container
4. setSize(int a, int b) : sets the size of container to specified
dimensions.
5. setText(String s) : sets the text of the label to s.
6. getText() : returns the text of the label.

8
Why using these components:

1. buttons: the most important thing for calculator is buttons like Button
Group, Radio Button, Button and toggle button. In this project the
most needed is just a button for doing operations and pressing
numbers, Generally, Button is basic of calculator.in this calculator I
didn’t used radio button which you should use Button group it and it
can be used as a ON and OFF switch for calculator, but I didn’t use
in this project because you should use a huge code for ON and OFF
and it’s not necessary in this sample project.

2. Label: I used ln this calculator to show calculation operator in the


label instead of showing it in the JTextFeild or the Screen of the
calculator, this label is showing number plus the operator the user
add to next number, it more better to show calculation operator in the
label, since showing the operator in the screen is not nice and take a
lot of space in the screen,the label take a small area and nicer than
showing it in the screen.

3. TextField: is the Screen of the Calculator and used to show the


numbers that user input it and it is just numbers not operators, the
operators are shown in the label, but you can not add text from the
screen.

9
4. JMenuBar: this component is basically for switching between
standard calculator and basic calculator and can be switched by using
Ctrl + S for Standard and Ctrl + B for basic, this menu bare is very
helpful, At first the calculator is just one part but then with menu bar
I divided it for two part basic and scientific

The Java Swing allows us to customize the GUI by changing the look and
feel(L&F). The look defines the general appearance of components and the
feel defines their behavior. L&Fs are subclasses of the LookAndFeel class
and each L&F is identified by its fully qualified class name.

JTattoo consists of several different Look and Feels for Swing


applications.

Some of the features:

• Extra ordinality look with harmonic colour themes


• Interactive feel with nice rollover effects
• Top performance through optimized paint algorithms

In here the used theme is AlumniumLookAndFeel theme.

10
Event Handler:

1. Class (ActionEvent): Listener interface (ActionListner)


public interface ActionListener extends EventListener, The listener
interface for receiving action events. The class that is interested in
processing an action event implements this interface, and the object
created with that class is registered with a component, using the
component's addActionListener method. When the action event
occurs, that object's actionPerformed method is invoked.

Method:
void actionPerformed(ActionEvent e)

this method is already defined in ActionListener class and we have just


override it. Here, you will define what will your program do. when the user
clicks the component being monitored for an action event.

Class (WindowEvent): interface Class (WindowListner):

extends ComponentEvent, which indicates that a window has changed its


status. WindowEvent is generated by a Window object when it is opened,
closed, about to close, activated or deactivated.

The event is passed to every WindowListener or WindowAdapter object


which registered to receive such events using the window's
addWindowListener method. (WindowAdapter objects implement the
WindowListener interface.) Each such listener object gets this
WindowEvent when the event occurs.
11
public abstract interface WindowListener

extend EventListener

The listener interface for receiving window events. The class that is
interested in processing a window event either implements this interface
(and all the methods it contains) or extends the abstract WindowAdapter
class (overriding only the methods of interest). The listener object created
from that class is then registered with a Window using the winodw's
addWindowListener method. When the window's status changes by virtue
of being opened, closed, activated or deactivatedthe relevant method in the
listener object s invoked, and the WindowEvent is passed to it.

Method:

void windowactivated(WindowEvent e)
Invoked when the window is set to be the user's active window, which means
the window will receive keyboard events.

12
CONCLUSION

In this project I learned A lot of things, one of the most important things is
using java swing for creating GUI which is very helpful, another thing is
using even handlers for doing actions with buttons and this
project(Calculator) is very good to start other project, it is basic to start a
big project.at First I was Serious to Choose this Project but then learned
lots of points from the project like using GUI components correctly,
organize my code, and using java swing.

13
REFERENCES
[1] https://www.javatpoint.com/java-awt

[2] https://docs.oracle.com/javase/tutorial/java/nutsandbolts/op1.html

[3]https://docs.oracle.com/javase/tutorial/uiswing/

[4]https://docs.oracle.com/javase/7/docs/api/java/beans/EventHandler.html

14

You might also like