Moin!
Ich versuche eine GUI zu erstellen, die je nach Eingabe als Lösung einer von 3 Möglichkeiten ausgibt. Dazu müssen die Ergebnisse von mehreren JComboBoxen (4) und JTextFields verknüpft werden. Kann mir da jemand sagen wie ich das mache? Und zusätzlich möchte ich das ein Ergebniss erst erscheint wenn alles ausgewählt / eingegeben wurde.
Sorry bin hier ziemlicher Anfänger und weiß langsam nicht mehr nach was ich googlen soll
Ich versuche eine GUI zu erstellen, die je nach Eingabe als Lösung einer von 3 Möglichkeiten ausgibt. Dazu müssen die Ergebnisse von mehreren JComboBoxen (4) und JTextFields verknüpft werden. Kann mir da jemand sagen wie ich das mache? Und zusätzlich möchte ich das ein Ergebniss erst erscheint wenn alles ausgewählt / eingegeben wurde.
Sorry bin hier ziemlicher Anfänger und weiß langsam nicht mehr nach was ich googlen soll
Java:
package de.jade.kursarbeit;
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;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
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() {
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());
if (LatDOwn > 90) {
JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ",
JOptionPane.INFORMATION_MESSAGE);
OwnPositionLatD.setText("");
}
}
});
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());
if (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());
if (LongDOwn > 180) {
JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ",
JOptionPane.INFORMATION_MESSAGE);
OwnPositionLatD.setText("");
}
}
});
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());
if (LongMOwn > 60) {
JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ",
JOptionPane.INFORMATION_MESSAGE);
OwnPositionLatD.setText("");
}
}
});
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());
if (LatDPOI > 90) {
JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ",
JOptionPane.INFORMATION_MESSAGE);
OwnPositionLatD.setText("");
}
}
});
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());
if (LatMPOI > 60) {
JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ",
JOptionPane.INFORMATION_MESSAGE);
OwnPositionLatD.setText("");
}
}
});
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());
if (LongDPOI > 180) {
JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ",
JOptionPane.INFORMATION_MESSAGE);
OwnPositionLatD.setText("");
}
}
});
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());
if (LongMPOI > 60) {
JOptionPane.showMessageDialog(null, "Please enter valid minutes", "Error ",
JOptionPane.INFORMATION_MESSAGE);
OwnPositionLatD.setText("");
}
}
});
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.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String selectedWind = (String) Wind.getSelectedItem();
if (selectedWind.equals("Wind > 15kn")) {
txtPaneSAR.setText("Expanding Search Square");
}
}
});*/
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();
}
}
});
}
}