Arama butonu
Bu konudaki kullanıcılar: 1 misafir
3
Cevap
604
Tıklama
0
Öne Çıkarma
Metod çağıramıyorum
A
5 yıl
Çavuş
Konu Sahibi

Merhaba arkadaşlar java ile hesap makinesi yapmaya çalışıyorum fakat bi sorunla karşılaştım. Bilen varsa yardımcı olabilirmi ?

< Resime gitmek için tıklayın >
< Resime gitmek için tıklayın >





package javaapplication2;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JavaApplication2 {
public static JTextField tf1=new JTextField(11);
public static JTextField tf2=new JTextField(11);
public double sayi,sonuc;
int islem;

public void matematik()
{
switch(islem)
{
case 1: // toplama
sonuc = sayi + Double.parseDouble(tf1.getText());
tf1.setText(Double.toString(sonuc));
break;
case 2: // çıkartma
sonuc = sayi - Double.parseDouble(tf1.getText());
tf1.setText(Double.toString(sonuc));
break;
case 3: //carpma
sonuc = sayi * Double.parseDouble(tf1.getText());
tf1.setText(Double.toString(sonuc));
break;
case 4: //bolme
sonuc = sayi / Double.parseDouble(tf1.getText());
tf1.setText(Double.toString(sonuc));
break;

}
}

public static void main(String[] args) {
JFrame pencere = new JFrame("328");
pencere.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pencere.setBounds(500,200,270,420);
pencere.setLayout(new FlowLayout(0));
tf1.setEditable(false);tf2.setEditable(false);
JButton b1=new JButton("1");
JButton b2=new JButton("2");
JButton b3=new JButton("3");
JButton b4=new JButton("4");
JButton b5=new JButton("5");
JButton b6=new JButton("6");
JButton b7=new JButton("7");
JButton b8=new JButton("8");
JButton b9=new JButton("9");
JButton b0=new JButton("0");
JButton ba=new JButton("+");
JButton be=new JButton("-");
JButton bc=new JButton("*");
JButton bb=new JButton("/");
JButton bn=new JButton(".");
JButton besit=new JButton("=");

tf1.setFont(new Font(Font.MONOSPACED,Font.BOLD,35));
tf1.setHorizontalAlignment(JTextField.RIGHT);
tf2.setHorizontalAlignment(JTextField.RIGHT);
tf2.setFont(tf1.getFont());

b1.setFont(tf1.getFont());b2.setFont(tf1.getFont());
b3.setFont(tf1.getFont());b4.setFont(tf1.getFont());
b5.setFont(tf1.getFont());b6.setFont(tf1.getFont());
b7.setFont(tf1.getFont());b8.setFont(tf1.getFont());
b9.setFont(tf1.getFont());b0.setFont(tf1.getFont());
bn.setFont(tf1.getFont());ba.setFont(tf1.getFont());
be.setFont(tf1.getFont());bc.setFont(tf1.getFont());
bb.setFont(tf1.getFont());besit.setFont(tf1.getFont());

b1.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"1");

}
});

b2.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"2");
}
});

b3.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"3");
}
});

b4.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"4");
}
});

b5.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"5");
}
});

b6.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"6");
}
});

b7.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"7");
}
});

b8.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"8");
}
});

b9.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"9");
}
});

b0.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"0");
}
});

bn.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+".");
}
});

bb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"/");
}
});

ba.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
}
});

be.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"-");
}
});

bc.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
tf1.setText(tf1.getText()+"*");
}
});

besit.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
matematik();
}
});

pencere.add(tf1);pencere.add(tf2);
pencere.add(b7);pencere.add(b8);pencere.add(b9);pencere.add(bb);
pencere.add(b4);pencere.add(b5);pencere.add(b6);pencere.add(bc);
pencere.add(b1);pencere.add(b2);pencere.add(b3);pencere.add(be);
pencere.add(b0);pencere.add(bn);pencere.add(ba);pencere.add(besit);

pencere.show();
}

}



I
5 yıl
Binbaşı

main içinde method yazarken "static" keywordunu kullanmalısınız. public static void matematik diye
zaten error de de non-static yazıyor.


Bu mesaja 1 cevap geldi.
A
5 yıl
Çavuş
Konu Sahibi

quote:

Orijinalden alıntı: I0SER_b0y

main içinde method yazarken "static" keywordunu kullanmalısınız. public static void matematik diye
zaten error de de non-static yazıyor.
Teşekkür ederim yardım için. değişkenleride static olarak düzenleyince sorun çözüldü





< Bu mesaj bu kişi tarafından değiştirildi acrossfire1 -- 27 Nisan 2020; 23:18:37 >
Bu mesaja 1 cevap geldi.
I
5 yıl
Binbaşı

https://www.geeksforgeeks.org/inner-class-java/ burda bahsediyor. ne yapmanız gerektiginden




Bu mesajda bahsedilenler: @acrossfire1
DH Mobil uygulaması ile devam edin. Mobil tarayıcınız ile mümkün olanların yanı sıra, birçok yeni ve faydalı özelliğe erişin. Gizle ve güncelleme çıkana kadar tekrar gösterme.