SWT In welche Ebene gehört dann die function()

NochNixBlicker

Bekanntes Mitglied
Java:
  public TriSdw() {
    JFormattedTextField tfvon = new JFormattedTextField(formatZahl);
     tfvon.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent arg0) {
            Function function = new function()
       }
     });
   }

// Hierhin?
private function() {
...
}
 
Tja, wo soll man da anfangen?
Bei public TriSdw() und private function() handelt es sich nicht um Methoden, da die Deklaration des Rückgabewertes fehlt. Demnach muss es sich um Konstruktoren handeln. Laut Anzahl der geschweiften Klammern sind beide Konstruktoren auf derselben Ebene und gehören damit zur selben Klasse, was aber nicht möglich ist, da sie (die Konstruktoren) unterschiedliche Namen haben.
Nehmen wir mal an, dass private function() tatsächlich der private Konstruktor der function-Klasse ist, und die function-Klasse eine innere Klasse der TriSdw-Klasse ist. Dann ist aber die Instanziierung in der focusLost()-Methode mit sehr hoher Wahrscheinlichkeit falsch. Du deklarierst die Variable "function" als Instanz der Klasse "Function" (grossgeschrieben) und rufst den Konstruktor der Klasse "function" (kleingeschrieben) auf. Und das geht überhaupt nur dann wenn die "function"-Klasse von "Function" abgeleitet ist oder "Function" ein interface ist, was von "function" implementiert wird. In beiden Fällen wäre die Namensgebung extrem verwirrend und nicht in Übereinstimmung mit den Java-Namenskonventionen.
 
Sorry für die Verwirrung ich poste mal den kompletten Code der Klasse:
Java:
package einsatz;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.text.NumberFormatter;
import javax.swing.JButton;
import javax.swing.JFormattedTextField;

import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.text.NumberFormat;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;

public class TriSdw extends JPanel {
   /**
    *
    */
   private static final long serialVersionUID = 1L;

   public TriSdw() {
     NumberFormat formatZahl = NumberFormat.getInstance();
  formatZahl.setGroupingUsed(false);
  NumberFormatter formatter = new NumberFormatter(formatZahl);
  formatter.setAllowsInvalid(false);
     
     GridBagLayout gridBagLayout = new GridBagLayout();
     gridBagLayout.columnWidths = new int[] { 100, 50, 50, 140, 0 };
     gridBagLayout.rowHeights = new int[] { 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 0 };
     gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 1.0, 0.0, Double.MIN_VALUE };
     gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE };
     setLayout(gridBagLayout);

     JLabel lblVeranstaltung = new JLabel("Veranstaltung:");
     lblVeranstaltung.setHorizontalAlignment(SwingConstants.RIGHT);
     lblVeranstaltung.setBounds(10, 10, 12, 10);
     GridBagConstraints gbc_lblVeranstaltung = new GridBagConstraints();
     gbc_lblVeranstaltung.fill = GridBagConstraints.BOTH;
     gbc_lblVeranstaltung.insets = new Insets(0, 0, 5, 5);
     gbc_lblVeranstaltung.gridx = 0;
     gbc_lblVeranstaltung.gridy = 1;
     this.add(lblVeranstaltung, gbc_lblVeranstaltung);

     JFormattedTextField tfVeranstaltung = new JFormattedTextField();
     GridBagConstraints gbc_tfVeranstaltung = new GridBagConstraints();
     gbc_tfVeranstaltung.gridwidth = 2;
     gbc_tfVeranstaltung.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfVeranstaltung.insets = new Insets(0, 0, 5, 5);
     gbc_tfVeranstaltung.gridx = 1;
     gbc_tfVeranstaltung.gridy = 1;
     add(tfVeranstaltung, gbc_tfVeranstaltung);

     JLabel lblGastgeber = new JLabel("Gastgeber:");
     lblGastgeber.setHorizontalAlignment(SwingConstants.RIGHT);
     lblGastgeber.setBounds(10, 23, 12, 10);
     GridBagConstraints gbc_lblGastgeber = new GridBagConstraints();
     gbc_lblGastgeber.fill = GridBagConstraints.BOTH;
     gbc_lblGastgeber.insets = new Insets(0, 0, 5, 5);
     gbc_lblGastgeber.gridx = 0;
     gbc_lblGastgeber.gridy = 2;
     this.add(lblGastgeber, gbc_lblGastgeber);

     JFormattedTextField tfGastgeber = new JFormattedTextField();
     GridBagConstraints gbc_tfGastgeber = new GridBagConstraints();
     gbc_tfGastgeber.gridwidth = 2;
     gbc_tfGastgeber.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfGastgeber.insets = new Insets(0, 0, 5, 5);
     gbc_tfGastgeber.gridx = 1;
     gbc_tfGastgeber.gridy = 2;
     add(tfGastgeber, gbc_tfGastgeber);

     JLabel lblGewässer = new JLabel("Gewässer:");
     lblGewässer.setHorizontalAlignment(SwingConstants.RIGHT);
     lblGewässer.setBounds(10, 36, 12, 10);
     GridBagConstraints gbc_lblGewässer = new GridBagConstraints();
     gbc_lblGewässer.fill = GridBagConstraints.BOTH;
     gbc_lblGewässer.insets = new Insets(0, 0, 5, 5);
     gbc_lblGewässer.gridx = 0;
     gbc_lblGewässer.gridy = 3;
     this.add(lblGewässer, gbc_lblGewässer);

     JFormattedTextField tfGewaesser = new JFormattedTextField();
     GridBagConstraints gbc_tfGewaesser = new GridBagConstraints();
     gbc_tfGewaesser.gridwidth = 2;
     gbc_tfGewaesser.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfGewaesser.insets = new Insets(0, 0, 5, 5);
     gbc_tfGewaesser.gridx = 1;
     gbc_tfGewaesser.gridy = 3;
     add(tfGewaesser, gbc_tfGewaesser);

     JLabel lblvon = new JLabel("von:");
     lblvon.setHorizontalAlignment(SwingConstants.RIGHT);
     lblvon.setBounds(10, 49, 12, 10);
     GridBagConstraints gbc_lblvon = new GridBagConstraints();
     gbc_lblvon.anchor = GridBagConstraints.EAST;
     gbc_lblvon.fill = GridBagConstraints.VERTICAL;
     gbc_lblvon.insets = new Insets(0, 0, 5, 5);
     gbc_lblvon.gridx = 0;
     gbc_lblvon.gridy = 4;
     this.add(lblvon, gbc_lblvon);
     
     JFormattedTextField tfvon = new JFormattedTextField(formatZahl);
     tfvon.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent arg0) {
       }
     });
     GridBagConstraints gbc_tfvon = new GridBagConstraints();
     gbc_tfvon.insets = new Insets(0, 0, 5, 5);
     gbc_tfvon.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfvon.gridx = 1;
     gbc_tfvon.gridy = 4;
     add(tfvon, gbc_tfvon);
     
     JFormattedTextField tfSchwimmzeit = new JFormattedTextField(formatZahl);
     tfSchwimmzeit.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent e) {
       }
     });
     GridBagConstraints gbc_tfSchwimmzeit = new GridBagConstraints();
     gbc_tfSchwimmzeit.insets = new Insets(0, 0, 5, 5);
     gbc_tfSchwimmzeit.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfSchwimmzeit.gridx = 2;
     gbc_tfSchwimmzeit.gridy = 4;
     add(tfSchwimmzeit, gbc_tfSchwimmzeit);

     JLabel lblMittlereSchwimmzeit = new JLabel("mittlere Schwimmzeit:");
     lblMittlereSchwimmzeit.setHorizontalAlignment(SwingConstants.RIGHT);
     lblMittlereSchwimmzeit.setBounds(10, 88, 12, 10);
     GridBagConstraints gbc_lblMittlereSchwimmzeit = new GridBagConstraints();
     gbc_lblMittlereSchwimmzeit.anchor = GridBagConstraints.WEST;
     gbc_lblMittlereSchwimmzeit.fill = GridBagConstraints.VERTICAL;
     gbc_lblMittlereSchwimmzeit.insets = new Insets(0, 0, 5, 0);
     gbc_lblMittlereSchwimmzeit.gridx = 3;
     gbc_lblMittlereSchwimmzeit.gridy = 4;
     this.add(lblMittlereSchwimmzeit, gbc_lblMittlereSchwimmzeit);

     JLabel lblbis = new JLabel("bis:");
     lblbis.setHorizontalAlignment(SwingConstants.RIGHT);
     lblbis.setBounds(10, 62, 12, 10);
     GridBagConstraints gbc_lblbis = new GridBagConstraints();
     gbc_lblbis.anchor = GridBagConstraints.EAST;
     gbc_lblbis.fill = GridBagConstraints.VERTICAL;
     gbc_lblbis.insets = new Insets(0, 0, 5, 5);
     gbc_lblbis.gridx = 0;
     gbc_lblbis.gridy = 5;
     this.add(lblbis, gbc_lblbis);
     
     JFormattedTextField tfbis = new JFormattedTextField(formatZahl);
     tfbis.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent e) {
       }
     });
     GridBagConstraints gbc_tfbis = new GridBagConstraints();
     gbc_tfbis.insets = new Insets(0, 0, 5, 5);
     gbc_tfbis.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfbis.gridx = 1;
     gbc_tfbis.gridy = 5;
     add(tfbis, gbc_tfbis);
     
     JFormattedTextField tfAbweichung = new JFormattedTextField(formatZahl);
     tfAbweichung.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent e) {
       }
     });
     GridBagConstraints gbc_tfAbweichung = new GridBagConstraints();
     gbc_tfAbweichung.insets = new Insets(0, 0, 5, 5);
     gbc_tfAbweichung.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfAbweichung.gridx = 2;
     gbc_tfAbweichung.gridy = 5;
     add(tfAbweichung, gbc_tfAbweichung);

     JLabel lblMittlereAbweichung = new JLabel("mittlere Abweichung:");
     lblMittlereAbweichung.setHorizontalAlignment(SwingConstants.RIGHT);
     lblMittlereAbweichung.setBounds(10, 101, 12, 10);
     GridBagConstraints gbc_lblMittlereAbweichung = new GridBagConstraints();
     gbc_lblMittlereAbweichung.anchor = GridBagConstraints.WEST;
     gbc_lblMittlereAbweichung.fill = GridBagConstraints.VERTICAL;
     gbc_lblMittlereAbweichung.insets = new Insets(0, 0, 5, 0);
     gbc_lblMittlereAbweichung.gridx = 3;
     gbc_lblMittlereAbweichung.gridy = 5;
     this.add(lblMittlereAbweichung, gbc_lblMittlereAbweichung);

     JLabel lblStrecke = new JLabel("Strecke:");
     lblStrecke.setHorizontalAlignment(SwingConstants.RIGHT);
     lblStrecke.setBounds(10, 75, 12, 10);
     GridBagConstraints gbc_lblStrecke = new GridBagConstraints();
     gbc_lblStrecke.anchor = GridBagConstraints.EAST;
     gbc_lblStrecke.fill = GridBagConstraints.VERTICAL;
     gbc_lblStrecke.insets = new Insets(0, 0, 5, 5);
     gbc_lblStrecke.gridx = 0;
     gbc_lblStrecke.gridy = 6;
     this.add(lblStrecke, gbc_lblStrecke);
     
     JFormattedTextField tfStrecke = new JFormattedTextField(formatZahl);
     tfStrecke.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent e) {
       }
     });
     GridBagConstraints gbc_tfStrecke = new GridBagConstraints();
     gbc_tfStrecke.insets = new Insets(0, 0, 5, 5);
     gbc_tfStrecke.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfStrecke.gridx = 1;
     gbc_tfStrecke.gridy = 6;
     add(tfStrecke, gbc_tfStrecke);
     
     JFormattedTextField tfMittlereV = new JFormattedTextField(formatZahl);
     tfMittlereV.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent e) {
       }
     });
     GridBagConstraints gbc_tfMittlereV = new GridBagConstraints();
     gbc_tfMittlereV.insets = new Insets(0, 0, 5, 5);
     gbc_tfMittlereV.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfMittlereV.gridx = 2;
     gbc_tfMittlereV.gridy = 6;
     add(tfMittlereV, gbc_tfMittlereV);

     JLabel lblMittlere_Geschwindigkeit = new JLabel("mittlere Geschwindigkeit:");
     lblMittlere_Geschwindigkeit.setHorizontalAlignment(SwingConstants.RIGHT);
     lblMittlere_Geschwindigkeit.setBounds(10, 114, 12, 10);
     GridBagConstraints gbc_lblMittlere_Geschwindigkeit = new GridBagConstraints();
     gbc_lblMittlere_Geschwindigkeit.anchor = GridBagConstraints.WEST;
     gbc_lblMittlere_Geschwindigkeit.fill = GridBagConstraints.VERTICAL;
     gbc_lblMittlere_Geschwindigkeit.insets = new Insets(0, 0, 5, 0);
     gbc_lblMittlere_Geschwindigkeit.gridx = 3;
     gbc_lblMittlere_Geschwindigkeit.gridy = 6;
     this.add(lblMittlere_Geschwindigkeit, gbc_lblMittlere_Geschwindigkeit);

     JLabel lblTeilnehmer = new JLabel("Teilnehmer:");
     lblTeilnehmer.setHorizontalAlignment(SwingConstants.RIGHT);
     GridBagConstraints gbc_lblTeilnehmer = new GridBagConstraints();
     gbc_lblTeilnehmer.anchor = GridBagConstraints.EAST;
     gbc_lblTeilnehmer.fill = GridBagConstraints.VERTICAL;
     gbc_lblTeilnehmer.insets = new Insets(0, 0, 5, 5);
     gbc_lblTeilnehmer.gridx = 0;
     gbc_lblTeilnehmer.gridy = 7;
     add(lblTeilnehmer, gbc_lblTeilnehmer);
     
     JFormattedTextField tfTeilnehmer = new JFormattedTextField(formatZahl);
     tfTeilnehmer.addFocusListener(new FocusAdapter() {
       @Override
       public void focusLost(FocusEvent e) {
       }
     });
     GridBagConstraints gbc_tfTeilnehmer = new GridBagConstraints();
     gbc_tfTeilnehmer.insets = new Insets(0, 0, 5, 5);
     gbc_tfTeilnehmer.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfTeilnehmer.gridx = 1;
     gbc_tfTeilnehmer.gridy = 7;
     add(tfTeilnehmer, gbc_tfTeilnehmer);

     JLabel lblDatum = new JLabel("Datum:");
     lblDatum.setHorizontalAlignment(SwingConstants.RIGHT);
     GridBagConstraints gbc_lblDatum = new GridBagConstraints();
     gbc_lblDatum.anchor = GridBagConstraints.EAST;
     gbc_lblDatum.fill = GridBagConstraints.VERTICAL;
     gbc_lblDatum.insets = new Insets(0, 0, 5, 5);
     gbc_lblDatum.gridx = 0;
     gbc_lblDatum.gridy = 8;
     add(lblDatum, gbc_lblDatum);
     
     JFormattedTextField tfDatum = new JFormattedTextField();
     GridBagConstraints gbc_tfDatum = new GridBagConstraints();
     gbc_tfDatum.insets = new Insets(0, 0, 5, 5);
     gbc_tfDatum.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfDatum.gridx = 1;
     gbc_tfDatum.gridy = 8;
     add(tfDatum, gbc_tfDatum);
     
     JFormattedTextField tfZeit = new JFormattedTextField();
     GridBagConstraints gbc_tfZeit = new GridBagConstraints();
     gbc_tfZeit.insets = new Insets(0, 0, 5, 5);
     gbc_tfZeit.fill = GridBagConstraints.HORIZONTAL;
     gbc_tfZeit.gridx = 2;
     gbc_tfZeit.gridy = 8;
     add(tfZeit, gbc_tfZeit);

     JLabel lblUhrzeit = new JLabel("Uhrzeit:");
     GridBagConstraints gbc_lblUhrzeit = new GridBagConstraints();
     gbc_lblUhrzeit.fill = GridBagConstraints.BOTH;
     gbc_lblUhrzeit.insets = new Insets(0, 0, 5, 0);
     gbc_lblUhrzeit.gridx = 3;
     gbc_lblUhrzeit.gridy = 8;
     add(lblUhrzeit, gbc_lblUhrzeit);

     JButton btnStart = new JButton("Start");
     GridBagConstraints gbc_btnStart = new GridBagConstraints();
     gbc_btnStart.fill = GridBagConstraints.BOTH;
     gbc_btnStart.insets = new Insets(0, 0, 0, 5);
     gbc_btnStart.gridx = 1;
     gbc_btnStart.gridy = 9;
     add(btnStart, gbc_btnStart);
   }
}

Wo muss/kann ich jetzt eine Funktion hinschreiben, die alle Panels dieses Tabbedpane zugänglich (nicht eingegraut macht? Das geht doch einfach mit ein paar Zeilen, oder?
 
Ich sehe weder was von "alle Panels" (sondern nur ein einziges), und ich sehe auch nichts von JTabbedPane.
Ausserdem kannst du die bei den ganzen JLabels und JTextFields das manuelle setzen der Bounds sparen. Das wird vom GridBagLayout übernommen.
Edit: Was hat das ganze mit SWT zu tun?
 
Zuletzt bearbeitet:
Also die einzelnen TabbedPanes sind in eigene Klassen ausgelagert. Und sorry ja, ich gebe dir Recht, denn ich hatte nämlich die falsche Klasse gepasted bzw. ich habe nicht zuende gedacht.

Die Hauptklasse
Java:
package einsatz;

import java.util.Date;

import javax.swing.JDialog;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;

public class Tri extends JDialog {

   /**
    *
    */
   private static final long serialVersionUID = 1L;

   /**
    * Launch the application.
    */
   /**
    * Create the dialog.
    */
   
   int teilnehmer;
   
   public Tri() {
     
     String veranstaltung;
     String gastgeber;
     String gewaesser;
     Float von;
     Float bis;
     Float strecke;
     Date mittlereSchwimmzeit;
     Date mittlereAbweichung;
     Date datum;
     Date zeit;
     
     setBounds(200, 200, 800, 400);
     JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
     getContentPane().add(tabbedPane);
     this.setVisible(true);
     this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

     TriSdw sdw = new TriSdw();
     tabbedPane.addTab("Stammdaten", null, sdw, null);
     tabbedPane.setEnabledAt(0, true);

     TriBsp bsp = new TriBsp();
     tabbedPane.addTab("Beispielwerte", null, bsp, null);
     tabbedPane.setEnabledAt(1, true);

     TriNvt nvt = new TriNvt();
     tabbedPane.addTab("Normalverteilung", null, nvt, null);
     tabbedPane.setEnabledAt(2, true);

     TriZus zus = new TriZus();
     tabbedPane.addTab("Zeiten und Strecken", null, zus, null);
     tabbedPane.setEnabledAt(3, true);

     TriBpl bpl = new TriBpl();
     tabbedPane.addTab("Bedarfsplanung", null, bpl, null);
     tabbedPane.setEnabledAt(4, true);

   }
}

Die Setbounds sind vom Windowbuilder.
Und wenn im TabbedPane sdw die notwendigen Felder eingegeben sind, sollen die anderen TabbedPanes aktivierbar werden. Könntest du mir bitte ein Beispiel für ein TabbedPane codieren?
 
Jetzt da ich deine Fragen lese, ärgere ich mich über meine Frage. Da ich mich immer wieder gedanklich mit meinem Projekt auseinandersetze, ist es für mich selbsterklärend, was ich meine.
Dein Frage verdeutlicht mir, wie es dem PC geht. Er weiss von nichts und man muss alles von Adam und Eva (oder dem Entrypoint) erklären. Dies ist KEIN Vorwurf. Also notwendig zur Berechnung der Kurve, damit zur Aktivierung der JTabbedPanes sind folgende Varablen:
Java:
public class Tri extends JDialog {

   int teilnehmer;
   Float von;
   Float bis;
   Float strecke;
   Date mittlereSchwimmzeit;
   Date mittlereAbweichung;
 
public Tri() {
Wobei bis-von=Strecke und dein Vermutung !null hat gestimmt. Ich hoffe die Position für die Deklaration der Variblen ist richtig, denn die Variablen werden ja im einen JTabbedPane eingegeben, und dann in einem anderen Verwendet. Wobei die JTabbedPanes, wie schon erwähnt in jeweils eine eigene Klasse ausgelagert sind.

SWT deshalb weil JTabbedPane doch eine SWT-Komponente ist, oder bin ich da auf dem falschen Dampfer?
 
JTabbedPane ist eine Swing Komponente. SWT steht für Standard Widget Toolkit und ist eine Alternative zu Swing.

Anstatt der Wrapper Klasse Float solltest du lieber den primitiven Typen float verwenden.
 
Du möchtest scheinbar den Wert der Variablen in einem der JPanels setzen. Dies wird aber nicht gehen! Number, String, und Date sind immutable.
Mache aus deinen Parametern erstmal ein Objekt. So wie es aussieht, reden wir über ein Wettschwimmen.
Wenn das Objekt soweit steht, dann kannst du darüber nachdenken, wie man seine Eigenschaften durch eine Gui ändert.
 

Zurück
Oben