JOptionPane schließt sich nicht wieder

R

RedVelvet

Mitglied
Moin!
Bin absoluter Anfänger und muss für eine Hausarbeit was in Java coden. Hier habe ich einen JOptionPane eingesetzt um vor einer zu großen Zahl zu warnen, man kann nur das Fenster nicht wieder schließen:

Java:
OwnPositionLatM = new JTextField();
        OwnPositionLatM.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LatMOwn = Integer.parseInt(OwnPositionLatM.getText());
                for (LatMOwn = 0; LatMOwn < 60; ) {
            JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ", JOptionPane.INFORMATION_MESSAGE);
               
                 

                    OwnPositionLatM.setText("");
               
                }
                            }
        });

Vielleicht hat ja jemand ne Idee....

Hier ist sonst auch der komplette code (bei weitem noch nicht fertig):

Java:
import java.awt.BorderLayout;
import java.awt.EventQueue;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import de.jade.kursarbeit.ComboBoxListeners.ListObject;

import javax.swing.JTextField;
import javax.swing.JComboBox;
import javax.swing.JButton;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.JLabel;
import javax.swing.JOptionPane;

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

public class JFrame extends javax.swing.JFrame {

    private JPanel contentPane;
    private JTextField OwnPositionLatD;
    private JTextField POILatD;
    private JTextField OwnPositionLongD;
    private JTextField POILongD;
    private JTextField STimeIncident;
    private JTextField STime;

    private JTextPane txtPaneSAR;

    private String[] VesselsString = { "Number of Vessels involved", "1", "2", "3", "4", "5", "more than 5" };

    private String[] SO = { "Search Object", "Person in water", "4-Person liferaft", "6-Person liferaft",
            "15-Person liferaft", "25-Person liferaft", "Boat >5m", "Boat 7m", "Boat 12m", "Boat 24m" };

    private String[] WindSpeed = { "Wind", "Wind < 15kn", "Wind > 15kn" };

    private String[] Visi = { "Visibility", "3nm", "5nm", "10nm", "15nm", "20nm" };

    private String[] Lat = { "N", "S" };

    private String[] Long = { "E", "W" };
    private JTextField OwnPositionLatM;
    private JTextField POILatM;
    private JTextField OwnPositionLongM;
    private JTextField POILongM;
    int LatDOwn, LatMOwn, LatOwn, LongDOwn, LongMOwn, LongOwn, LatDPOI, LatMPOI, LatPOI, LongDPOI, LongMPOI, LongPOI, TimeInci, TimeNow;

    public JFrame() {

/*        LatOwn = LatDOwn + LatMOwn / 60;
        LongOwn = LongDOwn + LongMOwn / 60;

        LatPOI = LatDPOI + LatMPOI / 60;
        LongPOI = LongDPOI + LongMPOI / 60;

        System.out.println(LatOwn + "°N");*/

        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 630, 477);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel lblOwnPosition = new JLabel("Own Position");
        lblOwnPosition.setBounds(30, 31, 102, 30);
        contentPane.add(lblOwnPosition);

        OwnPositionLatD = new JTextField();
        OwnPositionLatD.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LatDOwn = Integer.parseInt(OwnPositionLatD.getText());

            }
        });
        OwnPositionLatD.setBounds(156, 35, 37, 22);
        contentPane.add(OwnPositionLatD);
        OwnPositionLatD.setColumns(10);

        OwnPositionLatM = new JTextField();
        OwnPositionLatM.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LatMOwn = Integer.parseInt(OwnPositionLatM.getText());
                for (LatMOwn = 0; LatMOwn < 60; ) {
                    JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ", JOptionPane.INFORMATION_MESSAGE);
               
               

                    OwnPositionLatM.setText("");
               
                }
                            }
        });
           
           
       
        OwnPositionLatM.setColumns(10);
        OwnPositionLatM.setBounds(235, 35, 37, 22);
        contentPane.add(OwnPositionLatM);

        JComboBox N_S = new JComboBox(Lat);
        N_S.setBounds(314, 35, 44, 22);
        contentPane.add(N_S);

        OwnPositionLongD = new JTextField();
        OwnPositionLongD.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LongDOwn = Integer.parseInt(OwnPositionLongD.getText());

            }
        });
        OwnPositionLongD.setBounds(384, 35, 37, 22);
        contentPane.add(OwnPositionLongD);
        OwnPositionLongD.setColumns(10);

        OwnPositionLongM = new JTextField();
        OwnPositionLongM.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LongMOwn = Integer.parseInt(OwnPositionLongM.getText());

            }
        });
        OwnPositionLongM.setColumns(10);
        OwnPositionLongM.setBounds(467, 35, 37, 22);
        contentPane.add(OwnPositionLongM);

        JComboBox E_W = new JComboBox(Long);
        E_W.setBounds(547, 35, 44, 22);
        contentPane.add(E_W);

        JLabel lblPositionOfIncident = new JLabel("Position of Incident");
        lblPositionOfIncident.setBounds(30, 77, 135, 16);
        contentPane.add(lblPositionOfIncident);

        POILatD = new JTextField();
        POILatD.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            LatDPOI = Integer.parseInt(POILatD.getText());
        }
    });
        POILatD.setBounds(156, 74, 37, 22);
        contentPane.add(POILatD);
        POILatD.setColumns(10);

        POILatM = new JTextField();
        POILatM.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LatMPOI = Integer.parseInt(POILatM.getText());
            }
        });
        POILatM.setColumns(10);
        POILatM.setBounds(235, 74, 37, 22);
        contentPane.add(POILatM);

        JComboBox N_SPOI = new JComboBox(Lat);
        N_SPOI.setBounds(314, 74, 44, 22);
        contentPane.add(N_SPOI);

        POILongD = new JTextField();
        POILongD.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LongDPOI = Integer.parseInt(POILongD.getText());
            }
        });
        POILongD.setBounds(384, 74, 37, 22);
        contentPane.add(POILongD);
        POILongD.setColumns(10);

        POILongM = new JTextField();
        POILongM.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                LongMPOI = Integer.parseInt(POILongM.getText());
            }
        });
        POILongM.setColumns(10);
        POILongM.setBounds(467, 74, 37, 22);
        contentPane.add(POILongM);

        JComboBox E_WPOI = new JComboBox(Long);
        E_WPOI.setBounds(547, 74, 44, 22);
        contentPane.add(E_WPOI);

        JLabel lblShipTimeIncident = new JLabel("Time of Incident UTC");
        lblShipTimeIncident.setBounds(30, 127, 135, 16);
        contentPane.add(lblShipTimeIncident);

        STimeIncident = new JTextField();
        STimeIncident.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                TimeInci = Integer.parseInt(STimeIncident.getText());
               
            }
        });
        STimeIncident.setBounds(156, 124, 116, 22);
        contentPane.add(STimeIncident);
        STimeIncident.setColumns(10);

        JLabel lblShipTime = new JLabel("Time now UTC");
        lblShipTime.setBounds(326, 127, 85, 16);
        contentPane.add(lblShipTime);

        STime = new JTextField();
        STime.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                TimeNow = Integer.parseInt(STime.getText());
            }
        });
        STime.setBounds(423, 124, 116, 22);
        contentPane.add(STime);
        STime.setColumns(10);

        JComboBox Visibility = new JComboBox(Visi);
        Visibility.setBounds(427, 254, 135, 22);
        contentPane.add(Visibility);

        JComboBox SearchObject = new JComboBox(SO);
        SearchObject.setBounds(427, 184, 135, 22);
        contentPane.add(SearchObject);

        JComboBox Wind = new JComboBox(WindSpeed);
        Wind.setBounds(111, 184, 87, 22);
        contentPane.add(Wind);

        JComboBox Vessels = new JComboBox(VesselsString);
        Vessels.addActionListener(new ActionListener() {

            public void actionPerformed(ActionEvent event) {

                String selectedItem = (String) Vessels.getSelectedItem();

                if (selectedItem.equals("2")) {
                    txtPaneSAR.setText("Parallel Track Pattern 2");
                } else if (selectedItem.equals("3")) {
                    txtPaneSAR.setText("Parallel Track Pattern 3");
                } else if (selectedItem.equals("4")) {
                    txtPaneSAR.setText("Parallel Track Pattern 4");
                } else if (selectedItem.equals("5")) {
                    txtPaneSAR.setText("Parallel Track Pattern 5");
                } else if (selectedItem.equals("more than 5")) {
                    txtPaneSAR.setText("Parallel Track Pattern 5");
                }
            }
        });

        Vessels.setBounds(69, 254, 184, 22);
        contentPane.add(Vessels);

        JLabel lblSearchPattern = new JLabel("Recommended Search Pattern");
        lblSearchPattern.setBounds(30, 343, 194, 16);
        contentPane.add(lblSearchPattern);

        txtPaneSAR = new JTextPane();
        txtPaneSAR.setBounds(271, 343, 223, 22);
        contentPane.add(txtPaneSAR);

        JLabel lblDegree1 = new JLabel("°");
        lblDegree1.setBounds(203, 38, 23, 16);
        contentPane.add(lblDegree1);

        JLabel lblDegree3 = new JLabel("°");
        lblDegree3.setBounds(205, 77, 23, 16);
        contentPane.add(lblDegree3);

        JLabel lblDegree2 = new JLabel("°");
        lblDegree2.setBounds(432, 38, 23, 16);
        contentPane.add(lblDegree2);

        JLabel lblDegree4 = new JLabel("°");
        lblDegree4.setBounds(432, 77, 23, 16);
        contentPane.add(lblDegree4);

        JLabel lblMinute2 = new JLabel("´");
        lblMinute2.setBounds(512, 38, 23, 16);
        contentPane.add(lblMinute2);

        JLabel lblMinute4 = new JLabel("´");
        lblMinute4.setBounds(512, 77, 23, 16);
        contentPane.add(lblMinute4);

        JLabel lblMinute1 = new JLabel("´");
        lblMinute1.setBounds(279, 38, 23, 16);
        contentPane.add(lblMinute1);

        JLabel lblMinute3 = new JLabel("´");
        lblMinute3.setBounds(279, 77, 23, 16);
        contentPane.add(lblMinute3);

    }

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    JFrame frame = new JFrame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
}
 
Zuletzt bearbeitet von einem Moderator:
Ähnliche Java Themen
  Titel Forum Antworten Datum
J JOptionPane return bei "Abbrechen" AWT, Swing, JavaFX & SWT 13
O Swing JOptionPane.showOptionDialog - Wie kann ich Buttons größer machen AWT, Swing, JavaFX & SWT 10
O Timer in JOptionPane anzeigen AWT, Swing, JavaFX & SWT 2
Z Swing JOptionPane import AWT, Swing, JavaFX & SWT 5
R Swing JOptionPane Sprache Ändern AWT, Swing, JavaFX & SWT 4
O JOptionPane mit JFileDialog AWT, Swing, JavaFX & SWT 5
dereki2000 JPanel mit Rückgbe wie bei JOptionPane AWT, Swing, JavaFX & SWT 3
T JavaFX JFrame verhalten wie JOptionPane (ErrorMessage) AWT, Swing, JavaFX & SWT 1
I JOptionPane maximale Zeichen einstellen AWT, Swing, JavaFX & SWT 2
N Swing Mocken von JOptionPane im JUnit-Test AWT, Swing, JavaFX & SWT 3
R Ausgabe über JOptionPane.showMessageDialog funktioniert nicht AWT, Swing, JavaFX & SWT 2
W JOptionPane AWT, Swing, JavaFX & SWT 1
T JOptionPane Dialog plus Rechnung ausgeben AWT, Swing, JavaFX & SWT 1
snipesss Hintergrundbild in JOptionPane.showInputDialog? AWT, Swing, JavaFX & SWT 4
R Swing JOptionPane Fehlermeldung- bitte um Hilfe! AWT, Swing, JavaFX & SWT 4
J Event Handling JOptionPane ActionListener setzen. AWT, Swing, JavaFX & SWT 3
A Swing JOptionPane.showConfirmDialog, EventQueue wird weiter abgearbeitet AWT, Swing, JavaFX & SWT 2
C JOptionPane.showConfirmDialog() -> Focus auf NEIN -> Enter gibt YES_OPTION zurück AWT, Swing, JavaFX & SWT 6
T JOptionPane Enter = Okay AWT, Swing, JavaFX & SWT 3
NicoDeluxe JOptionPane AWT, Swing, JavaFX & SWT 2
B JFrame wie JOptionPane.showMessageDialog() AWT, Swing, JavaFX & SWT 2
D Swing JOptionPane verschwindet beim 2. Aufruf einfach so?? AWT, Swing, JavaFX & SWT 2
L Swing JOptionPane Verwirrung AWT, Swing, JavaFX & SWT 13
P JOptionPane input und show Message Dialog AWT, Swing, JavaFX & SWT 5
I javascript in javaprogramm JOptionpane -> haengt (embedded Interpreter) AWT, Swing, JavaFX & SWT 2
S JOptionPane sinnvoll benutzen AWT, Swing, JavaFX & SWT 7
J JOptionPane mit zwei Buttons?! AWT, Swing, JavaFX & SWT 3
D JOptionPane.QUESTION_MESSAGE Fett darstellen AWT, Swing, JavaFX & SWT 4
N JOptionPane als JWindow AWT, Swing, JavaFX & SWT 2
M Swing Änderungen eines TextFelds und JOptionPane AWT, Swing, JavaFX & SWT 5
O JOptionPane.showMessageDialog mit automatischem Zeilenumbruch AWT, Swing, JavaFX & SWT 9
E Swing setCaretPosition für ein JTextField in einem JOptionPane AWT, Swing, JavaFX & SWT 3
H Swing JOptionPane.showConfirmMessage() wird nicht angezeigt AWT, Swing, JavaFX & SWT 2
R JOptionPane.YES_NO_CANCEL_OPTION im SaveDialog verwenden AWT, Swing, JavaFX & SWT 6
U JFrame minimiert nach JDialog, JOptionPane AWT, Swing, JavaFX & SWT 3
R Eingegebenen Text in JOptionPane in andere Klasse weitergeben AWT, Swing, JavaFX & SWT 2
M JOptionPane.showInputDialog abbrechen abfangen? AWT, Swing, JavaFX & SWT 2
Weiti JOptionPane aus einer von JPanel abgeleiteten Klasse aufrufen AWT, Swing, JavaFX & SWT 3
N OK-Button in JOptionPane ansprechen AWT, Swing, JavaFX & SWT 5
D Swing JOptionPane + FileChooser .. Reihenfolge wichtig!? AWT, Swing, JavaFX & SWT 7
G Swing Meldung mit joptionpane information message AWT, Swing, JavaFX & SWT 22
B Swing JOptionPane ohne beep AWT, Swing, JavaFX & SWT 6
A Swing \t im JOptionPane AWT, Swing, JavaFX & SWT 2
G JOptionPane.showConfirmDialog size problem AWT, Swing, JavaFX & SWT 3
S JOptionPane - InitialValue AWT, Swing, JavaFX & SWT 9
S JOptionPane resultat kriegen AWT, Swing, JavaFX & SWT 7
ABstraCT JOptionPane setSize ? AWT, Swing, JavaFX & SWT 6
S JOptionPane.showInputDialog JList erzwingen? AWT, Swing, JavaFX & SWT 4
SebSnake JFrame "Focus" erzwingen (wie JOptionPane) AWT, Swing, JavaFX & SWT 3
G JOptionPane.showInputDialog(): Texteingabe und Fokus AWT, Swing, JavaFX & SWT 3
A Array wird im JOptionPane mehrfach ausgegeben AWT, Swing, JavaFX & SWT 3
A JOptionPane soll auf Enter reagieren AWT, Swing, JavaFX & SWT 4
F JOptionPane.showMessageDialog AWT, Swing, JavaFX & SWT 2
M JOptionPane.showMessageDialog() mit printStackTace() ? AWT, Swing, JavaFX & SWT 7
QDog JTabbedPane JOptionPane AWT, Swing, JavaFX & SWT 2
K Tabelle nach JOptionPane updaten AWT, Swing, JavaFX & SWT 5
A JOptionPane; CLOSED_OPTION ausschalten AWT, Swing, JavaFX & SWT 5
A Probleme mit einer JOptionPane in einem jar-File AWT, Swing, JavaFX & SWT 14
Z JOptionPane mit einer Methode in dem Vordergrund setzen? AWT, Swing, JavaFX & SWT 6
J JOptionPane Tabs AWT, Swing, JavaFX & SWT 3
G JOptionPane mit andere Farbe AWT, Swing, JavaFX & SWT 8
B Ein JOptionPane.showMessageDialog(.) AWT, Swing, JavaFX & SWT 6
G komplexes JOptionPane (oder doch JFrame?) AWT, Swing, JavaFX & SWT 2
G JOptionPane mit link zum anklicken AWT, Swing, JavaFX & SWT 4
G JOptionPane AWT, Swing, JavaFX & SWT 6
N Probleme mit eigenem JOptionPane AWT, Swing, JavaFX & SWT 2
A Schließen eines JOptionPane.showConfirmDialog AWT, Swing, JavaFX & SWT 6
B JOptionPane.showInputDialog mit drei ComboBoxen nebeneinande AWT, Swing, JavaFX & SWT 2
S JTextField und JOptionPane - Zeicheneingabe beschränken AWT, Swing, JavaFX & SWT 3
G JOptionPane AWT, Swing, JavaFX & SWT 3
eskimo328 JOptionPane ohne CANCEL Button AWT, Swing, JavaFX & SWT 2
M JOptionPane.showConfirmDialog. Frage zur Cancel_Option AWT, Swing, JavaFX & SWT 2
L JOptionPane AWT, Swing, JavaFX & SWT 4
P JComboBox.addItem erzeugt Layoutproblem mit JOptionPane AWT, Swing, JavaFX & SWT 2
J eigenes JOptionPane ? AWT, Swing, JavaFX & SWT 2
J JOptionPane Buttons AWT, Swing, JavaFX & SWT 4
G Eingabe auslesen mit JOptionPane AWT, Swing, JavaFX & SWT 2
vogella JOptionPane in den Vordergrund bringen AWT, Swing, JavaFX & SWT 2
P JOptionPane AWT, Swing, JavaFX & SWT 3
C Probleme beim Serialisieren mit JOptionPane AWT, Swing, JavaFX & SWT 12
S JOptionPane: methode ShowConfirmDialog ist undefiniert AWT, Swing, JavaFX & SWT 2
S JOptionPane und eine feste Zeilenbreite. AWT, Swing, JavaFX & SWT 4
S JProgressBar zu JOptionPane hinzufügen. AWT, Swing, JavaFX & SWT 8
G JOptionPane AWT, Swing, JavaFX & SWT 3
B Eingabeüberprüfung beim JOptionPane.showInputDialog() AWT, Swing, JavaFX & SWT 3
D Mit JOptionPane einen Link darstellen AWT, Swing, JavaFX & SWT 10
S JOptionPane.showMessageDialog(.) AWT, Swing, JavaFX & SWT 23
S Ein frage zu JOptionPane AWT, Swing, JavaFX & SWT 2
H wie frage ich mehrere buttons von joptionpane ab AWT, Swing, JavaFX & SWT 4
G Link in JoptionPane? AWT, Swing, JavaFX & SWT 3
N JOptionPane mit Html Tags AWT, Swing, JavaFX & SWT 5
B Focus in JOptionPane AWT, Swing, JavaFX & SWT 2
M Ausgabe mit JOptionPane AWT, Swing, JavaFX & SWT 6
U kleiner-Zeichen JEditorPanel (war: JOptionPane) AWT, Swing, JavaFX & SWT 5
S JOptionPane in den Bildschirmvordergrund bringen AWT, Swing, JavaFX & SWT 3
F JOptionPane soll nicht auf ENTER reagieren AWT, Swing, JavaFX & SWT 8
D Auf System-Icons wie die aus JOptionPane zugreifen? AWT, Swing, JavaFX & SWT 6
F Dialog (JOptionPane) modal machen AWT, Swing, JavaFX & SWT 3
R Nicht reproduzierbarer Bug in JOptionPane AWT, Swing, JavaFX & SWT 8
meez Auf Bilder der JOptionPane zugreifen... AWT, Swing, JavaFX & SWT 4

Ähnliche Java Themen

Anzeige

Neue Themen


Oben