package framePackage;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import java.text.ParseException;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.text.DefaultFormatterFactory;
import javax.swing.text.MaskFormatter;
public class MainFrame {
/**
* Deklarationen der Variablen
*/
JFrame frame1;
JMenuBar frame1MenuBar;
JMenu datei;
JMenu exit;
JPanel frame1Panel1;
JPanel frame1Panel2;
JPanel frame1Panel3;
JTextField textField1;
JTextField textField2;
JTextField textField3;
JFormattedTextField formattedTField1;
JFormattedTextField formattedTField2;
JButton buttonAddition;
JButton buttonSubtraktion;
JButton buttonDivision;
JButton buttonMultiplikation;
JButton buttonSquareRoot;
Action actionClose;
Action actionNew;
ActionListener action_Addition;
ActionListener action_Subtraktion;
ActionListener action_Multiplikation;
ActionListener action_Division;
ActionListener action_SquareRoot;
/**
* Konstruktor Methode MainFrame()
* @throws ParseException
*/
public MainFrame() throws ParseException {
// frame1 Settings
JFrame frame1 = new JFrame();
frame1.setTitle("frame1");
frame1.setSize(300,300);
frame1.setResizable(false);
frame1.setVisible(true);
final Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame1.setLocation((d.width - frame1.getSize().width) / 2, (d.height - frame1.getSize().height) / 2);
// Menüleiste
frame1MenuBar = new JMenuBar();
datei = new JMenu("Datei");
frame1MenuBar.add(datei);
frame1.setJMenuBar(frame1MenuBar);
// Actions der JMenuBar
/**
* Actions der JMenuBar
*/
// Schließen \\
actionClose = new AbstractAction("Schließen"){
private static final long serialVersionUID = 1L;
{/*putValue(Action.DISPLAYED_MNEMONIC_INDEX_KEY,0);
putValue(Action.SMALL_ICON, IconSmallNew);
putValue(Action.LARGE_ICON_KEY, IconNew); */
}
public void actionPerformed(ActionEvent e){
System.exit(0);
}
};
datei.add(actionClose);
/**
* Panel (Borderlayout)
*
* frame1Panel1 NORTH (frame1Panel2)
* frame1Panel1 CENTER (frame1Panel3)
* frame1Panel1 SOUTH
*
*/
// Panel Instanzen und deren Layout
frame1Panel1 = new JPanel();
frame1Panel1.setLayout(new FlowLayout());
frame1Panel2 = new JPanel();
frame1Panel2.setLayout(new BorderLayout());
// frame1Panel3 = new JPanel();
// frame1Panel3.setLayout(new BorderLayout());
// Buttons
buttonAddition = new JButton("+");
buttonSubtraktion = new JButton("-");
buttonMultiplikation = new JButton("*");
buttonDivision = new JButton("/");
buttonSquareRoot = new JButton("sqr");
// Buttons auf Panel2
frame1Panel2.add(buttonAddition, BorderLayout.NORTH);
frame1Panel2.add(buttonSubtraktion, BorderLayout.EAST);
frame1Panel2.add(buttonMultiplikation, BorderLayout.WEST);
frame1Panel2.add(buttonDivision, BorderLayout.SOUTH);
frame1Panel2.add(buttonSquareRoot, BorderLayout.CENTER);
// Textfelder
textField3 = new JTextField("Ergebnis", 10);
// Formatted TextFields
MaskFormatter Formatter1;
Formatter1 = new MaskFormatter();
Formatter1.setMask("*");// Formatter Eigenschaft
Formatter1.setValidCharacters("0123456789");
formattedTField1 = new JFormattedTextField(NumberFormat.getIntegerInstance());
formattedTField1.setPreferredSize(new Dimension(100,20));
formattedTField1.setFormatterFactory(new DefaultFormatterFactory(Formatter1));
formattedTField2 = new JFormattedTextField(NumberFormat.getIntegerInstance());
formattedTField2.setPreferredSize(new Dimension(100,20));
formattedTField2.setFormatterFactory(new DefaultFormatterFactory(Formatter1));
// Textfelder auf Panel1
frame1Panel1.add(formattedTField1, FlowLayout.LEFT);
frame1Panel1.add(formattedTField2, FlowLayout.RIGHT);
// ActionListener für Buttons
action_Addition = new ActionListener(){
public void actionPerformed(ActionEvent arg0) {
}
}; buttonAddition.addActionListener(action_Addition);
// frame1 ContentPane Settings
frame1.getContentPane().add("North", frame1Panel1);
frame1.getContentPane().add("Center", frame1Panel2);
frame1.getContentPane().add("South", textField3);
}
}