Hallo,
ich versuche eine Applikation mit Swing graphisch zu realisieren und weiß im Moment nicht, wie ich eine Applikation in einer SingleFrameApplication starten kann, z.B. über einen Button in der Menüleiste.
Das Teilprogramm "SettingsFrame.java", ein JFrame, kann alleine laufen. Das will ich aber von einem Hauptprogramm starten lassen. Wie muß ich das realisieren? Immerhin haben beide eine "public static void main"-Methode, wobei in einem Programm nur Eine existieren darf.
Vor allem wo kann ich das unter Eclipse einstellen?
Ich weiß, das sind Anfängerfragen, ich finde nur nichts auf die Schnelle in der Literatur.
Grüße
CaptainNelson
ich versuche eine Applikation mit Swing graphisch zu realisieren und weiß im Moment nicht, wie ich eine Applikation in einer SingleFrameApplication starten kann, z.B. über einen Button in der Menüleiste.
Das Teilprogramm "SettingsFrame.java", ein JFrame, kann alleine laufen. Das will ich aber von einem Hauptprogramm starten lassen. Wie muß ich das realisieren? Immerhin haben beide eine "public static void main"-Methode, wobei in einem Programm nur Eine existieren darf.
Vor allem wo kann ich das unter Eclipse einstellen?
Ich weiß, das sind Anfängerfragen, ich finde nur nichts auf die Schnelle in der Literatur.
Java:
import java.awt.event.ActionEvent;
public class SettingsFrame extends javax.swing.JFrame {
private JLabel jLPLZ;
private JTextField jTFPLZ;
private JLabel jLName;
private JButton jBtnRead;
private JTextField jTFSurname;
private JLabel jLSurname;
private JTextField jTFName;
private JScrollBar jScrollBar1;
private JButton jBtnOK;
private boolean existfile;
Settings s = new Settings();
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
SettingsFrame inst = new SettingsFrame();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public SettingsFrame() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setLayout(null);
if (!s.getDir().exists()) {
s.createDirectory();
}
if (s.getFile().exists()) {
existfile = false;
} else {
existfile = true;
s.createFile();
}
{
jLPLZ = new JLabel();
getContentPane().add(jLPLZ);
jLPLZ.setText("PLZ:");
jLPLZ.setBounds(31, 39, 45, 15);
}
{
jTFPLZ = new JTextField();
getContentPane().add(jTFPLZ);
jTFPLZ.setBounds(115, 36, 110, 22);
jTFPLZ.setEditable(existfile);
}
{
jBtnOK = new JButton();
getContentPane().add(jBtnOK);
jBtnOK.setText("OK");
jBtnOK.setBounds(127, 211, 69, 22);
jBtnOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jBtnOKActionPerformed(evt);
}
});
}
{
jScrollBar1 = new JScrollBar();
getContentPane().add(jScrollBar1);
jScrollBar1.setBounds(535, 58, 17, 139);
}
{
jLName = new JLabel();
getContentPane().add(jLName);
jLName.setText("Vorname:");
jLName.setBounds(32, 76, 78, 15);
}
{
jTFName = new JTextField();
getContentPane().add(jTFName);
jTFName.setBounds(115, 73, 110, 22);
jTFName.setEditable(existfile);
}
{
jLSurname = new JLabel();
getContentPane().add(jLSurname);
jLSurname.setText("Nachname:");
jLSurname.setBounds(32, 108, 83, 15);
}
{
jTFSurname = new JTextField();
getContentPane().add(jTFSurname);
jTFSurname.setBounds(115, 105, 110, 22);
jTFSurname.setEditable(existfile);
}
{
jBtnRead = new JButton();
getContentPane().add(jBtnRead);
jBtnRead.setText("Einlesen");
jBtnRead.setBounds(267, 211, 102, 22);
jBtnRead.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jBtnReadActionPerformed(evt);
}
});
}
pack();
this.setSize(574, 296);
} catch (Exception e) {
//add your error handling code here
e.printStackTrace();
}
}
private void jBtnOKActionPerformed(ActionEvent evt) {
s.setName(jTFName.getText());
s.setSurname(jTFSurname.getText());
s.setZip(Integer.parseInt(jTFPLZ.getText()));
s.storeSettings();
System.out.println("Vorname : " + s.getName());
System.out.println("Nachname: " + s.getSurname());
System.out.println("PLZ : " + s.getZip());
//s.createDirectory();
}
private void jBtnReadActionPerformed(ActionEvent evt) {
s.readSettings();
jTFName.setText(s.getName());
jTFSurname.setText(s.getSurname());
jTFPLZ.setText(s.getZip());
}
}
Grüße
CaptainNelson