Swing verzögerte returnrückgabe

A

Aeglasin

Gast
Hallo, also mein Problem ist aktuell, das ich gern wenn ein Nutzer einen von 2 Buttons drückt, einen Wert der die entsprechende Option repräsentiert an das, das Fenster erzeugende Objekt zurück gebe. (in etwa so wie es JOptionPane.showConformDialog(...) macht)
Aber einfach beim knopfdrücken den wert zurückgeben funktioniert bei mir nicht so recht, da zum reagieren ja immer ein Actionlistener benötigt wird der ja aber selbst eine Methode hat die auf das Actionevent eingeht, und wenn ich jetzt hier ein return abfeuern würde, würde das ja nur actionperformed Methode, welche ja einen void return wert erwartet, (also defakto garkeinen^^,) abschließen.

den Standert ConformDialog kann ich aber nicht verwenden, da der Nutzer bevor er auf den abschicken Knopf drückt noch ein paar daten eingeben muss.

Hoffe das problem is halbwegs verständlich.

hier mal die Klasse wie ich se im Moment hab:

Java:
package de.hhn.labsw.wiw.deskapp.gui;

import java.awt.BorderLayout;
import java.awt.TextArea;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import de.hhn.se.labsw.model.WiwModel;

/**
 * This code was edited or generated using CloudGarden's Jigloo SWT/Swing GUI
 * Builder, which is free for non-commercial use. If Jigloo is being used
 * commercially (ie, by a corporation, company or business for any purpose
 * whatever) then you should purchase a license for each developer using Jigloo.
 * Please visit [url=http://www.cloudgarden.com]Cloud Garden (Java Resources)[/url] for details. Use of Jigloo implies
 * acceptance of these licensing terms. A COMMERCIAL LICENSE HAS NOT BEEN
 * PURCHASED FOR THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED LEGALLY FOR
 * ANY CORPORATE OR COMMERCIAL PURPOSE.
 */
public class POIsaven extends javax.swing.JFrame {
	private JPanel Hauptpanel;
	private JTextField nameTxtfield;
	private JLabel labelLat;
	private JLabel artlabel;
	private JLabel beschreibungLabel;
	private TextArea beschreibungsTextfield;
	private JLabel infoLongi;
	private JLabel labellongi;
	private JLabel infoLati;
	private JLabel infoGeopos;
	private JLabel nameLabel;
	private final String[] poiType = WiwModel.supportedNodes;
	private JComboBox artChooser;
	private MapMouseadapter caller;
	private JButton cancelButton;
	private JButton regButton;
	private int returnwert = 0;

	/**
	 * Auto-generated main method to display this JFrame
	 */

	public POIsaven(MapMouseadapter aufrufer) {
		super();
		caller = aufrufer;
	}

	public int initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			{
				Hauptpanel = new JPanel();
				getContentPane().add(Hauptpanel, BorderLayout.CENTER);
				Hauptpanel.setLayout(null);
				Hauptpanel.setPreferredSize(new java.awt.Dimension(245, 329));
				{
					nameTxtfield = new JTextField();
					Hauptpanel.add(nameTxtfield);
					nameTxtfield.setText("POI-Name");
					nameTxtfield.setBounds(31, 35, 172, 23);
				}
				{
					nameLabel = new JLabel();
					Hauptpanel.add(nameLabel);
					nameLabel.setText("Wunschname des POI:");
					nameLabel.setBounds(43, 12, 147, 16);
				}
				{
					infoGeopos = new JLabel();
					Hauptpanel.add(infoGeopos);
					infoGeopos.setText("Globale Koordinaten des Punktes");
					infoGeopos.setBounds(31, 76, 185, 16);
				}
				{
					labelLat = new JLabel();
					Hauptpanel.add(labelLat);
					labelLat.setText("Lat:");
					labelLat.setBounds(12, 106, 19, 16);
				}
				{
					infoLati = new JLabel();
					Hauptpanel.add(infoLati);
					infoLati.setBounds(37, 109, 87, 10);
					infoLati.setText(String.valueOf(caller.lati));
				}
				{
					labellongi = new JLabel();
					Hauptpanel.add(labellongi);
					labellongi.setText("Long:");
					labellongi.setBounds(125, 106, 33, 16);
				}
				{
					infoLongi = new JLabel();
					Hauptpanel.add(infoLongi);
					infoLongi.setText(String.valueOf(caller.longi));
					infoLongi.setBounds(164, 106, 69, 16);
				}
				{
					beschreibungsTextfield = new TextArea();
					Hauptpanel.add(beschreibungsTextfield);
					beschreibungsTextfield.setText("Standartpunkt");
					beschreibungsTextfield.setBounds(12, 162, 215, 88);
				}
				{
					beschreibungLabel = new JLabel();
					Hauptpanel.add(beschreibungLabel);
					beschreibungLabel.setText("Beschreibung:");
					beschreibungLabel.setBounds(12, 140, 75, 16);
				}
				{
					ComboBoxModel artChooserModel = new DefaultComboBoxModel(
							poiType);
					artChooser = new JComboBox();
					Hauptpanel.add(artChooser);
					artChooser.setModel(artChooserModel);
					artChooser.setBounds(12, 284, 215, 18);
				}
				{
					artlabel = new JLabel();
					Hauptpanel.add(artlabel);
					artlabel.setText("POI-Art:");
					artlabel.setBounds(12, 262, 50, 20);
				}
				{
					regButton = new JButton();
					Hauptpanel.add(regButton);
					regButton.setText("Poi-Eintragen");
					regButton.setBounds(12, 331, 113, 27);
					regButton.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							// TODO Auto-generated method stub
							caller.art = (String) artChooser.getSelectedItem();
							caller.description = beschreibungsTextfield
									.getText();
							caller.name = nameTxtfield.getText();

							returnwert = 1;

						}
					});
				}
				{
					cancelButton = new JButton();
					Hauptpanel.add(cancelButton);
					cancelButton.setText("Abbrechen");
					cancelButton.setBounds(155, 331, 72, 27);
					cancelButton.addActionListener(new ActionListener() {

						@Override
						public void actionPerformed(ActionEvent e) {
							// TODO Auto-generated method stub
							returnwert = 2;
						}
					});
				}
			}
			pack();
			this.setSize(261, 396);
		} catch (Exception e) {
			// add your error handling code here
			e.printStackTrace();
		}
		// mein versuch der verzögerten rückgabe des return werts
		while (returnwert == 0) {
			try {
				wait();
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return returnwert;
	}

}
 
S

SlaterB

Gast
das erzeugte Fenster speichert seine Daten in Instanzattributen, die der 'Anzeiger' des erzeugten Fensters abrufen kann,
nachdem alles zu Ende ist
 

PrincE

Aktives Mitglied
Du brauchst ein showConfirmDialog mit zusätzlichen Textfeldern, die auf Vollständigkeit überprüft werden sollen, bevor abgeschickt werden darf?
 
A

Aeglasin

Gast
ok danke, die anleitung auf der stackoverflow-seite klingt genau nach dem was ich brauch^^ aber das AbsoluteLayout nehm ich weiterhin, mit Jigloo kann ich da besser die Komponenten so legen wie ich se ham will als mit irgend nem vorgefertigten^^
 

Neue Themen


Oben