NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package furkan;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class App1 {

double sayi, sonuc = 0;
int op = 0;

public App1() {
JFrame frame = new JFrame("Hesap Makinesi");
frame.setSize(250, 275);
frame.setLayout(new FlowLayout());
JMenuBar menuBar = new JMenuBar();
JMenuItem menu = new JMenuItem("Yardim");
JMenuItem menu1 = new JMenuItem("Hakkinda");

menu.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame,
"Hesap Makinesi'ni basit matematiksel işlemler yapmak için kullanabilirsiniz.", "YARDIM",
JOptionPane.PLAIN_MESSAGE);
}
});

menu1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
JOptionPane.showMessageDialog(frame, "Bu program Furkan Ekiz tarafından yazılmıştır");
}
});

menuBar.add(menu);
menuBar.add(menu1);
frame.add(menuBar);
frame.setJMenuBar(menuBar);
BilesenleriEkle(frame.getContentPane());
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

private void BilesenleriEkle(Container contentPane) {

JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
panel1.setLayout(new GridLayout(2, 1, 10, 10));
panel2.setLayout(new GridLayout(4, 4, 10, 10));
JTextField field1 = new JTextField(18);
field1.setText("0");
field1.setHorizontalAlignment(SwingConstants.RIGHT);
JTextField field2 = new JTextField(18);
field2.setEditable(false);
field2.setBorder(null);
field2.setHorizontalAlignment(SwingConstants.RIGHT);
JButton button0 = new JButton("0");
JButton button1 = new JButton("1");
JButton button2 = new JButton("2");
JButton button3 = new JButton("3");
JButton button4 = new JButton("4");
JButton button5 = new JButton("5");
JButton button6 = new JButton("6");
JButton button7 = new JButton("7");
JButton button8 = new JButton("8");
JButton button9 = new JButton("9");
JButton buttonA = new JButton("+");
JButton buttonE = new JButton("-");
JButton buttonB = new JButton("/");
JButton buttonC = new JButton("*");
JButton buttonH = new JButton("=");
JButton buttonT = new JButton("C");

panel1.add(field2);
panel1.add(field1);

panel2.add(button7);
panel2.add(button8);
panel2.add(button9);
panel2.add(buttonA);

panel2.add(button4);
panel2.add(button5);
panel2.add(button6);
panel2.add(buttonE);

panel2.add(button1);
panel2.add(button2);
panel2.add(button3);
panel2.add(buttonB);

panel2.add(button0);
panel2.add(buttonT);
panel2.add(buttonH);
panel2.add(buttonC);

button7.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 7);
field2.setText(field2.getText() + 7);
}
});

button8.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 8);
field2.setText(field2.getText() + 8);
}
});

button9.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 9);
field2.setText(field2.getText() + 9);
}
});

buttonA.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try {
if (!(field2.getText().endsWith("+") || field2.getText().endsWith("-")
|| field2.getText().endsWith("/") || field2.getText().endsWith("*"))) {
if (op == 2) {

sayi = Double.parseDouble(field1.getText());
sonuc = sonuc - sayi;

field1.setText(null);

} else if (op == 3) {

sayi = Double.parseDouble(field1.getText());
sonuc = sonuc / sayi;

field1.setText(null);

} else if (op == 4) {

sayi = Double.parseDouble(field1.getText());
sonuc = sonuc * sayi;

field1.setText(null);

} else {
sayi = Double.parseDouble(field1.getText());
if (sonuc == 0)
sonuc = sayi;
else
sonuc = sonuc + sayi;

}
field1.setText(null);
field2.setText(field2.getText() + "+");
}
} catch (NumberFormatException e1) {
field2.setText("Lütfen sayı giriniz");
field1.setText(null);
}
op = 1;
}
});

button4.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 4);
field2.setText(field2.getText() + 4);
}
});

button5.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 5);
field2.setText(field2.getText() + 5);
}
});

button6.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 6);
field2.setText(field2.getText() + 6);
}
});

buttonE.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try{
if (!(field2.getText().endsWith("+") || field2.getText().endsWith("-") || field2.getText().endsWith("/")
|| field2.getText().endsWith("*"))) {
if (op == 1) {

sayi = Double.parseDouble(field1.getText());
sonuc = sonuc + sayi;

field1.setText(null);

} else if (op == 3) {

sayi = Double.parseDouble(field1.getText());
sonuc = sonuc / sayi;

field1.setText(null);

} else if (op == 4) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc * sayi;
} else {
sayi = Double.parseDouble(field1.getText());
if (sonuc == 0)
sonuc = sayi;
else
sonuc = sonuc - sayi;
}
field1.setText(null);
field2.setText(field2.getText() + "-");
}
}catch(NumberFormatException e1){
field2.setText("Lütfen sayı giriniz");
field1.setText(null);
}
op = 2;
}
});

button1.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 1);
field2.setText(field2.getText() + 1);
}
});

button2.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 2);
field2.setText(field2.getText() + 2);
}
});

button3.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 3);
field2.setText(field2.getText() + 3);
}
});

buttonB.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try{
if (!(field2.getText().endsWith("+") || field2.getText().endsWith("-") || field2.getText().endsWith("/")
|| field2.getText().endsWith("*"))) {
if (op == 1) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc + sayi;
} else if (op == 2) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc - sayi;
} else if (op == 4) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc * sayi;
} else {
sayi = Double.parseDouble(field1.getText());
if (sonuc == 0)
sonuc = sayi;
else
sonuc = sonuc / sayi;
}
field1.setText(null);
field2.setText(field2.getText() + "/");
}
}catch(NumberFormatException e1){
field2.setText("Lütfen sayı giriniz");
field1.setText(null);
}
op = 3;
}
});

button0.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
if (field1.getText().equals("0"))
field1.setText(null);
field1.setText(field1.getText() + 0);
field2.setText(field2.getText() + 0);
}
});

buttonT.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
field1.setText("0");
field2.setText(null);
}
});

buttonC.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try{
if (!(field2.getText().endsWith("+") || field2.getText().endsWith("-") || field2.getText().endsWith("/")
|| field2.getText().endsWith("*"))) {
if (op == 1) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc + sayi;
} else if (op == 2) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc - sayi;
} else if (op == 3) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc / sayi;
} else {
sayi = Double.parseDouble(field1.getText());
if (sonuc == 0)
sonuc = sayi;
else
sonuc = sonuc * sayi;
}
field1.setText(null);
field2.setText(field2.getText() + "*");
}
}catch(NumberFormatException e1){
field2.setText("Lütfen sayı giriniz");
field1.setText(null);
}
op = 4;
}
});

buttonH.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
try{
if (!(field2.getText().endsWith("+") || field2.getText().endsWith("-") || field2.getText().endsWith("/")
|| field2.getText().endsWith("*"))) {
if (op == 1) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc + sayi;
} else if (op == 2) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc - sayi;
} else if (op == 3) {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc / sayi;
} else {
sayi = Double.parseDouble(field1.getText());
sonuc = sonuc * sayi;
}
field1.setText(String.valueOf(sonuc));
field2.setText(field2.getText() + "=" + String.valueOf(sonuc));
sonuc = 0;
}
}catch(NumberFormatException e1){
field2.setText("Lütfen sayı giriniz");
field1.setText(null);
}
}
});

contentPane.add(panel1);
contentPane.add(panel2);
}

public static void main(String[] args) {
new App1();
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.