Zum Inhalt springen
View in the app

A better way to browse. Learn more.

Fachinformatiker.de

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Frame öffnen

Empfohlene Antworten

Veröffentlicht

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!!

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 );

  }

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?

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.

du hast mir schon sehr geholfen, wollte dir nicht irgendwie vor den kopf stoßen.

und nochmals danke für die antwort und den link

Archiv

Dieses Thema wurde archiviert und kann nicht mehr beantwortet werden.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.