Auf Thema antworten

Ja du hast schon recht, die Version vorher war mindestens genauso schreib aufwendig :)


Ich hab das jetzt mal etwas verändert, mittlerweile läuft das ganze auch wieder, aber jetzt habe ich schon wieder das alte Problem mit der Maus und den Buttons ich habe ja wie du schon geschrieben hast das TextField zu JTextField verändert doch ich werde noch wahnsinnig mit dem GridBagLayout, erstens scheint es so als würde er meine Eingaben bei "gbc = makegbc(2, 2, 0, 0);" ignorieren und genauso auch bei "gbc.weightx = 100;" und "gbc.weighty = 100;" Was ich noch garnicht verstehe ist wie ich mit einem solchen Ausdruck das "ausgaben" Panel in NORTH legen kann und gleichzeitig das tasten Panel in CENTER oder ... mhh das hab ich noch garnicht versucht muss ich für jede andere anordnung ein eigenen Audruck schreiben und den als Block mit geschweiften Klammern umgeben?(sry fällt ist mir gerade beim schreiben eingefallen)


Hier mal wieder mein Code:



[code=Java]

gbc = makegbc(2, 2, 0, 0);

        gbc.weightx = 100;

        gbc.weighty = 100;

        gbc.fill = GridBagConstraints.BOTH;

        gbc.anchor = GridBagConstraints.NORTH;


        gbl.setConstraints(ausgabe, gbc);

        gbl.setConstraints(tasten, gbc);

        add(ausgabe);

        add(tasten);

        pack();

[/code]




[code=Java]

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;


public class Normal extends JFrame {


    JFrame f = new JFrame();

    JPanel alles = new JPanel();

    JPanel tasten = new JPanel();

    JButton[] array = new JButton[16];


    public Normal() {



        super("Normal");



        GridBagLayout gbl = new GridBagLayout();

        GridBagConstraints gbc = new GridBagConstraints();

        setLayout(gbl);



        JPanel ausgabe = new JPanel();

        JTextField anzeige = new JTextField("Machen Sie ihre Eingabe", 50);

        anzeige.setFont(new Font("Times New Roman", Font.BOLD, 20));

        ausgabe.add(anzeige);




        array[0] = new JButton("7");

        array[1] = new JButton("8");

        array[2] = new JButton("9");

        array[3] = new JButton(":");

        array[4] = new JButton("4");

        array[5] = new JButton("5");

        array[6] = new JButton("6");

        array[7] = new JButton("*");

        array[8] = new JButton("1");

        array[9] = new JButton("2");

        array[10] = new JButton("3");

        array[11] = new JButton("-");

        array[12] = new JButton("0");

        array[13] = new JButton(",");

        array[14] = new JButton("+");

        array[15] = new JButton("=");




        tasten.setLayout(new GridLayout(4, 4, 4, 4));

        for (int i = 0; i < 16; i++) {

            tasten.add(array[i]);

            array[i].setPreferredSize(new Dimension(50, 50));


        }



        gbc = makegbc(2, 2, 0, 0);

        gbc.weightx = 100;

        gbc.weighty = 100;

        gbc.fill = GridBagConstraints.BOTH;

        gbc.anchor = GridBagConstraints.NORTH;


        gbl.setConstraints(ausgabe, gbc);

        gbl.setConstraints(tasten, gbc);

        add(ausgabe);

        add(tasten);

        pack();




    }


    private GridBagConstraints makegbc(int x, int y, int width, int height) {


        GridBagConstraints gbc = new GridBagConstraints();

        gbc.gridx = x;

        gbc.gridy = y;

        gbc.gridwidth = width;

        gbc.gridheight = height;

        gbc.insets = new Insets(10, 10, 10, 10);

        return gbc;

    }


    public static void main(String[] args) {


        Normal n = new Normal();

        n.setSize(800, 500);

        n.setLocation(400, 300);

        n.setVisible(true);


    }

}

[/code]


Ich hoffe ich nerve dich mit meinen Prblemen nicht all zu sehr :)


liebe Grüße Matthias



Oben