0% found this document useful (0 votes)
15 views

ALL JAVA Project

good

Uploaded by

Waktola Lamesa
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

ALL JAVA Project

good

Uploaded by

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

SIX LABEL

package lbel;

import java.awt.*;

import javax.swing.*;

import javax.swing.border.*;

public class grand {

public static void main(String[] args) {

JFrame frame = new SixLabels();

frame.setTitle("Six Labels");

frame.setSize(300, 200);

frame.setLocationRelativeTo(null);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

class SixLabels extends JFrame {

public SixLabels() {

setLayout(new GridLayout(2, 3));


JLabel[] list = {

new JLabel("Black"),

new JLabel("Blue"),

new JLabel("Cyan"),

new JLabel("Green"),

new JLabel("Magenta"),

new JLabel("Orange")};

// set foreground colors

list[0].setForeground(Color.black);

list[1].setForeground(Color.blue);

list[2].setForeground(Color.cyan);

list[3].setForeground(Color.green);

list[4].setForeground(Color.magenta);

list[5].setForeground(Color.orange);

// set background colors

for (int i = 0; i < list.length; i++)

list[i].setBackground(Color.white);

// set fonts

Font font = new Font("TimesRoman", Font.BOLD, 20);

for (int i = 0; i < list.length; i++)

list[i].setFont(font);

// set borders

Border lineBorder = new LineBorder(Color.yellow, 1);


for (int i = 0; i < list.length; i++)

list[i].setBorder(lineBorder);

// set tooltip

for (int i = 0; i < list.length; i++)

list[i].setToolTipText(list[i].getText());

// add all labels to container

for (int i = 0; i < list.length; i++)

add(list[i]);

CALCULATOR;
import javax.swing.*;

import java.awt. *;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

@SuppressWarnings("serial")

public class CalculatorLayout extends JFrame implements ActionListener

// =======================Declaration of variable===============

//----------Common keys---------------
private final JButton bOne = new JButton("1");

private final JButton bTwo = new JButton("2");

private final JButton bThree = new JButton("3");

private final JButton bFour = new JButton("4");

private final JButton bFive = new JButton("5");

private final JButton bSix = new JButton("6");

private final JButton bSeven = new JButton("7");

private final JButton bEight = new JButton("8");

private final JButton bNine = new JButton("9");

private final JButton bZero = new JButton("0");

private final JButton bMul = new JButton("\u00D7");

private final JButton bDiv = new JButton("\u00F7");

private final JButton bAdd = new JButton("+");

private final JButton bSub = new JButton("\u02D7");

private final JButton bEqual = new JButton("=");

private final JButton bPoint = new JButton(".");

private final JButton bDel = new JButton("DE");

private JButton bClear = new JButton("C");

private JButton bSquare = new JButton("x\u00B2");

private JButton bCube = new JButton("x\u00B3");

private JButton bSqrt = new JButton("\u221A");

private JButton bPercent = new JButton("%");

private JButton bMod = new JButton("Mod");

private JButton bOneByN = new JButton("1/n");

private JButton bPlusMinus = new JButton("\u00B1");

//----------Scientific keys---------------

private JButton bSin = new JButton("sin");

private JButton bCos = new JButton("cos");


private JButton bTan = new JButton("tan");

private JButton bAsin = new JButton("asin");

private JButton bAcos = new JButton("acos");

private JButton bAtan = new JButton("atan");

private JButton bSinH = new JButton("sinh");

private JButton bCosH = new JButton("cosh");

private JButton bTanH = new JButton("tanh");

private JButton bPowerOfTen = new JButton("10^n");

private JButton bLog = new JButton("log");

private JButton bLn = new JButton("ln");

private JButton bAbs = new JButton("abs");

private JButton bExit = new JButton("EXIT");

//------------container variabl

LOAN AMOUNT

import java.util.Scanner;

public class loan {

public static void main(String[] args) {

Scanner input = new Scanner(System.in);

// Prompt the user to enter the loan amount and

// loan period in number of years

System.out.print("Loan Amount: ");

double loanAmount = input.nextDouble();

System.out.print("Number of Years: ");

int numberOfYears = input.nextInt();


// Display table header

System.out.println(

"Interest Rate Monthly Payment Total Payment");

// Display table with interest rates

for (double i = 5.0; i <= 8; i += 0.125) {

System.out.printf("%-5.3f", i);

System.out.print("% ");

double monthlyInterestRate = i / 1200;

double monthlyPayment = loanAmount * monthlyInterestRate / (1

- 1 / Math.pow(1 + monthlyInterestRate, numberOfYears * 6));

System.out.printf("%-19.2f", monthlyPayment);

System.out.printf("%-8.2f\n",(monthlyPayment * 6) * numberOfYears);

TEXT EDITOR
// Java Program to create a text editor using java
import java.awt.*;

import javax.swing.*;

import java.io.*;

import java.awt.event.*;

import javax.swing.plaf.metal.*;

import javax.swing.text.*;

class editor extends JFrame implements ActionListener {

// Text component

JTextArea t;

// Frame

JFrame f;

// Constructor

editor()

// Create a frame

f = new JFrame("editor");

try {

// Set metal look and feel

UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");

// Set theme to ocean

MetalLookAndFeel.setCurrentTheme(new OceanTheme());

catch (Exception e) {

}
// Text component

t = new JTextArea();

// Create a menubar

JMenuBar mb = new JMenuBar();

// Create amenu for menu

JMenu m1 = new JMenu("File");

// Create menu items

JMenuItem mi1 = new JMenuItem("New");

JMenuItem mi2 = new JMenuItem("Open");

JMenuItem mi3 = new JMenuItem("Save");

JMenuItem mi9 = new JMenuItem("Exit");

// Add action listener

mi1.addActionListener(this);

mi2.addActionListener(this);

mi3.addActionListener(this);

mi9.addActionListener(this);

m1.add(mi1);

m1.add(mi2);

m1.add(mi3);

m1.add(mi9);

// Create amenu for menu

JMenu m2 = new JMenu("Edit");


// Create menu items

JMenuItem mi4 = new JMenuItem("cut");

JMenuItem mi5 = new JMenuItem("copy");

JMenuItem mi6 = new JMenuItem("paste");

JMenuItem mi7 = new JMenuItem("select All");

// Add action listener

mi4.addActionListener(this);

mi5.addActionListener(this);

mi6.addActionListener(this);

mi7.addActionListener(this);

m2.add(mi4);

m2.add(mi5);

m2.add(mi6);

m2.add(mi7);

JMenu m3 = new JMenu("Help");

JMenuItem mi8 = new JMenuItem("About");

mi8.addActionListener(this);

m3.add(mi8);

mb.add(m1);

mb.add(m2);

mb.add(m3);

f.setJMenuBar(mb);

f.add(t);

f.setSize(500, 500);
f.show();

// If a button is pressed

public void actionPerformed(ActionEvent e)

String s = e.getActionCommand();

if (s.equals("cut")) {

t.cut();

else if (s.equals("copy")) {

t.copy();

else if (s.equals("paste")) {

t.paste();

else if (s.equals("select All")) {

t.selectAll();

else if (s.equals("Save")) {

// Create an object of JFileChooser class

JFileChooser j = new JFileChooser("f:");

// Invoke the showsSaveDialog function to show the save dialog

int r = j.showSaveDialog(null);

if (r == JFileChooser.APPROVE_OPTION) {
// Set the label to the path of the selected directory

File fi = new File(j.getSelectedFile().getAbsolutePath());

try {

// Create a file writer

FileWriter wr = new FileWriter(fi, false);

// Create buffered writer to write

BufferedWriter w = new BufferedWriter(wr);

// Write

w.write(t.getText());

w.flush();

w.close();

catch (Exception evt) {

JOptionPane.showMessageDialog(f, evt.getMessage());

// If the user cancelled the operation

else

JOptionPane.showMessageDialog(f, "the user cancelled the operation");

else if (s.equals("Open")) {

// Create an object of JFileChooser class

JFileChooser j = new JFileChooser("f:");


// Invoke the showsOpenDialog function to show the save dialog

int r = j.showOpenDialog(null);

// If the user selects a file

if (r == JFileChooser.APPROVE_OPTION) {

// Set the label to the path of the selected directory

File fi = new File(j.getSelectedFile().getAbsolutePath());

try {

// String

String s1 = "", sl = "";

// File reader

FileReader fr = new FileReader(fi);

// Buffered reader

BufferedReader br = new BufferedReader(fr);

// Initialize sl

sl = br.readLine();

// Take the input from the file

while ((s1 = br.readLine()) != null) {

sl = sl + "\n" + s1;

// Set the text

t.setText(sl);

}
catch (Exception evt) {

JOptionPane.showMessageDialog(f, evt.getMessage());

// If the user cancelled the operation

else

JOptionPane.showMessageDialog(f, "the user cancelled the operation");

else if (s.equals("New")) {

t.setText("");

else if (s.equals("About")) {

t.setText("INFORMATION ABOUT THIS TEXT EDITOR\n"

+"New submenu: to create new text editor;\n"

+ "Save is for saving the file;\n"

+ "Open will be for openning the existing file and \n"

+ "Exit for closing the text editor.\n");

else if (s.equals("Exit")) {

f.setVisible(false);

// Main class

public static void main(String args[])

editor e = new editor();

}
es---------------

private JTextField tfDisplay = new JTextField();//result displaying screen

private JTextField tfRawInput = new JTextField();

private String sRawInput = "";

private String sDisplay = "";//Input string

private boolean isPlus = true;//Is the sign of the operand is plus

private boolean isPoint = false;//is there is decimal point in the operands

private boolean isOperation = false;

private double number1 = 0;// 1st operand

private double number2 = 0;// 2nd operand

private double result = 0;// Result

private char operation = ' ';// Operation

static Color windowColor = new Color(110, 119, 129);//Color of container window

//==================Default Constructor to Design the layout of the


calculator===========================

public CalculatorLayout()

setBackground(windowColor);

setLayout(null);

JPanel pScreen1 = new JPanel(); // The screen that display the input

JPanel pScreen2 = new JPanel(); // The screen that show the result

JPanel pKeypad1 = new JPanel(); // The keypad that contain the common keys

JPanel pKeypad2 = new JPanel(); // The keypad that contains the scientific keys.

//---------------------Fonts & Colors------------------------

Font fontResDisplay = new Font("Times New Roman", Font.BOLD, 35);//Font for


displaying result
Font fontKeypad = new Font("Times New Roman", Font.PLAIN, 20);//Font for
key character

Font fontKeypad1 = new Font("Times New Roman", Font.PLAIN, 15);//Font for


key character

Color screenColor = new Color(91, 178, 91);

Color numberKeyColor = new Color(212, 212, 212);

Color equalColor = new Color(63, 132, 243);

Color exitColor = new Color(224, 67, 67);

Color otherColor = new Color(247, 247, 247);

Color copyRightColor = new Color(0, 0, 255);

//===========================Designing the Result screen of the calculator


===========================

add(pScreen1).setBounds(0, 0, 340, 30);

pScreen1.add(tfRawInput);

pScreen1.setLayout(null);

tfRawInput.setBounds(0, 0, 340, 30);

tfRawInput.setHorizontalAlignment(JTextField.LEFT);

tfRawInput.setFont(new Font("Times New Roman", Font.PLAIN, 20));

tfRawInput.setText("0");

tfRawInput.setEditable(false);

tfRawInput.setBackground(screenColor);

tfRawInput.setForeground(Color.BLACK);

//===========================Designing the Result screen of the calculator


===========================

add(pScreen2).setBounds(0, 30, 340, 50);

pScreen2.add(tfDisplay);

pScreen2.setLayout(null);

tfDisplay.setBounds(0, 0, 340, 50);


tfDisplay.setHorizontalAlignment(JTextField.RIGHT);

tfDisplay.setFont(fontResDisplay);

tfDisplay.setText("0");

tfDisplay.setEditable(false);

tfDisplay.setBackground(screenColor);

tfDisplay.setForeground(Color.BLACK);

//==========================Designing the keypad1(Common Keys) of the


calculator =====================

add(pKeypad1).setBounds(0, 250, 343, 190);

pKeypad1.setLayout(null);

pKeypad1.setBackground(windowColor);

//------------setting font, color and style of the common keys-------

bOne.setFont(fontKeypad); bOne.setBackground(numberKeyColor);
bOne.setFocusable(false);

bTwo.setFont(fontKeypad); bTwo.setBackground(numberKeyColor);
bTwo.setFocusable(false);

bThree.setFont(fontKeypad); bThree.setBackground(numberKeyColor);
bThree.setFocusable(false);

bFour.setFont(fontKeypad); bFour.setBackground(numberKeyColor);
bFour.setFocusable(false);

bFive.setFont(fontKeypad); bFive.setBackground(numberKeyColor);
bFive.setFocusable(false);

bSix.setFont(fontKeypad); bSix.setBackground(numberKeyColor);
bSix.setFocusable(false);

bSeven.setFont(fontKeypad); bSeven.setBackground(numberKeyColor);
bSeven.setFocusable(false);

bEight.setFont(fontKeypad); bEight.setBackground(numberKeyColor);
bEight.setFocusable(false);

bNine.setFont(fontKeypad); bNine.setBackground(numberKeyColor);
bNine.setFocusable(false);
bZero.setFont(fontKeypad); bZero.setBackground(numberKeyColor);
bZero.setFocusable(false);

bAdd.setFont(fontKeypad); bAdd.setBackground(otherColor);
bAdd.setFocusable(false);

bSub.setFont(fontKeypad); bSub.setBackground(otherColor);
bSub.setFocusable(false);

bMul.setFont(fontKeypad); bMul.setBackground(otherColor);
bMul.setFocusable(false);

bDiv.setFont(fontKeypad); bDiv.setBackground(otherColor);
bDiv.setFocusable(false);

bPoint.setFont(fontKeypad); bPoint.setBackground(numberKeyColor);
bPoint.setFocusable(false);

bEqual.setFont(new Font("Times New Roman", Font.PLAIN, 40));


bEqual.setBackground(equalColor); bEqual.setFocusable(false);

bDel.setFont(fontKeypad1); bDel.setBackground(Color.ORANGE);
bDel.setFocusable(false);

bClear.setFont(fontKeypad); bClear.setBackground(exitColor);
bClear.setFocusable(false);

bSquare.setFont(fontKeypad); bSquare.setBackground(otherColor);
bSquare.setFocusable(false);

bSqrt.setFont(fontKeypad); bSqrt.setBackground(otherColor);
bSqrt.setFocusable(false);

bCube.setFont(fontKeypad); bCube.setBackground(otherColor);
bCube.setFocusable(false);

bPercent.setFont(fontKeypad); bPercent.setBackground(otherColor);
bPercent.setFocusable(false);

bMod.setFont(new Font("Times New Roman", Font.PLAIN, 10));


bMod.setBackground(otherColor); bMod.setFocusable(false);

bOneByN.setFont(fontKeypad1); bOneByN.setBackground(otherColor);
bOneByN.setFocusable(false);

bPlusMinus.setFont(fontKeypad);
bPlusMinus.setBackground(numberKeyColor); bPlusMinus.setFocusable(false);

//-----------------------------placing the common keys-------------------------------------


// 1st row

//pKeypad1.add(bDel).setBounds(226, 0, 54, 38);


pKeypad1.add(bClear).setBounds(280, 0, 54, 38);

// 2nd row

pKeypad1.add(bSeven).setBounds(10, 0, 54,
38);pKeypad1.add(bEight).setBounds(64, 0, 54, 38);pKeypad1.add(bNine).setBounds(118, 0, 54, 38);

pKeypad1.add(bMul).setBounds(172, 0, 54,
38);pKeypad1.add(bDiv).setBounds(226, 0, 54, 38);pKeypad1.add(bSquare).setBounds(280, 0, 54, 38);

// 3rd row

pKeypad1.add(bFour).setBounds(10, 38, 54,


38);pKeypad1.add(bFive).setBounds(64, 38, 54, 38);pKeypad1.add(bSix).setBounds(118, 38, 54, 38);

pKeypad1.add(bAdd).setBounds(172, 38, 54,


38);pKeypad1.add(bSub).setBounds(226, 38, 54, 38);pKeypad1.add(bCube).setBounds(280, 38, 54, 38);

// 4th row

pKeypad1.add(bOne).setBounds(10, 76, 54,


38);pKeypad1.add(bTwo).setBounds(64, 76, 54, 38);pKeypad1.add(bThree).setBounds(118, 76, 54, 38);

pKeypad1.add(bEqual).setBounds(172, 76, 108,


38);pKeypad1.add(bMod).setBounds(280, 76, 54, 38);

// 5th row

pKeypad1.add(bZero).setBounds(10, 114, 54,


38);pKeypad1.add(bPoint).setBounds(64, 114, 54, 38);pKeypad1.add(bPlusMinus).setBounds(118, 114,
54, 38);

pKeypad1.add(bOneByN).setBounds(172, 114, 54,


38);pKeypad1.add(bPercent).setBounds(226, 114, 54, 38);pKeypad1.add(bSqrt).setBounds(280, 114, 54,
38);

//==========================Designing the keypad2(scientific Keys) of the


calculator =====================

add(pKeypad2).setBounds(0, 100, 343, 145);

pKeypad2.setLayout(null);

pKeypad2.setBackground(windowColor);
//----------------------copyright tag-------------------------------------------------------

//JLabel copyRight = new JLabel("\u00A9 2013 CI- Soft. Tech.");

//copyRight.setForeground(copyRightColor);

//pKeypad2.add(copyRight).setBounds(205, 130, 150, 15);

//-----------------------------placing the Scientific keys-------------------------------------

// 1st row

pKeypad2.add(bDel).setBounds(226, 0, 54, 38);


pKeypad2.add(bClear).setBounds(280, 0, 54, 38);

pKeypad2.add(bSin).setBounds(10, 38, 65,


38);pKeypad2.add(bCos).setBounds(75, 38, 65, 38);pKeypad2.add(bTan).setBounds(140, 38, 65, 38);

pKeypad2.add(bLog).setBounds(205, 38, 65,


38);pKeypad2.add(bLn).setBounds(270, 38, 64, 38);

// 2nd row

pKeypad2.add(bAsin).setBounds(10, 76, 65,


38);pKeypad2.add(bAcos).setBounds(75, 76, 65, 38);pKeypad2.add(bAtan).setBounds(140, 76, 65, 38);

pKeypad2.add(bPowerOfTen).setBounds(205, 76, 65,


38);pKeypad2.add(bAbs).setBounds(270, 76, 64, 38);

// 3rd row

pKeypad2.add(bSinH).setBounds(10, 114, 65,


38);pKeypad2.add(bCosH).setBounds(75, 114, 65, 38);pKeypad2.add(bTanH).setBounds(140, 114, 65,
38);

pKeypad2.add(bExit).setBounds(205, 114, 130, 38);

//------------setting font, color and style of the common keys-------

bSin.setFont(fontKeypad); bSin.setBackground(otherColor);
bSin.setFocusable(false);

bCos.setFont(fontKeypad); bCos.setBackground(otherColor);
bCos.setFocusable(false);
bTan.setFont(fontKeypad); bTan.setBackground(otherColor);
bTan.setFocusable(false);

bAsin.setFont(fontKeypad1); bAsin.setBackground(otherColor);
bAsin.setFocusable(false);

bAcos.setFont(fontKeypad1); bAcos.setBackground(otherColor);
bAcos.setFocusable(false);

bAtan.setFont(fontKeypad1); bAtan.setBackground(otherColor);
bAtan.setFocusable(false);

bSinH.setFont(fontKeypad1); bSinH.setBackground(otherColor);
bSinH.setFocusable(false);

bCosH.setFont(fontKeypad1); bCosH.setBackground(otherColor);
bCosH.setFocusable(false);

bTanH.setFont(fontKeypad1); bTanH.setBackground(otherColor);
bTanH.setFocusable(false);

bLog.setFont(fontKeypad); bLog.setBackground(otherColor);
bLog.setFocusable(false);

bLn.setFont(fontKeypad); bLn.setBackground(otherColor);
bLn.setFocusable(false);

bAbs.setFont(fontKeypad); bAbs.setBackground(otherColor);
bAbs.setFocusable(false);

bExit.setFont(fontKeypad); bExit.setBackground(exitColor);
bExit.setFocusable(false);

bPowerOfTen.setFont(fontKeypad1);
bPowerOfTen.setBackground(otherColor); bPowerOfTen.setFocusable(false);

// ======================================Adding actionListener
=======================================

//common keys

bOne.addActionListener(this);

bTwo.addActionListener(this);

bThree.addActionListener(this);

bFour.addActionListener(this);

bFive.addActionListener(this);
bSix.addActionListener(this);

bSeven.addActionListener(this);

bEight.addActionListener(this);

bNine.addActionListener(this);

bZero.addActionListener(this);

bAdd.addActionListener(this);

bSub.addActionListener(this);

bMul.addActionListener(this);

bDiv.addActionListener(this);

bPoint.addActionListener(this);

bEqual.addActionListener(this);

bDel.addActionListener(this);

bClear.addActionListener(this);

bSquare.addActionListener(this);

bSqrt.addActionListener(this);

bCube.addActionListener(this);

bPercent.addActionListener(this);

bMod.addActionListener(this);

bOneByN.addActionListener(this);

bPlusMinus.addActionListener(this);

//scientific keys

bSin.addActionListener(this);

bCos.addActionListener(this);

bTan.addActionListener(this);

bAsin.addActionListener(this);

bAcos.addActionListener(this);

bAtan.addActionListener(this);

bSinH.addActionListener(this);

bCosH.addActionListener(this);
bTanH.addActionListener(this);

bPowerOfTen.addActionListener(this);

bLog.addActionListener(this);

bLn.addActionListener(this);

bAbs.addActionListener(this);

bExit.addActionListener(this);

//=================================Main
method=============================

public static void main(String[] CHAND)

CalculatorLayout frame = new CalculatorLayout();

frame.setTitle("CI- Calculator");

frame.setSize(350, 450);

frame.getContentPane().setBackground(windowColor);

frame.setLocationRelativeTo(null);

//frame.setMaximizedBounds(new Rectangle(300, 200));

frame.setResizable(false);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

//==============================ActionListener of All keys


===========================

@Override

public void actionPerformed(ActionEvent e)

{
if (e.getSource() == bOne)

if(operation == '=')

sDisplay = "1";

sRawInput = "1";

tfRawInput.setText(sRawInput);

operation = ' ';

else

sDisplay = sDisplay + "1";

sRawInput += "1";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bTwo)

if(operation == '=')

sDisplay = "2";

sRawInput = "2";

tfRawInput.setText(sRawInput);

operation = ' ';

else

sDisplay = sDisplay + "2";

sRawInput += "2";
tfRawInput.setText(sRawInput);

else if (e.getSource() == bThree)

if(operation == '=')

sDisplay = "3";

sRawInput = "3";

tfRawInput.setText(sRawInput);

operation = ' ';

else

sDisplay = sDisplay + "3";

sRawInput += "3";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bFour)

if(operation == '=')

sDisplay = "4";

sRawInput = "4";

tfRawInput.setText(sRawInput);

operation = ' ';

else
{

sDisplay = sDisplay + "4";

sRawInput += "4";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bFive)

if(operation == '=')

sDisplay = "5";

sRawInput = "5";

tfRawInput.setText(sRawInput);

operation = ' ';

else

sDisplay = sDisplay + "5";

sRawInput += "5";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bSix)

if(operation == '=')

sDisplay = "6";

sRawInput = "6";

tfRawInput.setText(sRawInput);
operation = ' ';

else

sDisplay = sDisplay + "6";

sRawInput += "6";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bSeven)

if(operation == '=')

sDisplay = "7";

sRawInput = "7";

tfRawInput.setText(sRawInput);

operation = ' ';

else

sDisplay = sDisplay + "7";

sRawInput += "7";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bEight)

if(operation == '=')

{
sDisplay = "8";

sRawInput = "8";

tfRawInput.setText(sRawInput);

operation = ' ';

else

sDisplay = sDisplay + "8";

sRawInput += "8";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bNine)

if(operation == '=')

sDisplay = "9";

sRawInput = "9";

tfRawInput.setText(sRawInput);

operation = ' ';

else

sDisplay = sDisplay + "9";

sRawInput += "9";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bZero)


{

if(sDisplay.equals(""))//zero at first

sDisplay = "0";

sRawInput += "0";

tfRawInput.setText(sRawInput);

else

sDisplay = sDisplay + "0";

sRawInput += "0";

tfRawInput.setText(sRawInput);

else if (e.getSource() == bPoint) ///when bPoint is clicked

if(sDisplay.equals(""))//bPoint at starting of a number

sDisplay = "0.";

sRawInput += "0.";

tfRawInput.setText(sRawInput);

else if(!isPoint)//when there is no bPoint till now then just add the
bPoint

sDisplay = sDisplay + ".";

sRawInput += ".";

tfRawInput.setText(sRawInput);

}
isPoint = true;//when the bPoint button is clicked once set the bPoint
flag to true

else if(e.getSource() == bPlusMinus && !sDisplay.equals("") &&


!isOperation)//plus minus(sign) button

if(isPlus)

sDisplay = "-" + sDisplay;

sRawInput = sDisplay;

tfRawInput.setText(sRawInput);

isPlus = false;

else

sDisplay = sDisplay.substring(1, sDisplay.length());

sRawInput = sDisplay.substring(1, sDisplay.length());

tfRawInput.setText(sRawInput);

isPlus = true;

else if (e.getSource() == bAdd && (!sDisplay.equals("") || operation == '=')) // +


button is clicked and input is not empty

if(!isOperation)//to check if plus without number1

number1 = Double.parseDouble(sDisplay);

sDisplay = "";

operation = '+';

isPlus = true;
sRawInput += " + ";

tfRawInput.setText(sRawInput);

if(isPoint)//when there is any bPoint number or any bDivision


operation, there may be a bPoint in the result

tfDisplay.setText(""+number1);

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)number1);

else if(isOperation && operation != '=')

number2 = Double.parseDouble(sDisplay);

if(operation == '+')

result = number1 + number2;

else if(operation == '-')

result = number1 - number2;

else if(operation == '*')

result = number1 * number2;

else if(operation == '/')


{

result = number1 / number2;

else if(operation == '%')

result = number1 % number2;

else

result = number2;

String temp = "";

if(isPoint || operation == '/')//when there is any bPoint number


or any bDivision operation, there may be a bPoint in the result

tfDisplay.setText(""+result);

temp = ""+result;

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

operation = '+';

sDisplay = "";

number1 = result;

isPlus = true;

isPoint = false;

isOperation = true;
sRawInput += " + ";

tfRawInput.setText(sRawInput);

sRawInput = temp + " + ";

else if(operation == '=')

sDisplay = "";

operation = '+';

isPlus = true;

isOperation = true;

sRawInput += " + ";

tfRawInput.setText(sRawInput);

isOperation = true;

else if (e.getSource() == bSub && (!sDisplay.equals("") || operation == '=')) // -


button is clicked and input is not empty

if(!isOperation)//to check if plus without number1

number1 = Double.parseDouble(sDisplay);

sDisplay = "";

operation = '-';

isPlus = true;

sRawInput += " - ";

tfRawInput.setText(sRawInput);

if(isPoint)//when there is any bPoint number or any bDivision


operation, there may be a bPoint in the result

{
tfDisplay.setText(""+number1);

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)number1);

else if(isOperation && operation != '=')

number2 = Double.parseDouble(sDisplay);

if(operation == '+')

result = number1 + number2;

else if(operation == '-')

result = number1 - number2;

else if(operation == '*')

result = number1 * number2;

else if(operation == '/')

result = number1 / number2;

else if(operation == '%')

{
result = number1 % number2;

else

result = number2;

String temp = "";

if(isPoint || operation == '/')//when there is any bPoint number


or any bDivision operation, there may be a bPoint in the result

tfDisplay.setText(""+result);

temp = ""+result;

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

operation = '-';

sDisplay = "";

number1 = result;

isPlus = true;

isPoint = false;

isOperation = true;

sRawInput += " - ";

tfRawInput.setText(sRawInput);

sRawInput = temp + " + ";

else if(operation == '=')


{

sDisplay = "";

operation = '-';

isPlus = true;

isOperation = true;

sRawInput += " - ";

tfRawInput.setText(sRawInput);

isOperation = true;

else if (e.getSource() == bMul && (!sDisplay.equals("") || operation == '=')) // *


button is clicked and input is not empty

if(!isOperation)//to check if plus without number1

number1 = Double.parseDouble(sDisplay);

sDisplay = "";

operation = '*';

isPlus = true;

sRawInput += " \u00D7 ";

tfRawInput.setText(sRawInput);

if(isPoint)//when there is any bPoint number or any bDivision


operation, there may be a bPoint in the result

tfDisplay.setText(""+number1);

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)number1);
}

else if(isOperation && operation != '=')

number2 = Double.parseDouble(sDisplay);

if(operation == '+')

result = number1 + number2;

else if(operation == '-')

result = number1 - number2;

else if(operation == '*')

result = number1 * number2;

else if(operation == '/')

result = number1 / number2;

else if(operation == '%')

result = number1 % number2;

else

result = number2;
}

String temp = "";

if(isPoint || operation == '/')//when there is any bPoint number


or any bDivision operation, there may be a bPoint in the result

tfDisplay.setText(""+result);

temp = ""+result;

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

operation = '*';

sDisplay = "";

number1 = result;

isPlus = true;

isPoint = false;

isOperation = true;

sRawInput += " \u00D7 ";

tfRawInput.setText(sRawInput);

sRawInput = temp + " \u00D7 ";

else if(operation == '=')

sDisplay = "";

operation = '*';

isPlus = true;

isOperation = true;
sRawInput += " \u00D7 ";

tfRawInput.setText(sRawInput);

isOperation = true;

else if (e.getSource() == bDiv && (!sDisplay.equals("") || operation == '=')) //


bDivision button is clicked and input is not empty

if(!isOperation)//to check if plus without number1

number1 = Double.parseDouble(sDisplay);

sDisplay = "";

operation = '/';

isPlus = true;

sRawInput += " / ";

tfRawInput.setText(sRawInput);

if(isPoint)//when there is any bPoint number or any bDivision


operation, there may be a bPoint in the result

tfDisplay.setText(""+number1);

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)number1);

else if(isOperation && operation != '=')

number2 = Double.parseDouble(sDisplay);
if(operation == '+')

result = number1 + number2;

else if(operation == '-')

result = number1 - number2;

else if(operation == '*')

result = number1 * number2;

else if(operation == '/')

result = number1 / number2;

else if(operation == '%')

result = number1 % number2;

else

result = number2;

String temp = "";

if(isPoint || operation == '/')//when there is any bPoint number


or any bDivision operation, there may be a bPoint in the result

{
tfDisplay.setText(""+result);

temp = ""+result;

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

operation = '*';

sDisplay = "";

number1 = result;

isPlus = true;

isPoint = false;

isOperation = true;

sRawInput += " / ";

tfRawInput.setText(sRawInput);

sRawInput = temp + " / ";

else if(operation == '=')

sDisplay = "";

operation = '/';

isPlus = true;

isOperation = true;

sRawInput += " / ";

tfRawInput.setText(sRawInput);

isOperation = true;

}
else if (e.getSource() == bMod && (!sDisplay.equals("") || operation ==
'='))//Modules button

if(!isOperation)//to check if plus without number1

number1 = Double.parseDouble(sDisplay);

sDisplay = "";

operation = '%';

isPlus = true;

sRawInput += " mod ";

tfRawInput.setText(sRawInput);

if(isPoint)//when there is any bPoint number or any bDivision


operation, there may be a bPoint in the result

tfDisplay.setText(""+number1);

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)number1);

else if(isOperation && operation != '=')

number2 = Double.parseDouble(sDisplay);

if(operation == '+')

result = number1 + number2;

}
else if(operation == '-')

result = number1 - number2;

else if(operation == '*')

result = number1 * number2;

else if(operation == '/')

result = number1 / number2;

else if(operation == '%')

result = number1 % number2;

else

result = number2;

String temp = "";

if(isPoint || operation == '/')//when there is any bPoint number


or any bDivision operation, there may be a bPoint in the result

tfDisplay.setText(""+result);

temp = ""+result;

else if(!isPoint)//when there is no bPoint in the result

{
tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

operation = '%';

sDisplay = "";

number1 = result;

isPlus = true;

isPoint = false;

isOperation = true;

sRawInput += " mod ";

tfRawInput.setText(sRawInput);

sRawInput = temp + " * ";

else if(operation == '=')

sDisplay = "";

operation = '%';

isPlus = true;

isOperation = true;

sRawInput += " mod ";

tfRawInput.setText(sRawInput);

isOperation = true;

else if (e.getSource() == bEqual && !sDisplay.equals(""))//when bEqual button is


clicked and the input is not empty

number2 = Double.parseDouble(sDisplay);
if(operation == '+')

result = number1 + number2;

else if(operation == '-')

result = number1 - number2;

else if(operation == '*')

result = number1 * number2;

else if(operation == '/')

result = number1 / number2;

else if(operation == '%')

result = number1 % number2;

else

result = number2;

String temp = "";

if(isPoint || operation == '/')//when there is any bPoint number or any


bDivision operation, there may be a bPoint in the result

tfDisplay.setText(""+result);
temp = ""+result;

else if(!isPoint)//when there is no bPoint in the result

tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

sDisplay = "";

number1 = result;

isPlus = true;

isPoint = false;

isOperation = true;

sRawInput += " = ";

tfRawInput.setText(sRawInput);

sRawInput = temp;

operation = '=';

else if (e.getSource() == bDel && !sDisplay.equals(""))//DE button

sDisplay = sDisplay.substring(0, sDisplay.length()-1);

sRawInput = sRawInput.substring(0, sRawInput.length()-1);

if(sRawInput.equals(""))//after deleting the last digit

//tfDisplay.setText("0");

tfRawInput.setText("0");

else

//tfDisplay.setText(sDisplay);
tfRawInput.setText(sRawInput);

else if (e.getSource() == bClear)//Clear button

number1 = number2 = result = 0;

sDisplay = "";

operation = ' ';

tfDisplay.setText("0");

isPoint = false;

isPlus = true;

isOperation = false;

sRawInput = "";

tfRawInput.setText("0");

else if (e.getSource() == bSquare && !sDisplay.equals(""))//Square button

number1 = Double.parseDouble(sDisplay);

result = Math.pow(number1, 2);

String temp = "";

if(!isPoint)

tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

else

tfDisplay.setText(""+result);

temp = ""+result;
}

sRawInput += "^2 = ";

tfRawInput.setText(sRawInput);

sRawInput = temp;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = false;

isOperation = true;

isPlus = true;

else if (e.getSource() == bSqrt && !sDisplay.equals(""))//root button

number1 = Double.parseDouble(sDisplay);

result = Math.sqrt(number1);

sRawInput = "\u221A" + sRawInput;

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if (e.getSource() == bCube && !sDisplay.equals("")) //Cube button

number1 = Double.parseDouble(sDisplay);
result = Math.pow(number1, 3);

String temp = "";

if(!isPoint)

tfDisplay.setText(""+(long)result);

temp = ""+(long)result;

else

tfDisplay.setText(""+result);

temp = ""+result;

sRawInput +="^3 = ";

tfRawInput.setText(sRawInput);

sRawInput = temp;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = false;

isOperation = true;

isPlus = true;

else if (e.getSource() == bOneByN && !sDisplay.equals(""))// 1/n button

number1 = Double.parseDouble(sDisplay);

result = 1 / number1;

if(isPoint)

{
sRawInput = "1 / " + number1;

else

sRawInput = "1 / " + (long)number1;

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sDisplay = "";

sRawInput = ""+result;

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bPercent && !sDisplay.equals("") && operation=='*')//


% button is pressed

number2 = Double.parseDouble(sDisplay);

result = number1 * (number2 / 100);

sRawInput = number1+" \u00D7 "+number2+"%";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sDisplay = "";

number1 = result;

operation = '=';

isPlus = true;

isOperation = true;
isPoint = true;

sRawInput = ""+result;

else if(e.getSource() == bSin && !sDisplay.equals(""))//sin function

number1 = Double.parseDouble(sDisplay);

if(number1 == 30)

result = Math.sin(Math.toRadians(number1)) +
0.0000000000000001;

else

result = Math.sin(Math.toRadians(number1));

sRawInput = "sin("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bCos && !sDisplay.equals(""))//cosine function

number1 = Double.parseDouble(sDisplay);
if(number1 == 60)

result = Math.cos(Math.toRadians(number1)) -
0.0000000000000001;

else if (number1 == 90)

result = 0;

else

result = Math.cos(Math.toRadians(number1));

sRawInput = "cos("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bTan && !sDisplay.equals(""))//tan function

number1 = Double.parseDouble(sDisplay);

if(number1 == 45)

{
result = Math.tan(Math.toRadians(number1)) +
0.0000000000000001;

else if(number1 == 90)

result = 0;

tfDisplay.setText("Invalid");

else

result = Math.tan(Math.toRadians(number1));

sRawInput = "tan("+sRawInput+")";

tfRawInput.setText(sRawInput);

if(number1 != 90)

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bSinH && !sDisplay.equals(""))//sinh function

number1 = Double.parseDouble(sDisplay);
result = Math.sinh(Math.toRadians(number1));

sRawInput = "sinh("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bCosH && !sDisplay.equals(""))//cosh function

number1 = Double.parseDouble(sDisplay);

result = Math.cosh(Math.toRadians(number1));

sRawInput = "cosh("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bTanH && !sDisplay.equals(""))//tanh function

{
number1 = Double.parseDouble(sDisplay);

result = Math.tanh(Math.toRadians(number1));

sRawInput = "tanH("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bAsin && !sDisplay.equals(""))//asin function

number1 = Double.parseDouble(sDisplay);

result = Math.asin(Math.toRadians(number1));

sRawInput = "asin("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bAcos && !sDisplay.equals(""))//acos function


{

number1 = Double.parseDouble(sDisplay);

result = Math.acos(Math.toRadians(number1));

sRawInput = "acos("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bAtan && !sDisplay.equals(""))//atan function

number1 = Double.parseDouble(sDisplay);

result = Math.atan(Math.toRadians(number1));

sRawInput = "atan("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

}
else if(e.getSource() == bLog && !sDisplay.equals(""))//log function

number1 = Double.parseDouble(sDisplay);

result = Math.log10(number1);

sRawInput = "log"+sRawInput;

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bLn && !sDisplay.equals(""))//ln function

number1 = Double.parseDouble(sDisplay);

result = Math.log(number1);

sRawInput = "ln"+sRawInput;

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;
}

else if(e.getSource() == bAbs && !sDisplay.equals(""))//abs function

number1 = Double.parseDouble(sDisplay);

result = Math.abs(number1);

sRawInput = "abs("+sRawInput+")";

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;

isOperation = true;

isPlus = true;

else if(e.getSource() == bPowerOfTen && !sDisplay.equals(""))//power of ten


function

number1 = Double.parseDouble(sDisplay);

result = Math.pow(10, number1);

sRawInput = "10^"+sRawInput;

tfRawInput.setText(sRawInput);

tfDisplay.setText(""+result);

sRawInput = ""+result;

sDisplay = "";

number1 = result;

operation = '=';

isPoint = true;
isOperation = true;

isPlus = true;

else if(e.getSource() == bExit)//exit button

System.exit(0);

CLOCK;
import java.awt.*;

import java.awt.event.*;

import java.util.Calendar;

import java.util.GregorianCalendar;

import javax.swing.*;

public class Exercise07 extends JApplet {

private ClockPanel clockPanel3 = new ClockPanel();

private static final long serialVersionUID = 1L;

public static void main(String[] args) {

Exercise07 applet = new Exercise07();

JFrame frame = new JFrame();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Exercise07");

frame.add(applet, BorderLayout.CENTER);

frame.setSize(900, 400);

frame.setLocationRelativeTo(null);

frame.setVisible(true);

public Exercise07() {

JPanel panel1 = new JPanel(new GridLayout(1, 3));

panel1.add(clockPanel3);

add(panel1, BorderLayout.CENTER);

JPanel panel2 = new JPanel();

JButton jButton1 = new JButton("");

JLabel jButtonb1 = new JLabel("");

jButton1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

clockPanel3.start();

});

jButton1.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

clockPanel3.stop();

});
//panel2.add(jButtonb1);

//panel2.add(jButton1);

add(panel2, BorderLayout.SOUTH);

class ClockPanel extends JPanel implements Runnable {

private JButton jbtStart = new JButton("Start");

private JButton jbtStop = new JButton("Stop");

private boolean isRunning = true;

private static final long serialVersionUID = 1L;

private StillClock clock = new StillClock();

public void stop() {

isRunning = false;

public void start() {

isRunning = true;

public ClockPanel() {

setLayout(new BorderLayout());

JPanel panel1 = new JPanel();

jbtStop.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

isRunning = false;

} );
panel1.add(jbtStop);

jbtStart.addActionListener(new ActionListener() {

@Override

public void actionPerformed(ActionEvent e) {

isRunning = true;

} );

panel1.add(jbtStart);

add(panel1, BorderLayout.SOUTH);

add(clock, BorderLayout.CENTER);

Thread thread = new Thread(this);

thread.start();

@Override

public void run() {

try {

while (true) {

Thread.sleep(1000);

if(isRunning) {

clock.setCurrentTime();

clock.repaint();

} catch (InterruptedException e) {

e.printStackTrace();

}
class StillClock extends JPanel {

private static final long serialVersionUID = 1L;

private int hour;

private int minute;

private int second;

/** Construct a default clock with the current time */

public StillClock() {

setCurrentTime();

/** Construct a clock with specified hour, minute, and second */

public StillClock(int hour, int minute, int second) {

this.hour = hour;

this.minute = minute;

this.second = second;

/** Return hour */

public int getHour() {

return hour;

/** Set a new hour */

public void setHour(int hour) {

this.hour = hour;

repaint();

}
/** Return minute */

public int getMinute() {

return minute;

/** Set a new minute */

public void setMinute(int minute) {

this.minute = minute;

repaint();

/** Return second */

public int getSecond() {

return second;

/** Set a new second */

public void setSecond(int second) {

this.second = second;

repaint();

@Override

/** Draw the clock */

protected void paintComponent(Graphics g) {

super.paintComponent(g);

// Initialize clock parameters


int clockRadius = (int) (Math.min(getWidth(), getHeight()) * 0.8 * 0.5);

int xCenter = getWidth() / 2;

int yCenter = getHeight() / 2;

// Draw circle

g.setColor(Color.black);

g.drawOval(xCenter - clockRadius, yCenter - clockRadius,

2 * clockRadius, 2 * clockRadius);

g.drawString("12", xCenter - 5, yCenter - clockRadius + 12);

g.drawString("9", xCenter - clockRadius + 3, yCenter + 5);

g.drawString("3", xCenter + clockRadius - 10, yCenter + 3);

g.drawString("6", xCenter - 3, yCenter + clockRadius - 3);

// Draw second hand

int sLength = (int) (clockRadius * 0.8);

int xSecond = (int) (xCenter + sLength

* Math.sin(second * (2 * Math.PI / 60)));

int ySecond = (int) (yCenter - sLength

* Math.cos(second * (2 * Math.PI / 60)));

g.setColor(Color.red);

g.drawLine(xCenter, yCenter, xSecond, ySecond);

// Draw minute hand

int mLength = (int) (clockRadius * 0.65);

int xMinute = (int) (xCenter + mLength

* Math.sin(minute * (2 * Math.PI / 60)));

int yMinute = (int) (yCenter - mLength

* Math.cos(minute * (2 * Math.PI / 60)));

g.setColor(Color.blue);
g.drawLine(xCenter, yCenter, xMinute, yMinute);

// Draw hour hand

int hLength = (int) (clockRadius * 0.5);

int xHour = (int) (xCenter + hLength

* Math.sin((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));

int yHour = (int) (yCenter - hLength

* Math.cos((hour % 12 + minute / 60.0) * (2 * Math.PI / 12)));

g.setColor(Color.green);

g.drawLine(xCenter, yCenter, xHour, yHour);

public void setCurrentTime() {

// Construct a calendar for the current date and time

Calendar calendar = new GregorianCalendar();

// Set current hour, minute and second

this.hour = calendar.get(Calendar.HOUR_OF_DAY);

this.minute = calendar.get(Calendar.MINUTE);

this.second = calendar.get(Calendar.SECOND);

@Override

public Dimension getPreferredSize() {

return new Dimension(200, 200);

}
TRAFFIC SIGNAL
import javax.swing.*;

import java.awt.BorderLayout;

import java.awt.Color;

import java.awt.Graphics;

import java.awt.event.ItemEvent;

import java.awt.event.ItemListener;

import java.awt.event.WindowAdapter;

import java.awt.event.WindowEvent;

public class Trafficlight extends JFrame implements ItemListener {

JRadioButton RB1, RB2, RB3;

int x = 0, y = 0, z = 0;

public Trafficlight() {

// Create panel p1 for the buttons and set GridLayout

JPanel p1 = new JPanel();

//Add label and text field to the panel

RB1 = new JRadioButton("Red");

RB2 = new JRadioButton("Yellow");

RB3 = new JRadioButton("Green");

RB1.addItemListener(this);

RB2.addItemListener(this);

RB3.addItemListener(this);

p1.add(RB1);

p1.add(RB2);

p1.add(RB3);
// Create panel p2 to hold p1 and some other component

JPanel p2 = new JPanel(new BorderLayout());

p2.add(p1, BorderLayout.SOUTH);

// add contents into the frame

add(p2);

addWindowListener(new WindowAdapter() {

@Override

public void windowClosing(WindowEvent e) {

// It haults here itself

System.exit(0);

});

public void itemStateChanged(ItemEvent ie) {

if (ie.getSource() == RB1) {

x = 1;

// Again repainting the button

repaint();

if (ie.getSource() == RB2) {

y = 1;

// Again repainting the button

repaint();

if (ie.getSource() == RB3) {

z = 1;

// Again repainting the button


repaint();

public void paint(Graphics g) {

g.drawRect(105, 35, 50, 140);

g.drawOval(110, 40, 40, 40);

g.drawOval(110, 85, 40, 40);

g.drawOval(110, 130, 40, 40);

// Case: Red

if (x == 1) {

g.setColor(Color.RED);

g.fillOval(111, 41, 39, 39);

g.setColor(Color.WHITE);

g.fillOval(111, 86, 39, 39);

g.setColor(Color.WHITE);

g.fillOval(111, 131, 39, 39);

x = 0;

// Case: Orange

if (y == 1) {

g.setColor(Color.WHITE);

g.fillOval(111, 41, 39, 39);

g.setColor(Color.ORANGE);

g.fillOval(111, 86, 39, 39);

g.setColor(Color.WHITE);

g.fillOval(111, 131, 39, 39);

y = 0;

if (z == 1) {

g.setColor(Color.WHITE);

g.fillOval(111, 41, 39, 39);

g.setColor(Color.WHITE);
g.fillOval(111, 86, 39, 39);

g.setColor(Color.GREEN);

g.fillOval(111, 131, 39, 39);

z = 0;

/** Main method */

public static void main(String[] args) {

Trafficlight frame = new Trafficlight();

frame.setTitle("Traffic Light");

frame.setSize(275, 230);

frame.setLocationRelativeTo(null); // Center the frame

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

Accunt inf
package inf;

import javax.swing.*;

public class accunt extends javax.swing.JFrame {

JTextField username = new JTextField(15);

JPasswordField password = new JPasswordField(15);

JTextArea comments = new JTextArea(4, 15);


JButton ok = new JButton("OK");

JButton cancel = new JButton("Cancel");

public accunt() {

super("Account Information");

setSize(300, 220);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JPanel pane = new JPanel();

JLabel usernameLabel = new JLabel("Username: ");

JLabel passwordLabel = new JLabel("Password: ");

JLabel commentsLabel = new JLabel("Comments: ");

comments.setLineWrap(true);

comments.setWrapStyleWord(true);

pane.add(usernameLabel);

pane.add(username);

pane.add(passwordLabel);

pane.add(password);

pane.add(commentsLabel);

pane.add(comments);

pane.add(ok);

pane.add(cancel);

add(pane);

setVisible(true);

public static void main(String[] arguments) {

accunt acc = new accunt();

}}
grade;
import javax.swing.*;
import java.awt.*;

public class STUDENT extends JFrame {

public STUDENT() {
// Set GridLayout, 3 rows, 2 columns, and gaps 5 between
// components horizontally and vertically
JPanel p1 = new JPanel();
p1.setLayout(new GridLayout(5, 2, 0, 1));

// Add labels and text fields to the frame


p1.add(new JLabel("First Name", JLabel.RIGHT));
p1.add(new JTextField(15));
p1.add(new JLabel("Last Name", JLabel.RIGHT));
p1.add(new JTextField(15));
p1.add(new JLabel("Mark", JLabel.RIGHT));
p1.add(new JTextField(15));
p1.add(new JLabel("Grade", JLabel.RIGHT));
p1.add(new JTextField("grade dispalyed here", 15));
p1.add(new JButton("Submit"));
p1.add(new JButton("Clear"));
JPanel p2 = new JPanel();
p2.add(new JLabel("Welcome to student grading system"));
p2.add(p1);
add(p2);
}

/**
* Main method
*/
public static void main(String[] args) {
STUDENT frame = new STUDENT();
frame.setTitle("student grades");
frame.setSize(380, 220);
frame.setLocationRelativeTo(null); // Center the frame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

PUZZLE G
package mati;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class pz extends JFrame implements

ActionListener{

JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,next;

pz(){ super("Puzzle Game - JavaTpoint");

b1=new JButton("1");

b2=new JButton(" ");

b3=new JButton("3");

b4=new JButton("4");

b5=new JButton("5");

b6=new JButton("6");

b7=new JButton("7");

b8=new JButton("8");

b9=new JButton("2");

next=new JButton("next");

b1.setBounds(10,30,50,40);

b2.setBounds(70,30,50,40);

b3.setBounds(130,30,50,40);

b4.setBounds(10,80,50,40);

b5.setBounds(70,80,50,40);

b6.setBounds(130,80,50,40);

b7.setBounds(10,130,50,40);

b8.setBounds(70,130,50,40);

b9.setBounds(130,130,50,40);
next.setBounds(70,200,100,40);

add(b1);add(b2);add(b3);add(b4);add(b5);add(b6);add(b7);add(b8);add(b9); add(next);

b1.addActionListener(this);

b2.addActionListener(this);

b3.addActionListener(this);

b4.addActionListener(this);

b5.addActionListener(this);

b6.addActionListener(this);

b7.addActionListener(this);

b8.addActionListener(this);

b9.addActionListener(this);

next.addActionListener(this);

next.setBackground(Color.black);

next.setForeground(Color.green);

setSize(250,300);

setLayout(null);

setVisible(true);

setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}//end of constructor

public void actionPerformed(ActionEvent e){

if(e.getSource()==next){ String s=b4.getLabel();

b4.setLabel(b9.getLabel());

b9.setLabel(s);

s=b1.getLabel();

b1.setLabel(b5.getLabel());

b5.setLabel(s); s=b2.getLabel();

b2.setLabel(b7.getLabel());

b7.setLabel(s);
}

if(e.getSource()==b1){

String s=b1.getLabel();

if(b2.getLabel().equals(" ")){ b2.setLabel(s);

b1.setLabel(" ");}

else if(b4.getLabel().equals(" ")){ b4.setLabel(s);

b1.setLabel(" ");}

}//end of if

if(e.getSource()==b3){

String s=b3.getLabel();

if(b2.getLabel().equals(" ")){ b2.setLabel(s);

b3.setLabel(" ");}

else if(b6.getLabel().equals(" ")){ b6.setLabel(s);

b3.setLabel(" ");}

}//end of if

if(e.getSource()==b2){ String s=b2.getLabel();

if(b1.getLabel().equals(" ")){ b1.setLabel(s);

b2.setLabel(" ");}

else if(b3.getLabel().equals(" ")){ b3.setLabel(s);

b2.setLabel(" ");}

else if(b5.getLabel().equals(" ")){ b5.setLabel(s);

b2.setLabel(" ");}

}//end of if

if(e.getSource()==b4){ String s=b4.getLabel();

if(b1.getLabel().equals(" ")){ b1.setLabel(s);

b4.setLabel(" ");}

else if(b7.getLabel().equals(" ")){ b7.setLabel(s);

b4.setLabel(" ");}

else if(b5.getLabel().equals(" ")){ b5.setLabel(s);


b4.setLabel(" ");}

}//end of if

if(e.getSource()==b5){ String s=b5.getLabel();

if(b2.getLabel().equals(" ")){ b2.setLabel(s);

b5.setLabel(" ");}

else if(b4.getLabel().equals(" ")){ b4.setLabel(s);

b5.setLabel(" ");}

else if(b6.getLabel().equals(" ")){ b6.setLabel(s);

b5.setLabel(" ");}

else if(b8.getLabel().equals(" ")){ b8.setLabel(s);

b5.setLabel(" ");}

}//end of if

if(e.getSource()==b6){ String s=b6.getLabel();

if(b9.getLabel().equals(" ")){ b9.setLabel(s);

b6.setLabel(" ");}

else if(b3.getLabel().equals(" ")){ b3.setLabel(s);

b6.setLabel(" ");}

else if(b5.getLabel().equals(" ")){ b5.setLabel(s);

b6.setLabel(" ");}

}//end of if

if(e.getSource()==b7){ String s=b7.getLabel();

if(b4.getLabel().equals(" ")){ b4.setLabel(s);

b7.setLabel(" ");}

else if(b8.getLabel().equals(" ")){ b8.setLabel(s);

b7.setLabel(" ");}

}//end of if

if(e.getSource()==b8){ String s=b8.getLabel();

if(b7.getLabel().equals(" ")){ b7.setLabel(s);


b8.setLabel(" ");}

else if(b9.getLabel().equals(" ")){ b9.setLabel(s);

b8.setLabel(" ");}

else if(b5.getLabel().equals(" ")){ b5.setLabel(s);

b8.setLabel(" ");} }//end of if

if(e.getSource()==b9){ String s=b9.getLabel();

if(b6.getLabel().equals(" ")){ b6.setLabel(s);

b9.setLabel(" ");}

else if(b8.getLabel().equals(" ")){ b8.setLabel(s);

b9.setLabel(" ");}

if(b1.getLabel().equals("1")&&b2.getLabel()

.equals("2")&&b3.getLabel() .equals("3")&&b4.getLabel().equals("4")&&b5.getLabel().equals("5")

&&b6.getLabel().equals("6")&&b7.getLabel().equals

("7")&&b8.getLabel()

.equals("8")&&b9.getLabel().equals(" ")){

JOptionPane.showMessageDialog(pz.this,"!!!you won!!!");

}//end of if

}//end of actionPerformed

public static void main(String[] args){ new pz();

}//end of main

}//end of class
GROUP ASSIGNMENT OF JAVA PROGRAMMING

WOLLEG NO
ID NO
NAME

A
1 MATHEWOS DESALEGN
1206286
2 FIRAOL GAMACHU

UNIVER 1206
3 EBISA DASU
1206

SITY 4
1206197
ABDI GIRMA

COLLEG
E OF
ENGINE
ERING
AND

You might also like