ALL JAVA Project
ALL JAVA Project
package lbel;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
frame.setTitle("Six Labels");
frame.setSize(300, 200);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
public SixLabels() {
new JLabel("Black"),
new JLabel("Blue"),
new JLabel("Cyan"),
new JLabel("Green"),
new JLabel("Magenta"),
new JLabel("Orange")};
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);
list[i].setBackground(Color.white);
// set fonts
list[i].setFont(font);
// set borders
list[i].setBorder(lineBorder);
// set tooltip
list[i].setToolTipText(list[i].getText());
add(list[i]);
CALCULATOR;
import javax.swing.*;
import java.awt. *;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
@SuppressWarnings("serial")
// =======================Declaration of variable===============
//----------Common keys---------------
private final JButton bOne = new JButton("1");
//----------Scientific keys---------------
//------------container variabl
LOAN AMOUNT
import java.util.Scanner;
System.out.println(
System.out.printf("%-5.3f", i);
System.out.print("% ");
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.*;
// Text component
JTextArea t;
// Frame
JFrame f;
// Constructor
editor()
// Create a frame
f = new JFrame("editor");
try {
UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
MetalLookAndFeel.setCurrentTheme(new OceanTheme());
catch (Exception e) {
}
// Text component
t = new JTextArea();
// Create a menubar
mi1.addActionListener(this);
mi2.addActionListener(this);
mi3.addActionListener(this);
mi9.addActionListener(this);
m1.add(mi1);
m1.add(mi2);
m1.add(mi3);
m1.add(mi9);
mi4.addActionListener(this);
mi5.addActionListener(this);
mi6.addActionListener(this);
mi7.addActionListener(this);
m2.add(mi4);
m2.add(mi5);
m2.add(mi6);
m2.add(mi7);
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
String s = e.getActionCommand();
if (s.equals("cut")) {
t.cut();
else if (s.equals("copy")) {
t.copy();
else if (s.equals("paste")) {
t.paste();
t.selectAll();
else if (s.equals("Save")) {
int r = j.showSaveDialog(null);
if (r == JFileChooser.APPROVE_OPTION) {
// Set the label to the path of the selected directory
try {
// Write
w.write(t.getText());
w.flush();
w.close();
JOptionPane.showMessageDialog(f, evt.getMessage());
else
else if (s.equals("Open")) {
int r = j.showOpenDialog(null);
if (r == JFileChooser.APPROVE_OPTION) {
try {
// String
// File reader
// Buffered reader
// Initialize sl
sl = br.readLine();
sl = sl + "\n" + s1;
t.setText(sl);
}
catch (Exception evt) {
JOptionPane.showMessageDialog(f, evt.getMessage());
else
else if (s.equals("New")) {
t.setText("");
else if (s.equals("About")) {
else if (s.equals("Exit")) {
f.setVisible(false);
// Main class
}
es---------------
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.
pScreen1.add(tfRawInput);
pScreen1.setLayout(null);
tfRawInput.setHorizontalAlignment(JTextField.LEFT);
tfRawInput.setText("0");
tfRawInput.setEditable(false);
tfRawInput.setBackground(screenColor);
tfRawInput.setForeground(Color.BLACK);
pScreen2.add(tfDisplay);
pScreen2.setLayout(null);
tfDisplay.setFont(fontResDisplay);
tfDisplay.setText("0");
tfDisplay.setEditable(false);
tfDisplay.setBackground(screenColor);
tfDisplay.setForeground(Color.BLACK);
pKeypad1.setLayout(null);
pKeypad1.setBackground(windowColor);
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);
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);
bOneByN.setFont(fontKeypad1); bOneByN.setBackground(otherColor);
bOneByN.setFocusable(false);
bPlusMinus.setFont(fontKeypad);
bPlusMinus.setBackground(numberKeyColor); bPlusMinus.setFocusable(false);
// 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
// 4th row
// 5th row
pKeypad2.setLayout(null);
pKeypad2.setBackground(windowColor);
//----------------------copyright tag-------------------------------------------------------
//copyRight.setForeground(copyRightColor);
// 1st row
// 2nd row
// 3rd row
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=============================
frame.setTitle("CI- Calculator");
frame.setSize(350, 450);
frame.getContentPane().setBackground(windowColor);
frame.setLocationRelativeTo(null);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
@Override
{
if (e.getSource() == bOne)
if(operation == '=')
sDisplay = "1";
sRawInput = "1";
tfRawInput.setText(sRawInput);
else
sRawInput += "1";
tfRawInput.setText(sRawInput);
if(operation == '=')
sDisplay = "2";
sRawInput = "2";
tfRawInput.setText(sRawInput);
else
sRawInput += "2";
tfRawInput.setText(sRawInput);
if(operation == '=')
sDisplay = "3";
sRawInput = "3";
tfRawInput.setText(sRawInput);
else
sRawInput += "3";
tfRawInput.setText(sRawInput);
if(operation == '=')
sDisplay = "4";
sRawInput = "4";
tfRawInput.setText(sRawInput);
else
{
sRawInput += "4";
tfRawInput.setText(sRawInput);
if(operation == '=')
sDisplay = "5";
sRawInput = "5";
tfRawInput.setText(sRawInput);
else
sRawInput += "5";
tfRawInput.setText(sRawInput);
if(operation == '=')
sDisplay = "6";
sRawInput = "6";
tfRawInput.setText(sRawInput);
operation = ' ';
else
sRawInput += "6";
tfRawInput.setText(sRawInput);
if(operation == '=')
sDisplay = "7";
sRawInput = "7";
tfRawInput.setText(sRawInput);
else
sRawInput += "7";
tfRawInput.setText(sRawInput);
if(operation == '=')
{
sDisplay = "8";
sRawInput = "8";
tfRawInput.setText(sRawInput);
else
sRawInput += "8";
tfRawInput.setText(sRawInput);
if(operation == '=')
sDisplay = "9";
sRawInput = "9";
tfRawInput.setText(sRawInput);
else
sRawInput += "9";
tfRawInput.setText(sRawInput);
if(sDisplay.equals(""))//zero at first
sDisplay = "0";
sRawInput += "0";
tfRawInput.setText(sRawInput);
else
sRawInput += "0";
tfRawInput.setText(sRawInput);
sDisplay = "0.";
sRawInput += "0.";
tfRawInput.setText(sRawInput);
else if(!isPoint)//when there is no bPoint till now then just add the
bPoint
sRawInput += ".";
tfRawInput.setText(sRawInput);
}
isPoint = true;//when the bPoint button is clicked once set the bPoint
flag to true
if(isPlus)
sRawInput = sDisplay;
tfRawInput.setText(sRawInput);
isPlus = false;
else
tfRawInput.setText(sRawInput);
isPlus = true;
number1 = Double.parseDouble(sDisplay);
sDisplay = "";
operation = '+';
isPlus = true;
sRawInput += " + ";
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+number1);
tfDisplay.setText(""+(long)number1);
number2 = Double.parseDouble(sDisplay);
if(operation == '+')
else
result = number2;
tfDisplay.setText(""+result);
temp = ""+result;
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
operation = '+';
sDisplay = "";
number1 = result;
isPlus = true;
isPoint = false;
isOperation = true;
sRawInput += " + ";
tfRawInput.setText(sRawInput);
sDisplay = "";
operation = '+';
isPlus = true;
isOperation = true;
tfRawInput.setText(sRawInput);
isOperation = true;
number1 = Double.parseDouble(sDisplay);
sDisplay = "";
operation = '-';
isPlus = true;
tfRawInput.setText(sRawInput);
{
tfDisplay.setText(""+number1);
tfDisplay.setText(""+(long)number1);
number2 = Double.parseDouble(sDisplay);
if(operation == '+')
{
result = number1 % number2;
else
result = number2;
tfDisplay.setText(""+result);
temp = ""+result;
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
operation = '-';
sDisplay = "";
number1 = result;
isPlus = true;
isPoint = false;
isOperation = true;
tfRawInput.setText(sRawInput);
sDisplay = "";
operation = '-';
isPlus = true;
isOperation = true;
tfRawInput.setText(sRawInput);
isOperation = true;
number1 = Double.parseDouble(sDisplay);
sDisplay = "";
operation = '*';
isPlus = true;
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+number1);
tfDisplay.setText(""+(long)number1);
}
number2 = Double.parseDouble(sDisplay);
if(operation == '+')
else
result = number2;
}
tfDisplay.setText(""+result);
temp = ""+result;
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
operation = '*';
sDisplay = "";
number1 = result;
isPlus = true;
isPoint = false;
isOperation = true;
tfRawInput.setText(sRawInput);
sDisplay = "";
operation = '*';
isPlus = true;
isOperation = true;
sRawInput += " \u00D7 ";
tfRawInput.setText(sRawInput);
isOperation = true;
number1 = Double.parseDouble(sDisplay);
sDisplay = "";
operation = '/';
isPlus = true;
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+number1);
tfDisplay.setText(""+(long)number1);
number2 = Double.parseDouble(sDisplay);
if(operation == '+')
else
result = number2;
{
tfDisplay.setText(""+result);
temp = ""+result;
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
operation = '*';
sDisplay = "";
number1 = result;
isPlus = true;
isPoint = false;
isOperation = true;
tfRawInput.setText(sRawInput);
sDisplay = "";
operation = '/';
isPlus = true;
isOperation = true;
tfRawInput.setText(sRawInput);
isOperation = true;
}
else if (e.getSource() == bMod && (!sDisplay.equals("") || operation ==
'='))//Modules button
number1 = Double.parseDouble(sDisplay);
sDisplay = "";
operation = '%';
isPlus = true;
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+number1);
tfDisplay.setText(""+(long)number1);
number2 = Double.parseDouble(sDisplay);
if(operation == '+')
}
else if(operation == '-')
else
result = number2;
tfDisplay.setText(""+result);
temp = ""+result;
{
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
operation = '%';
sDisplay = "";
number1 = result;
isPlus = true;
isPoint = false;
isOperation = true;
tfRawInput.setText(sRawInput);
sDisplay = "";
operation = '%';
isPlus = true;
isOperation = true;
tfRawInput.setText(sRawInput);
isOperation = true;
number2 = Double.parseDouble(sDisplay);
if(operation == '+')
else
result = number2;
tfDisplay.setText(""+result);
temp = ""+result;
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
sDisplay = "";
number1 = result;
isPlus = true;
isPoint = false;
isOperation = true;
tfRawInput.setText(sRawInput);
sRawInput = temp;
operation = '=';
//tfDisplay.setText("0");
tfRawInput.setText("0");
else
//tfDisplay.setText(sDisplay);
tfRawInput.setText(sRawInput);
sDisplay = "";
tfDisplay.setText("0");
isPoint = false;
isPlus = true;
isOperation = false;
sRawInput = "";
tfRawInput.setText("0");
number1 = Double.parseDouble(sDisplay);
if(!isPoint)
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
else
tfDisplay.setText(""+result);
temp = ""+result;
}
tfRawInput.setText(sRawInput);
sRawInput = temp;
sDisplay = "";
number1 = result;
operation = '=';
isPoint = false;
isOperation = true;
isPlus = true;
number1 = Double.parseDouble(sDisplay);
result = Math.sqrt(number1);
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+result);
sRawInput = ""+result;
sDisplay = "";
number1 = result;
operation = '=';
isPoint = true;
isOperation = true;
isPlus = true;
number1 = Double.parseDouble(sDisplay);
result = Math.pow(number1, 3);
if(!isPoint)
tfDisplay.setText(""+(long)result);
temp = ""+(long)result;
else
tfDisplay.setText(""+result);
temp = ""+result;
tfRawInput.setText(sRawInput);
sRawInput = temp;
sDisplay = "";
number1 = result;
operation = '=';
isPoint = false;
isOperation = true;
isPlus = true;
number1 = Double.parseDouble(sDisplay);
result = 1 / number1;
if(isPoint)
{
sRawInput = "1 / " + number1;
else
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+result);
sDisplay = "";
sRawInput = ""+result;
number1 = result;
operation = '=';
isPoint = true;
isOperation = true;
isPlus = true;
number2 = Double.parseDouble(sDisplay);
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+result);
sDisplay = "";
number1 = result;
operation = '=';
isPlus = true;
isOperation = true;
isPoint = true;
sRawInput = ""+result;
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;
number1 = Double.parseDouble(sDisplay);
if(number1 == 60)
result = Math.cos(Math.toRadians(number1)) -
0.0000000000000001;
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;
number1 = Double.parseDouble(sDisplay);
if(number1 == 45)
{
result = Math.tan(Math.toRadians(number1)) +
0.0000000000000001;
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;
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;
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;
{
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;
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;
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;
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;
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;
}
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;
number1 = Double.parseDouble(sDisplay);
sRawInput = "10^"+sRawInput;
tfRawInput.setText(sRawInput);
tfDisplay.setText(""+result);
sRawInput = ""+result;
sDisplay = "";
number1 = result;
operation = '=';
isPoint = true;
isOperation = true;
isPlus = true;
System.exit(0);
CLOCK;
import java.awt.*;
import java.awt.event.*;
import java.util.Calendar;
import java.util.GregorianCalendar;
import javax.swing.*;
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() {
panel1.add(clockPanel3);
add(panel1, BorderLayout.CENTER);
jButton1.addActionListener(new ActionListener() {
@Override
clockPanel3.start();
});
jButton1.addActionListener(new ActionListener() {
@Override
clockPanel3.stop();
});
//panel2.add(jButtonb1);
//panel2.add(jButton1);
add(panel2, BorderLayout.SOUTH);
isRunning = false;
isRunning = true;
public ClockPanel() {
setLayout(new BorderLayout());
jbtStop.addActionListener(new ActionListener() {
@Override
isRunning = false;
} );
panel1.add(jbtStop);
jbtStart.addActionListener(new ActionListener() {
@Override
isRunning = true;
} );
panel1.add(jbtStart);
add(panel1, BorderLayout.SOUTH);
add(clock, BorderLayout.CENTER);
thread.start();
@Override
try {
while (true) {
Thread.sleep(1000);
if(isRunning) {
clock.setCurrentTime();
clock.repaint();
} catch (InterruptedException e) {
e.printStackTrace();
}
class StillClock extends JPanel {
public StillClock() {
setCurrentTime();
this.hour = hour;
this.minute = minute;
this.second = second;
return hour;
this.hour = hour;
repaint();
}
/** Return minute */
return minute;
this.minute = minute;
repaint();
return second;
this.second = second;
repaint();
@Override
super.paintComponent(g);
// Draw circle
g.setColor(Color.black);
2 * clockRadius, 2 * clockRadius);
g.setColor(Color.red);
g.setColor(Color.blue);
g.drawLine(xCenter, yCenter, xMinute, yMinute);
g.setColor(Color.green);
this.hour = calendar.get(Calendar.HOUR_OF_DAY);
this.minute = calendar.get(Calendar.MINUTE);
this.second = calendar.get(Calendar.SECOND);
@Override
}
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;
int x = 0, y = 0, z = 0;
public Trafficlight() {
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
p2.add(p1, BorderLayout.SOUTH);
add(p2);
addWindowListener(new WindowAdapter() {
@Override
System.exit(0);
});
if (ie.getSource() == RB1) {
x = 1;
repaint();
if (ie.getSource() == RB2) {
y = 1;
repaint();
if (ie.getSource() == RB3) {
z = 1;
// Case: Red
if (x == 1) {
g.setColor(Color.RED);
g.setColor(Color.WHITE);
g.setColor(Color.WHITE);
x = 0;
// Case: Orange
if (y == 1) {
g.setColor(Color.WHITE);
g.setColor(Color.ORANGE);
g.setColor(Color.WHITE);
y = 0;
if (z == 1) {
g.setColor(Color.WHITE);
g.setColor(Color.WHITE);
g.fillOval(111, 86, 39, 39);
g.setColor(Color.GREEN);
z = 0;
frame.setTitle("Traffic Light");
frame.setSize(275, 230);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
Accunt inf
package inf;
import javax.swing.*;
public accunt() {
super("Account Information");
setSize(300, 220);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
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);
}}
grade;
import javax.swing.*;
import java.awt.*;
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));
/**
* 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.*;
ActionListener{
JButton b1,b2,b3,b4,b5,b6,b7,b8,b9,next;
b1=new JButton("1");
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
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();
b1.setLabel(" ");}
b1.setLabel(" ");}
}//end of if
if(e.getSource()==b3){
String s=b3.getLabel();
b3.setLabel(" ");}
b3.setLabel(" ");}
}//end of if
b2.setLabel(" ");}
b2.setLabel(" ");}
b2.setLabel(" ");}
}//end of if
b4.setLabel(" ");}
b4.setLabel(" ");}
}//end of if
b5.setLabel(" ");}
b5.setLabel(" ");}
b5.setLabel(" ");}
b5.setLabel(" ");}
}//end of if
b6.setLabel(" ");}
b6.setLabel(" ");}
b6.setLabel(" ");}
}//end of if
b7.setLabel(" ");}
b7.setLabel(" ");}
}//end of if
b8.setLabel(" ");}
b9.setLabel(" ");}
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
}//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