Versionsvergleich

Aus ProgrammingWiki

Vergleich: 2010-12-19T10:39:00+00:00 → 2011-01-10T19:41:07+00:00

<language>Java</language>
−
<code id="4d0de0c477ea5">
−
public class Zaehler {
−
    private int zaehler;
−
 
−
    public Zaehler() {
−
        zaehler = 0;
−
    }
−
 
−
    public int getZaehler() {
−
        return zaehler;
−
    }
−
 
−
    public void erhoeheZaehler(){
−
        zaehler++;
−
    }
−
}
+
<code id="4d13a232e8581">
+
public Object Eingabe() {
+
 double x = 0;
−
public class ZaehlerGUI extends javax.swing.JFrame {
−
 
−
    private Zaehler z;
−
 
−
    /** Creates new form ZaehlerGUI */
−
    public ZaehlerGUI() {
−
        initComponents();
−
        z = new Zaehler();
−
    }
−
 
−
    /** This method is called from within the constructor to
−
     * initialize the form.
−
     * WARNING: Do NOT modify this code. The content of this method is
−
     * always regenerated by the Form Editor.
−
     */
−
    // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
−
    private void initComponents() {
−
        button1 = new java.awt.Button();
−
        textField1 = new java.awt.TextField();
−
        label1 = new java.awt.Label();
−
 
−
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
−
        button1.setLabel("Erh\u00f6hen um 1");
−
        button1.addActionListener(new java.awt.event.ActionListener() {
−
            public void actionPerformed(java.awt.event.ActionEvent evt) {
−
                button1ActionPerformed(evt);
−
            }
−
        });
−
 
−
        textField1.setText("0");
−
 
−
        label1.setText("Ein Z\u00e4hler als Beispiel f\u00fcr den Entwurf eines GUI");
−
 
−
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
−
        getContentPane().setLayout(layout);
−
        layout.setHorizontalGroup(
−
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
−
            .add(layout.createSequentialGroup()
−
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
−
                    .add(layout.createSequentialGroup()
−
                        .add(100, 100, 100)
−
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
−
                            .add(org.jdesktop.layout.GroupLayout.LEADING, textField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
−
                            .add(org.jdesktop.layout.GroupLayout.LEADING, button1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
−
                    .add(layout.createSequentialGroup()
−
                        .addContainerGap()
−
                        .add(label1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 270, Short.MAX_VALUE)))
−
                .addContainerGap())
−
        );
−
        layout.setVerticalGroup(
−
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
−
            .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
−
                .addContainerGap()
−
                .add(label1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
−
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 29, Short.MAX_VALUE)
−
                .add(textField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
−
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
−
                .add(button1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
−
                .add(70, 70, 70))
−
        );
−
        pack();
−
    }// </editor-fold>
−
 
−
    private void button1ActionPerformed(java.awt.event.ActionEvent evt) {
−
        z.erhoeheZaehler();
−
        textField1.setText(""+z.getZaehler());
−
    }
−
 
−
    /**
−
     * @param args the command line arguments
−
     */
−
    public static void main(String args[]) {
−
        java.awt.EventQueue.invokeLater(new Runnable() {
−
            public void run() {
−
                new ZaehlerGUI().setVisible(true);
−
            }
−
        });
−
    }
−
 
−
    // Variables declaration - do not modify
−
    private java.awt.Button button1;
−
    private java.awt.Label label1;
−
    private java.awt.TextField textField1;
−
    // End of variables declaration
+
 JTextField myTextField = new JTextField("                         ");
+
 JButton myButton1 = new JButton("Eingabe");
+
 JButton myButton2 = new JButton("Beenden");
+
 JPanel myPanel1 = new JPanel();
+
 JPanel myPanel2 = new JPanel();
+
+
 myFrame = new JFrame("Deine Zahl");
+
 myFrame.setSize(200, 100);
+
 myFrame.setLocationRelativeTo(null);
+
+
 myPanel1.add(myTextField);
+
 myPanel2.add(myButton1);
+
 myPanel2.add(myButton2);
+
+
 myFrame.getContentPane().setLayout(new BorderLayout());
+
 myFrame.getContentPane().add(myPanel1, BorderLayout.NORTH);
+
 myFrame.getContentPane().add(myPanel2, BorderLayout.SOUTH);
+
 myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+
 myFrame.setResizable(false); 
+
 myFrame.setVisible(true);
+
    
+
 myButton1.addActionListener(this);
+
 myButton2.addActionListener(this);
+
    
+
 private void actionPerformed(ActionEvent Ereignis) {
+
  String zk = new String(); 
+
  if (Ereignis.getSource() == myButton1)
+
   try {
+
    x = Double.parseDouble(myTextField.getText());
+
   }
+
   catch (NumberFormatException Ereignis) {
+
    x = -1;
+
   }
+
  else if (Ereignis.getSource() == myButton2)
+
   x = -2;
+
  else
+
   x = -2;
+
  myFrame.dispose();
+
 }
+
+
 public int Wert() {
+
  while (x == 0); 
+
  return (int)x;
+
 }
+
+
 return this;
}
</code>
+
+
<run id="4d13a232e8627">
+
Object myEingabe = Eingabe();
+
System.out.println(myEingabe.Wert());
+
</run>