Klasse ConfigurationWindow:
[JAVA=42]package exercises.project;
import java.util.Locale;
import java.util.ResourceBundle;
import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
public class ConfigurationWindow extends JFrame {
private static final String PATH = "path";
private static final String OPTION = "option";
private static final String LANGUAGE = "language";
private static final String RDB_GET_USERDATA = "rdbGetUserdata";
private static final String RDB_SEARCH_USER = "rdbSearchUser";
private static final String LIST_SEARCH = "listSearch";
private ResourceBundle bundle;
private JPanel panel;
private JTextField filePath = new JTextField("");
private JButton Ok;
private JButton Cancel;
private JButton File;
public ConfigurationWindow() {
super("Choose your activity");
setSize(360, 250);
setLocation(300, 300);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Locale.setDefault(Locale.ENGLISH);
bundle = ResourceBundle.getBundle(getClass().getPackage().getName() + ".resources");
panel = new JPanel();
panel.setLayout(null);
getContentPane().add(panel);
JLabel options = new JLabel(bundle.getString(OPTION));
panel.add(options);
options.setBounds(10, 10, 200, 20);
//JComboBox mit Sprachen
JLabel languageLabel = new JLabel(bundle.getString(LANGUAGE));
panel.add(languageLabel);
languageLabel.setBounds(20, 30, 200, 20);
String LanguageList[] = { "English", "German"};
JComboBox language = new JComboBox(LanguageList);
language.setBounds(20, 50, 100, 25);
panel.add(language);
//JLabel
JLabel listorSearch = new JLabel(bundle.getString(LIST_SEARCH));
panel.add(listorSearch);
listorSearch.setBounds(20, 80, 200, 20);
//RadioButtons & ButtonGroup
JRadioButton rb1 = new JRadioButton(bundle.getString(RDB_GET_USERDATA));
JRadioButton rb2 = new JRadioButton(bundle.getString(RDB_SEARCH_USER));
rb1.setSelected(true);
ButtonGroup btngrpoup = new ButtonGroup();
btngrpoup.add(rb1);
btngrpoup.add(rb2);
//Zuweisung der Buttons
panel.add(rb1);
rb1.setBounds(20, 100, 100, 15);
panel.add(rb2);
rb2.setBounds(150, 100, 100, 15);
JLabel pathLabel = new JLabel(bundle.getString(PATH));
panel.add(pathLabel);
pathLabel.setBounds(20, 130, 200, 15);
filePath.setEditable(false);
panel.add(filePath);
filePath.setBounds(20, 150, 200, 20);
//JButton
Ok = new JButton("OK");
Cancel = new JButton("Cancel");
File = new JButton("Durchsuchen");
panel.add(Ok);
Ok.setBounds(215, 15, 75, 30);
panel.add(Cancel);
Cancel.setBounds(215, 50, 75, 30);
panel.add(File);
File.setBounds(222, 150, 115, 19);
Ok.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
check();
}
});
Cancel.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
System.exit(0);
}
});
File.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent e) {
FileChoose();
}
});
setVisible(true);
}
public static void main(String[] args) {
ConfigurationWindow cw = new ConfigurationWindow();
cw.setVisible(true);
}
public void FileChoose() {
JFileChooser chooser = new JFileChooser();
chooser.showDialog(null, "Open");
String select = chooser.getSelectedFile().toString();
filePath.setText(select);
}
public void check() {
if (filePath.equals("")) {
JOptionPane.showMessageDialog(null, "Path can't be empty!", "Error",
JOptionPane.ERROR_MESSAGE);
}
}
}[/code]