Hallo an alle bin der neue hier^^
Ich fanage mal gleich direkt an. Mein eingentliches Ziel ist es einen Kleinen Formelrechner mit GUI zu bauen
Wollte zum testen als erstes blos zwei Zahlen addieren, aber irgend wo hängt es total
könnte von euch jemand mal drüberschauen?
Fehler Meldung ist
[SIZE=+1]Starter:
[/SIZE]
GUI
[SIZE=+1]
[SIZE=+1]Contoller
Addtion
[SIZE=+1]
[/SIZE][/SIZE][/SIZE]
Ich fanage mal gleich direkt an. Mein eingentliches Ziel ist es einen Kleinen Formelrechner mit GUI zu bauen
Wollte zum testen als erstes blos zwei Zahlen addieren, aber irgend wo hängt es total
könnte von euch jemand mal drüberschauen?
Fehler Meldung ist
Java:
Exception in thread "main" java.lang.NullPointerException
at gui.OGUI.setAdditionListener(OGUI.java:112)
at controller.Controller.addListener(Controller.java:29)
at controller.Controller.<init>(Controller.java:18)
at misc.Starter.main(Starter.java:11)
[SIZE=+1]Starter:
Java:
package misc;
import controller.Controller;
public class Starter {
static Controller controller;
public static void main(String[] args) {
// TODO Auto-generated method stub
controller = new Controller();
controller.showGUI();
}
}
GUI
[SIZE=+1]
Java:
package gui;
import java.awt.EventQueue;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.EmptyBorder;
public class OGUI extends JFrame {
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private JTextField Awert;
private JTextField Bwert;
private JTextField ERGwert;
private JButton NeuWerte;
private JButton Tuwas;
/**
* Launch the application.
*/
// public static void main(String[] args) {
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// try {
// OGUI frame = new OGUI();
// frame.setVisible(true);
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// }
//
// /**
// * Create the frame.
public OGUI() {
super("tu_was");
Form();
}
private void Form(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
JButton Tuwas = new JButton("tu_was");
Tuwas.setBounds(258, 51, 117, 25);
contentPane.add(Tuwas);
NeuWerte = new JButton("Refresh");
NeuWerte.setBounds(258, 111, 117, 25);
contentPane.add(NeuWerte);
Awert = new JTextField();
Awert.setBounds(12, 12, 114, 19);
contentPane.add(Awert);
Awert.setColumns(10);
Bwert = new JTextField();
Bwert.setBounds(12, 54, 114, 19);
contentPane.add(Bwert);
Bwert.setColumns(10);
ERGwert = new JTextField();
ERGwert.setBounds(12, 114, 114, 19);
contentPane.add(ERGwert);
ERGwert.setColumns(10);
}
public void resetOGUI(){
this.Awert.setText(" ");
this.Bwert.setText(" ");
this.ERGwert.setText(" ");
}
public String get_A_Eingabe(){
return this.Awert.getText();
}
public String get_B_Eingabe(){
return this.Bwert.getText();
}
public void setErgebnis(String erg){
this.ERGwert.setText(erg);
}
public void setAdditionListener(ActionListener l){
this.Tuwas.addActionListener(l);
}
public void setResetFormListener(ActionListener l){
this.NeuWerte.addActionListener(l);
}
}
[SIZE=+1]Contoller
Java:
package controller;
import formelen.Addition;
import gui.OGUI;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class Controller {
private OGUI ogui;
private Addition addition;
public Controller(){
this.ogui = new OGUI();
this.addition = new Addition();
addListener();
}
public void showGUI(){
this.ogui.setVisible(true);
}
private void addListener(){
this.ogui.setAdditionListener(new AdditionListener());
this.ogui.setResetFormListener(new ResetFormListener());
}
/
class AdditionListener implements ActionListener{
public void actionPerformed(ActionEvent e){
long aaWert = Long.valueOf(ogui.get_A_Eingabe());
long bbWert = Long.valueOf(ogui.get_B_Eingabe());
addition.additionBerechnen(aaWert, bbWert);
ogui.setErgebnis(String.valueOf(addition.getAddErg()));
}
}
class ResetFormListener implements ActionListener{
public void actionPerformed(ActionEvent e) {
ogui.resetOGUI();
addition.zurückSetzen();
}
}
}
Addtion
[SIZE=+1]
Java:
package formelen;
public class Addition {
long x;
public Addition(){
zurückSetzen();
}
public void zurückSetzen(){
this.x = 0;
}
public void additionBerechnen(long aaWert, long bbWert){
this.x = (aaWert+bbWert);
}
public long getAddErg(){
return this.x;
}
}
[/SIZE][/SIZE][/SIZE]