白屏java jframe

时间:2016-01-15 20:30:27

标签: java jframe

我想用JFrame制作一个成绩计算器,但我总是得到一个白色的屏幕,如果你能帮助我,我将不胜感激。

主要类别:

    package me.imfrozen;

public class TheMainClass {

    public static void main(String[] args) {
    new FrameA();

    }

}

Frame-Class,其中包含所有按钮和Spinners:

    package me.imfrozen;

import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSpinner;
import javax.swing.SpinnerNumberModel;

@SuppressWarnings("serial")
public class FrameA extends JFrame {
    static JSpinner sa6;
    static JSpinner sa7;
    static JSpinner sa8;
    static JSpinner sa1;
    static JSpinner sa2;
    static JSpinner sa3;
    static JSpinner sa4;
    static JSpinner sa5;

    static JSpinner ex2;
    static JSpinner ex3;
    static JSpinner ex7;
    static JSpinner ex8;
    static JSpinner ex5;
    static JSpinner ex4;
    static JSpinner ex6;
    static JSpinner ex1;

    static JSpinner af2;
    static JSpinner af4;
    static JSpinner af6;
    static JSpinner af8;
    static JSpinner af3;
    static JSpinner af1;
    static JSpinner af5;
    static JSpinner af7;
    static JButton btnNewButton;
    private JLabel lblDeinNotendurchschnitt;
    private JLabel lblNote;

    public FrameA() {
        getContentPane().setFont(new Font("Tahoma", Font.PLAIN, 30));

        setVisible(true);
        setTitle("Notenrechner");
        setIconImage(Toolkit.getDefaultToolkit().getImage(FrameA.class.getResource("/me/imfrozen/icon.png")));
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 500, 452);

        JLabel lblSchulaufgaben = new JLabel("Schulaufgaben");
        lblSchulaufgaben.setBounds(37, 11, 130, 31);
        lblSchulaufgaben.setFont(new Font("Tahoma", Font.PLAIN, 20));

        JLabel lblExen = new JLabel("Stegreifaufgaben");
        lblExen.setBounds(200, 11, 152, 31);
        lblExen.setFont(new Font("Tahoma", Font.PLAIN, 20));

        JLabel lblAbfragen = new JLabel("Abfragen");
        lblAbfragen.setBounds(388, 11, 80, 31);
        lblAbfragen.setFont(new Font("Tahoma", Font.PLAIN, 20));

        JSpinner sa5 = new JSpinner();
        sa5.setBounds(97, 53, 50, 50);
        sa5.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa5.setFont(new Font("Tahoma", Font.PLAIN, 30));

        sa6 = new JSpinner();
        sa6.setBounds(97, 114, 50, 50);
        sa6.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa6.setFont(new Font("Tahoma", Font.PLAIN, 30));

        sa7 = new JSpinner();
        sa7.setBounds(97, 175, 50, 50);
        sa7.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa7.setFont(new Font("Tahoma", Font.PLAIN, 30));

        sa8 = new JSpinner();
        sa8.setBounds(97, 236, 50, 50);
        sa8.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa8.setFont(new Font("Tahoma", Font.PLAIN, 30));

        sa1 = new JSpinner();
        sa1.setBounds(37, 53, 50, 50);
        sa1.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa1.setFont(new Font("Tahoma", Font.PLAIN, 30));

        sa2 = new JSpinner();
        sa2.setBounds(37, 114, 50, 50);
        sa2.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa2.setFont(new Font("Tahoma", Font.PLAIN, 30));

        sa3 = new JSpinner();
        sa3.setBounds(37, 175, 50, 50);
        sa3.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa3.setFont(new Font("Tahoma", Font.PLAIN, 30));

        sa4 = new JSpinner();
        sa4.setBounds(37, 236, 50, 50);
        sa4.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        sa4.setFont(new Font("Tahoma", Font.PLAIN, 30));

        ex2 = new JSpinner();
        ex2.setBounds(210, 53, 50, 50);

        ex2.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex2.setFont(new Font("Tahoma", Font.PLAIN, 30));
        ex3 = new JSpinner();
        ex3.setBounds(210, 114, 50, 50);


        ex3.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex3.setFont(new Font("Tahoma", Font.PLAIN, 30));
        ex7 = new JSpinner();
        ex7.setBounds(210, 175, 50, 50);


        ex7.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex7.setFont(new Font("Tahoma", Font.PLAIN, 30));
        ex8 = new JSpinner();
        ex8.setBounds(210, 236, 50, 50);


        ex8.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex8.setFont(new Font("Tahoma", Font.PLAIN, 30));
        ex5 = new JSpinner();
        ex5.setBounds(270, 53, 50, 50);


        ex5.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex5.setFont(new Font("Tahoma", Font.PLAIN, 30));
        ex4 = new JSpinner();
        ex4.setBounds(270, 114, 50, 50);


        ex4.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex4.setFont(new Font("Tahoma", Font.PLAIN, 30));
        ex6 = new JSpinner();
        ex6.setBounds(270, 175, 50, 50);


        ex6.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex6.setFont(new Font("Tahoma", Font.PLAIN, 30));
        ex1 = new JSpinner();
        ex1.setBounds(270, 236, 50, 50);


        ex1.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        ex1.setFont(new Font("Tahoma", Font.PLAIN, 30));
        af2 = new JSpinner();
        af2.setBounds(418, 53, 50, 50);


        af2.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af2.setFont(new Font("Tahoma", Font.PLAIN, 30));
        af4 = new JSpinner();
        af4.setBounds(418, 114, 50, 50);


        af4.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af4.setFont(new Font("Tahoma", Font.PLAIN, 30));
        af6 = new JSpinner();
        af6.setBounds(418, 175, 50, 50);


        af6.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af6.setFont(new Font("Tahoma", Font.PLAIN, 30));
        af8 = new JSpinner();
        af8.setBounds(418, 236, 50, 50);


        af8.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af8.setFont(new Font("Tahoma", Font.PLAIN, 30));
        af3 = new JSpinner();
        af3.setBounds(358, 114, 50, 50);


        af3.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af3.setFont(new Font("Tahoma", Font.PLAIN, 30));
        af1 = new JSpinner();
        af1.setBounds(358, 53, 50, 50);


        af1.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af1.setFont(new Font("Tahoma", Font.PLAIN, 30));
        af5 = new JSpinner();
        af5.setBounds(358, 175, 50, 50);


        af5.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af5.setFont(new Font("Tahoma", Font.PLAIN, 30));

        af7 = new JSpinner();
        af7.setBounds(358, 236, 50, 50);
        af7.setModel(new SpinnerNumberModel(0, 0, 6, 1));
        af7.setFont(new Font("Tahoma", Font.PLAIN, 30));

        btnNewButton = new JButton("Note aktualisieren");
        btnNewButton.setFont(new Font("Tahoma", Font.PLAIN, 30));
        btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent paramActionEvent) {

            }
        });
        btnNewButton.setBounds(10, 356, 464, 46);
        getContentPane().setLayout(null);

        getContentPane().add(lblSchulaufgaben);
        getContentPane().add(lblExen);
        getContentPane().add(lblAbfragen);
        getContentPane().add(sa1);
        getContentPane().add(sa5);
        getContentPane().add(ex2);
        getContentPane().add(ex5);
        getContentPane().add(af1);
        getContentPane().add(af2);
        getContentPane().add(sa2);
        getContentPane().add(sa6);
        getContentPane().add(ex3);
        getContentPane().add(ex4);
        getContentPane().add(af3);
        getContentPane().add(af4);
        getContentPane().add(sa3);
        getContentPane().add(sa7);
        getContentPane().add(sa4);
        getContentPane().add(sa8);
        getContentPane().add(ex7);
        getContentPane().add(ex6);
        getContentPane().add(ex8);
        getContentPane().add(ex1);
        getContentPane().add(af5);
        getContentPane().add(af6);
        getContentPane().add(af7);
        getContentPane().add(af8);
        getContentPane().add(btnNewButton);

        lblDeinNotendurchschnitt = new JLabel("Dein Notendurchschnitt:");
        lblDeinNotendurchschnitt.setFont(new Font("Tahoma", Font.PLAIN, 30));
        lblDeinNotendurchschnitt.setBounds(37, 295, 323, 50);
        getContentPane().add(lblDeinNotendurchschnitt);

        lblNote = new JLabel("2");
        lblNote.setFont(new Font("Tahoma", Font.PLAIN, 30));
        lblNote.setBounds(388, 302, 16, 37);
        getContentPane().add(lblNote);

    }
}

计算器:

    package me.imfrozen;

public class rechner {
    public static int note = 1;
    int a = 0, b = 0, c = 0;
    public static double sa_ges = 0;

    int sa1 = (Integer) FrameA.sa1.getValue();
    int sa2 = (Integer) FrameA.sa2.getValue();
    int sa3 = (Integer) FrameA.sa3.getValue();
    int sa4 = (Integer) FrameA.sa4.getValue();
    int sa5 = (Integer) FrameA.sa5.getValue();
    int sa6 = (Integer) FrameA.sa6.getValue();
    int sa7 = (Integer) FrameA.sa7.getValue();
    int sa8 = (Integer) FrameA.sa8.getValue();

    int ex1 = (Integer) FrameA.ex1.getValue();
    int ex2 = (Integer) FrameA.ex2.getValue();
    int ex3 = (Integer) FrameA.ex3.getValue();
    int ex4 = (Integer) FrameA.ex4.getValue();
    int ex5 = (Integer) FrameA.ex5.getValue();
    int ex6 = (Integer) FrameA.ex6.getValue();
    int ex7 = (Integer) FrameA.ex7.getValue();
    int ex8 = (Integer) FrameA.ex8.getValue();

    int af1 = (Integer) FrameA.af1.getValue();
    int af2 = (Integer) FrameA.af2.getValue();
    int af3 = (Integer) FrameA.af3.getValue();
    int af4 = (Integer) FrameA.af4.getValue();
    int af5 = (Integer) FrameA.af5.getValue();
    int af6 = (Integer) FrameA.af6.getValue();
    int af7 = (Integer) FrameA.af7.getValue();
    int af8 = (Integer) FrameA.af8.getValue();


    int sa = 0, ex = 0, af = 0, exaf = 0;

    {
    //SCHULAUFGABEN
    if (sa1 >= 1){
        a++;
    }
    if (sa2 >= 1){
        a++;
    }
    if (sa3 >= 1){
        a++;
    }
    if (sa4 >= 1){
        a++;
    }
    if (sa5 >= 1){
        a++;
    }
    if (sa6 >= 1){
        a++;
    }
    if (sa7 >= 1){
        a++;
    }
    if (sa8 >= 1){
        a++;
    }

    //EXEN
    if (ex1 >= 1){
        b++;
    }
    if (ex2 >= 1){
        b++;
    }
    if (ex3 >= 1){
        b++;
    }
    if (ex4 >= 1){
        b++;
    }
    if (ex5 >= 1){
        b++;
    }
    if (ex6 >= 1){
        b++;
    }
    if (ex7 >= 1){
        b++;
    }
    if (ex8 >= 1){
        b++;
    }

    //ABFRAGEN
    if (af1 >= 1){
        c++;
    }
    if (af2 >= 1){
        c++;
    }
    if (af3 >= 1){
        c++;
    }
    if (af4 >= 1){
        c++;
    }
    if (af5 >= 1){
        c++;
    }
    if (af6 >= 1){
        c++;
    }
    if (af7 >= 1){
        c++;
    }
    if (af8 >= 1){
        c++;
    }

    //AUSRECHNEN
    sa = sa1+sa2+sa3+sa4+sa5+sa6+sa7+sa8;
    ex = (ex1+ex2+ex3+ex4+ex5+ex6+ex7+ex8) / b;
    af = (af1+af2+af3+af4+af5+af6+af7+af8) / c;
    exaf = ex + af;
    note = (sa + exaf) / a++ ;
    }
}

0 个答案:

没有答案