Struktur zerstört

Diskutiere Struktur zerstört im Java Basics - Anfänger-Themen Bereich.
N

nk000

Hallo,

Ich sollte für die Schule ein Programm schreiben aber habe irgendwie die Struktur zerstört.
Könnt ihr mir helfen die wieder herzustellen?
Java:
package klausurzuhausetest;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.FlowLayout;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;

public class frame extends JFrame {

    private JPanel contentPane;
    private JTextField jTextFieldK;
    private JTextField jTextFieldS;
    int[] klausurenA = new int[4];
    int[] sonstigeA = new int[50];
    int i = 0;
    int j = 0;


    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    frame frame = new frame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public frame() {
        setTitle("Durchschnittsrechner");
        setBackground(Color.WHITE);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBackground(Color.WHITE);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
        
        JLabel jLabel1 = new JLabel("Durchschnitt");
        jLabel1.setBounds(172, 13, 80, 30);
        contentPane.add(jLabel1);
        
        JLabel jLabel2 = new JLabel("Klausuren:");
        jLabel2.setBounds(12, 60, 73, 30);
        contentPane.add(jLabel2);
        
        jTextFieldK = new JTextField();
        jTextFieldK.setBounds(136, 64, 116, 22);
        contentPane.add(jTextFieldK);
        jTextFieldK.setColumns(10);
        
        JButton jButtonEK = new JButton("Einlesen");
        jButtonEK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                    klausurenA[i] = Integer.parseInt(jTextFieldK.getText());
                    i = i + 1;
            }
        });
        jButtonEK.setBounds(267, 63, 97, 25);
        contentPane.add(jButtonEK);
        
        JLabel jLabel3 = new JLabel("Sonstige:");
        jLabel3.setBounds(12, 118, 73, 30);
        contentPane.add(jLabel3);
        
        jTextFieldS = new JTextField();
        jTextFieldS.setColumns(10);
        jTextFieldS.setBounds(136, 122, 116, 22);
        contentPane.add(jTextFieldS);
        
        JButton jButtonES = new JButton("Einlesen");
        jButtonES.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sonstigeA[j] = Integer.parseInt(jTextFieldS.getText());
                j = j + 1;
            }
        });
        jButtonES.setBounds(267, 121, 97, 25);
        contentPane.add(jButtonES);
        
        JLabel jLabelA = new JLabel("");
        jLabelA.setBackground(Color.BLACK);
        jLabelA.setBounds(136, 176, 116, 46);
        contentPane.add(jLabelA);
        
        JCheckBox jCheckBoxK = new JCheckBox("Klausur 40%");
        jCheckBoxK.setBounds(8, 16, 113, 25);
        contentPane.add(jCheckBoxK);
        
        JButton jButtonB = new JButton("Berechnen");
        jButtonB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                double n = 0.3;
                double m = 0.7;
                if(jCheckBoxK.isSelected()) {
                    n = 0.4;
                    m = 0.6;
                }
                if(klausurenA[0] == 0) {
                    n = 1;
                    m = 0;
                }
                if(sonstigeA[0] == 0) {
                    n = 0;
                    m = 1;
                }
                double ergk = 0;
                double ergs = 0;
                if(klausurenA[0] != 0) {
                    int x = 0;
                    while( x < i) {
                         ergk = klausurenA[x] + ergk;
                         x = x + 1;
                }
                if(sonstigeA[0] != 0) {
                    int y = 0;
                    while( y < j) {
                        ergs = sonstigeA[y] + ergs;
                        y = y + 1;
                }
                double ergkf = (ergk / i)*n;
                double ergsf = (ergs / j)*m;
                double ergkfsf = ergkf + ergsf;
                String ergfff = ergkfsf + "";
                jLabelA.setText(ergfff);
            }

        });
        jButtonB.setBounds(267, 197, 97, 25);
        contentPane.add(jButtonB);
        
        
    }

}
 
I

insanezulu

Was funktioniert nicht? Wie sollte es funktionieren? Welche Fehlermeldungen gibt es ggf.? Was waren deine letzten Änderungen? Schreit nach einem Rollback...
 
N

nk000

Was funktioniert nicht? Wie sollte es funktionieren? Welche Fehlermeldungen gibt es ggf.? Was waren deine letzten Änderungen? Schreit nach einem Rollback...
Ich weiß nicht genau was passiert ist aber folgende Fehlermeldung erscheint:
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Syntax error, insert "}" to complete ClassBody

at klausurzuhausetest.frame.main(frame.java:44)
 
I

insanezulu

Du hast in Zeile 144 und 145 nur zwei schließende geschweifte Klammern vergessen:
Java:
package EmailsCli1;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;

public class Frame extends JFrame {
	private JPanel contentPane;
	private JTextField jTextFieldK;
	private JTextField jTextFieldS;
	private int[] klausurenA = new int[4];
	private int[] sonstigeA = new int[50];
	private int i = 0;
	private int j = 0;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Frame frame = new Frame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public Frame() {
		setTitle("Durchschnittsrechner");
		setBackground(Color.WHITE);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(Color.WHITE);
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(null);

		JLabel jLabel1 = new JLabel("Durchschnitt");
		jLabel1.setBounds(172, 13, 80, 30);
		contentPane.add(jLabel1);

		JLabel jLabel2 = new JLabel("Klausuren:");
		jLabel2.setBounds(12, 60, 73, 30);
		contentPane.add(jLabel2);

		jTextFieldK = new JTextField();
		jTextFieldK.setBounds(136, 64, 116, 22);
		contentPane.add(jTextFieldK);
		jTextFieldK.setColumns(10);

		JButton jButtonEK = new JButton("Einlesen");
		jButtonEK.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				klausurenA[i] = Integer.parseInt(jTextFieldK.getText());
				i = i + 1;
			}
		});
		jButtonEK.setBounds(267, 63, 97, 25);
		contentPane.add(jButtonEK);

		JLabel jLabel3 = new JLabel("Sonstige:");
		jLabel3.setBounds(12, 118, 73, 30);
		contentPane.add(jLabel3);

		jTextFieldS = new JTextField();
		jTextFieldS.setColumns(10);
		jTextFieldS.setBounds(136, 122, 116, 22);
		contentPane.add(jTextFieldS);

		JButton jButtonES = new JButton("Einlesen");
		jButtonES.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				sonstigeA[j] = Integer.parseInt(jTextFieldS.getText());
				j = j + 1;
			}
		});
		jButtonES.setBounds(267, 121, 97, 25);
		contentPane.add(jButtonES);

		JLabel jLabelA = new JLabel("");
		jLabelA.setBackground(Color.BLACK);
		jLabelA.setBounds(136, 176, 116, 46);
		contentPane.add(jLabelA);

		JCheckBox jCheckBoxK = new JCheckBox("Klausur 40%");
		jCheckBoxK.setBounds(8, 16, 113, 25);
		contentPane.add(jCheckBoxK);

		JButton jButtonB = new JButton("Berechnen");
		jButtonB.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				double n = 0.3;
				double m = 0.7;
				if (jCheckBoxK.isSelected()) {
					n = 0.4;
					m = 0.6;
				}
				if (klausurenA[0] == 0) {
					n = 1;
					m = 0;
				}
				if (sonstigeA[0] == 0) {
					n = 0;
					m = 1;
				}
				double ergk = 0;
				double ergs = 0;
				if (klausurenA[0] != 0) {
					int x = 0;
					while (x < i) {
						ergk = klausurenA[x] + ergk;
						x = x + 1;
					}
					if (sonstigeA[0] != 0) {
						int y = 0;
						while (y < j) {
							ergs = sonstigeA[y] + ergs;
							y = y + 1;
						}
						double ergkf = (ergk / i) * n;
						double ergsf = (ergs / j) * m;
						double ergkfsf = ergkf + ergsf;
						String ergfff = ergkfsf + "";
						jLabelA.setText(ergfff);
					}

				}
			}
		});
		jButtonB.setBounds(267, 197, 97, 25);
		contentPane.add(jButtonB);
	}
}
 
N

nk000

Du hast in Zeile 144 und 145 nur zwei schließende geschweifte Klammern vergessen:
Java:
package EmailsCli1;

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JLabel;
import java.awt.Color;
import javax.swing.JTextField;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JCheckBox;

public class Frame extends JFrame {
    private JPanel contentPane;
    private JTextField jTextFieldK;
    private JTextField jTextFieldS;
    private int[] klausurenA = new int[4];
    private int[] sonstigeA = new int[50];
    private int i = 0;
    private int j = 0;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Frame frame = new Frame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public Frame() {
        setTitle("Durchschnittsrechner");
        setBackground(Color.WHITE);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 450, 300);
        contentPane = new JPanel();
        contentPane.setBackground(Color.WHITE);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel jLabel1 = new JLabel("Durchschnitt");
        jLabel1.setBounds(172, 13, 80, 30);
        contentPane.add(jLabel1);

        JLabel jLabel2 = new JLabel("Klausuren:");
        jLabel2.setBounds(12, 60, 73, 30);
        contentPane.add(jLabel2);

        jTextFieldK = new JTextField();
        jTextFieldK.setBounds(136, 64, 116, 22);
        contentPane.add(jTextFieldK);
        jTextFieldK.setColumns(10);

        JButton jButtonEK = new JButton("Einlesen");
        jButtonEK.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                klausurenA[i] = Integer.parseInt(jTextFieldK.getText());
                i = i + 1;
            }
        });
        jButtonEK.setBounds(267, 63, 97, 25);
        contentPane.add(jButtonEK);

        JLabel jLabel3 = new JLabel("Sonstige:");
        jLabel3.setBounds(12, 118, 73, 30);
        contentPane.add(jLabel3);

        jTextFieldS = new JTextField();
        jTextFieldS.setColumns(10);
        jTextFieldS.setBounds(136, 122, 116, 22);
        contentPane.add(jTextFieldS);

        JButton jButtonES = new JButton("Einlesen");
        jButtonES.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                sonstigeA[j] = Integer.parseInt(jTextFieldS.getText());
                j = j + 1;
            }
        });
        jButtonES.setBounds(267, 121, 97, 25);
        contentPane.add(jButtonES);

        JLabel jLabelA = new JLabel("");
        jLabelA.setBackground(Color.BLACK);
        jLabelA.setBounds(136, 176, 116, 46);
        contentPane.add(jLabelA);

        JCheckBox jCheckBoxK = new JCheckBox("Klausur 40%");
        jCheckBoxK.setBounds(8, 16, 113, 25);
        contentPane.add(jCheckBoxK);

        JButton jButtonB = new JButton("Berechnen");
        jButtonB.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                double n = 0.3;
                double m = 0.7;
                if (jCheckBoxK.isSelected()) {
                    n = 0.4;
                    m = 0.6;
                }
                if (klausurenA[0] == 0) {
                    n = 1;
                    m = 0;
                }
                if (sonstigeA[0] == 0) {
                    n = 0;
                    m = 1;
                }
                double ergk = 0;
                double ergs = 0;
                if (klausurenA[0] != 0) {
                    int x = 0;
                    while (x < i) {
                        ergk = klausurenA[x] + ergk;
                        x = x + 1;
                    }
                    if (sonstigeA[0] != 0) {
                        int y = 0;
                        while (y < j) {
                            ergs = sonstigeA[y] + ergs;
                            y = y + 1;
                        }
                        double ergkf = (ergk / i) * n;
                        double ergsf = (ergs / j) * m;
                        double ergkfsf = ergkf + ergsf;
                        String ergfff = ergkfsf + "";
                        jLabelA.setText(ergfff);
                    }

                }
            }
        });
        jButtonB.setBounds(267, 197, 97, 25);
        contentPane.add(jButtonB);
    }
}
Ok danke. Ich denke jetzt kann ich noch die letzen Fehler beheben.:)
 
I

insanezulu

Und nicht wundern... bei mir heißt das package EmailsCli1 und ich habe aus Konformität aus frame Frame gemacht.
 
Thema: 

Struktur zerstört

Passende Stellenanzeigen aus deiner Region:
Anzeige

Neue Themen

Anzeige

Anzeige
Oben