rechenmaschine/GUI.java

49 lines
1.8 KiB
Java

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class GUI extends JFrame {
private JPanel panelMain;
private JTextField textFieldRechenterm;
private JLabel labelGibRechentermEin;
private JButton buttonBerechnen;
private JLabel labelErgebnis;
public GUI(String title){
super(title);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setContentPane(panelMain);
this.pack();
buttonBerechnen.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
//TODO: Text vom Text field zu Eingabe übergeben
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (ClassNotFoundException classNotFoundException) {
classNotFoundException.printStackTrace();
} catch (InstantiationException instantiationException) {
instantiationException.printStackTrace();
} catch (IllegalAccessException illegalAccessException) {
illegalAccessException.printStackTrace();
} catch (UnsupportedLookAndFeelException unsupportedLookAndFeelException) {
unsupportedLookAndFeelException.printStackTrace();
}
Rechenmaschine rechner = new Rechenmaschine(textFieldRechenterm.getText());
labelErgebnis.setText("Das Ergebnis ist: "+rechner.getResult());
}
});
}
public static void main(String[] args) {
JFrame frame = new GUI("Rechenterme");
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
private void createUIComponents() {
// TODO: place custom component creation code here
}
}