Zum Inhalt springen

Empfohlene Beiträge

Geschrieben

Versuche mich erst seit ganz kurzer Zeit an Java und habe nun folgendes Problem:

Ich habe mit dem JBuilder ein neues Projekt erstellt und habe darin 2 Frames.

Ich will nun aus dem 1.frame heraus den 2. Frame öffnen.

Kann mir bitte jemand helfen?

ich sterbe noch weil ich das nicht hinkriege.

Danke schonmal!!

Geschrieben

das ist eine methode um nen frame/dialog anzuzeigen ... die musst du einfach nur mit nem button laden ... (actionlistener)


public void showDialog() {

    this.setSize( new Dimension( 220, 275 ) );

    this.setTitle( "about" );

    this.getContentPane().setLayout( null );

    // set location == center of screen

    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

    Dimension frameSize = this.getSize();

    if ( frameSize.height > screenSize.height )

    {

      frameSize.height = screenSize.height;

    }

    if ( frameSize.width > screenSize.width )

    {

      frameSize.width = screenSize.width;

    }

    this.setLocation( ( screenSize.width - frameSize.width ) / 2, ( screenSize.height - frameSize.height ) / 2 );

    jbInit();

    this.setModal(true);

    this.setVisible( true );

  }

Geschrieben

hab das jetzt ganz einfach so gelöst:

...

...

...

JFrame Frame2_Eingabe = new JFrame();

...

...

...

...

void jButtonInput_actionPerformed(ActionEvent e) {

Frame2_Eingabe.show();

}

Jetzt hab ich aber das Problem, dass ein Fenster aufgeht und irgendwas von unvollständiger Konfiguration da steht.

ein kollege meinte ich hätte gar keine main-methode oder sowas.

hier also mal der komplette code:

package birthday;

import java.awt.*;

import javax.swing.*;

import com.borland.jbcl.layout.*;

import java.awt.event.*;

/**

* Title:

* Description:

* Copyright: Copyright © 2003

* Company:

* @author

* @version 1.0

*/

public class Frame1 extends JFrame {

XYLayout xYLayout1 = new XYLayout();

JComboBox jComboBox1 = new JComboBox();

JLabel daten = new JLabel();

Scrollbar scrollbar1 = new Scrollbar();

JButton jButtonInput = new JButton();

JFrame Frame2_Eingabe = new JFrame();

public Frame1() {

try {

jbInit();

}

catch(Exception e) {

e.printStackTrace();

}

}

private void jbInit() throws Exception {

this.getContentPane().setLayout(xYLayout1);

this.getContentPane().setBackground(SystemColor.activeCaptionBorder);

jButtonInput.setText("Eingabe");

jButtonInput.addActionListener(new java.awt.event.ActionListener() {

public void actionPerformed(ActionEvent e) {

jButtonInput_actionPerformed(e);

}

});

this.getContentPane().add(jComboBox1, new XYConstraints(39, 28, 45, 20));

this.getContentPane().add(daten, new XYConstraints(35, 70, 337, 203));

this.getContentPane().add(scrollbar1, new XYConstraints(374, 86, -1, 210));

this.getContentPane().add(jButtonInput, new XYConstraints(308, 14, 86, 24));

jComboBox1.addItem("A");

jComboBox1.addItem("B");

jComboBox1.addItem("C");

jComboBox1.addItem("D");

jComboBox1.addItem("E");

jComboBox1.addItem("F");

jComboBox1.addItem("G");

jComboBox1.addItem("H");

jComboBox1.addItem("I");

jComboBox1.addItem("J");

jComboBox1.addItem("K");

jComboBox1.addItem("L");

jComboBox1.addItem("M");

jComboBox1.addItem("N");

jComboBox1.addItem("O");

jComboBox1.addItem("P");

jComboBox1.addItem("Q");

jComboBox1.addItem("R");

jComboBox1.addItem("S");

jComboBox1.addItem("T");

jComboBox1.addItem("U");

jComboBox1.addItem("V");

jComboBox1.addItem("W");

jComboBox1.addItem("X");

jComboBox1.addItem("Y");

jComboBox1.addItem("Z");

}

void jButtonInput_actionPerformed(ActionEvent e) {

Frame2_Eingabe.show();

}

}

Hat jemand ein Herz für Newbies und kann mir auch diesmal helfen?

Geschrieben

ich weiss zwar nicht, was an der vorigen antwort nich geholfen sein soll, aber egal ...

dir fehlt auf jeden fall ne main(String args[]) methode. ohne die startet ein prog normal nicht.

dann wuerd ich mal ins java handbuch (links) reinschauen und mir die swing kapitel durchlesen ...

im uebrigen verwendet man normal pro frame eine klasse. d.h. fuer frame2 solltest du ne eigene klasse anlegen.

Erstelle ein Benutzerkonto oder melde Dich an, um zu kommentieren

Du musst ein Benutzerkonto haben, um einen Kommentar verfassen zu können

Benutzerkonto erstellen

Neues Benutzerkonto für unsere Community erstellen. Es ist einfach!

Neues Benutzerkonto erstellen

Anmelden

Du hast bereits ein Benutzerkonto? Melde Dich hier an.

Jetzt anmelden

Fachinformatiker.de, 2024 by SE Internet Services

fidelogo_small.png

Schicke uns eine Nachricht!

Fachinformatiker.de ist die größte IT-Community
rund um Ausbildung, Job, Weiterbildung für IT-Fachkräfte.

Fachinformatiker.de App

Download on the App Store
Get it on Google Play

Kontakt

Hier werben?
Oder sende eine E-Mail an

Social media u. feeds

Jobboard für Fachinformatiker und IT-Fachkräfte

×
×
  • Neu erstellen...