[an error occurred while processing this directive]


Rheinland-Pfalz;  Informatik                                 

Letzte Aktualisierung:  21.8.2008; Claus Schmitt

Zurück zur Startseite Informatik / Rheinland-Pfalz Startseite Informatik-Rheinland-Pfalz

   Aufrufe seit  20.8.2008                       

 zurück zur Java Startseite

                                                                                                                                            

                                                   


Erstellung der Java GUI über ein Plugin für Eclipse

 

Vgl auch die Synopse der Quelltexte.


 




Im Folgenden wird der Quelltext für das  DM_in_Euro-Problem gezeigt, wenn man die GUI mit dem Plugin Jigloo automatisiert erzeugt;

nur der gelb hinterlegte Text wurde "von Hand" eingefügt:

package mit_plugin;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.NumberFormat;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextPane;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
/**
 * 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 www.cloudgarden.com 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 GUI_plugin extends javax.swing.JFrame {
	private JTextPane textfield_dm;;
	private JButton jButton;
	private JLabel jLabel2;
	private JLabel jLabel1;
	private JTextPane textfield_euro;;
	/**
	 * Auto-generated main method to display this JFrame
	 */
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				GUI_plugin inst = new GUI_plugin();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	public GUI_plugin() {
		super();
		initGUI();
	}
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				textfield_dm = new JTextPane();
				getContentPane().add(textfield_dm);
				textfield_dm.setBounds(45, 49, 127, 31);
			}
			{
				textfield_euro = new JTextPane();
				getContentPane().add(textfield_euro);
				textfield_euro.setBounds(233, 49, 127, 31);
			}
			{
				jLabel1 = new JLabel();
				getContentPane().add(jLabel1);
				jLabel1.setText("DM");
				jLabel1.setBounds(45, 24, 35, 14);
			}
			{
				jLabel2 = new JLabel();
				getContentPane().add(jLabel2);
				jLabel2.setText("Euro");
				jLabel2.setBounds(233, 24, 33, 14);
			}
			{
				jButton = new JButton();
				getContentPane().add(jButton);
				jButton.setText("Umwandlung von DM in Euro");
				jButton.setBounds(212, 123, 203, 42);
				jButton.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						System.out.println("jButton.actionPerformed, event="
								+ evt);
						// TODO add your code for jButton.actionPerformed
						buttonBerechneClicked();
					}
				});
			}
			pack();
			this.setSize(457, 332);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	// Die Methode für die Aktion, wenn der Knopf gedrückt wird
	public void buttonBerechneClicked() {
		double dm = 0;
		try {
			// Den DM-Wert aus dem Fenster ziehen
			dm = Double.parseDouble(textfield_dm.getText());
		} catch (NumberFormatException e) {
			dm = -1;
		}
		if (dm >= 0) {
			// in Euro umrechnen
			double euro = dm2euro(dm);
			// Für die Stringvariable ausgabe formatieren
			NumberFormat nf = NumberFormat.getInstance();
			nf.setMaximumFractionDigits(2);
			String ausgabe = nf.format(euro) + "€";
			textfield_euro.setText(ausgabe);
		} else
			textfield_euro.setText("Fehler in der Eingabe");
	}
	// Die Methode für die eigentliche Umrechnung
	public double dm2euro(double dm) {
		double euro = dm / 1.95583;
		return euro;
	}
}

zum Anfang der Seite    Begriffe Suchen

Ergänzungen und Anregungen bitte an Claus Schmitt
 

Zurück zur Startseite Informatik / Rheinland-Pfalz Startseite Informatik-Rheinland-Pfalz
Impressum · Datenschutz