mirror of
https://codeberg.org/qg-info-unterricht/bluej-ueberlauf-demo.git
synced 2025-12-10 15:28:35 +01:00
204 lines
No EOL
6.7 KiB
Java
204 lines
No EOL
6.7 KiB
Java
import java.awt.*;
|
|
import java.awt.event.*;
|
|
import javax.swing.*;
|
|
import javax.swing.event.*;
|
|
|
|
/**
|
|
*
|
|
* Applet zum ZahlUeberlauf
|
|
*
|
|
* @version 1.0 from 11.10.2016
|
|
* @author Tom Schaller, Dirk Zechnall
|
|
*/
|
|
|
|
public class Zaehlen extends JFrame {
|
|
// Anfang Attribute
|
|
private JButton jButton1 = new JButton();
|
|
private JButton jButton2 = new JButton();
|
|
private JLabel jLabel1 = new JLabel();
|
|
private JLabel jLabel2 = new JLabel();
|
|
private JLabel jLabel3 = new JLabel();
|
|
private JLabel jLabel4 = new JLabel();
|
|
private JLabel jLabel5 = new JLabel();
|
|
private JLabel jLabel6 = new JLabel();
|
|
private JButton jButton3 = new JButton();
|
|
private JButton jButton4 = new JButton();
|
|
private JButton jButton5 = new JButton();
|
|
private JButton jButton6 = new JButton();
|
|
private JLabel jLabel7 = new JLabel();
|
|
private JLabel jLabel8 = new JLabel();
|
|
private JButton jButton7 = new JButton();
|
|
private JButton jButton8 = new JButton();
|
|
|
|
private byte b = 120;
|
|
private short s = 32760;
|
|
private int i = 2147483647;
|
|
private long l = 9223372036854775807L;
|
|
// Ende Attribute
|
|
|
|
public Zaehlen () {
|
|
super ("Zaehlen mit elementaren Datentypen");
|
|
int frameWidth = 494;
|
|
int frameHeight = 177;
|
|
setSize(frameWidth, frameHeight);
|
|
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
|
|
int x = (d.width - getSize().width) / 2;
|
|
int y = (d.height - getSize().height) / 2;
|
|
setLocation(x, y);
|
|
Container cp = getContentPane();
|
|
cp.setLayout(null);
|
|
// Anfang Komponenten
|
|
jButton1.setBounds(288, 40, 75, 25);
|
|
jButton1.setText("+1");
|
|
jButton1.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton1.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton1_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton1);
|
|
jButton2.setBounds(288, 72, 75, 25);
|
|
jButton2.setText("+1");
|
|
jButton2.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton2.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton2_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton2);
|
|
jLabel1.setBounds(8, 40, 78, 20);
|
|
jLabel1.setText("short");
|
|
cp.add(jLabel1);
|
|
jLabel2.setBounds(8, 72, 54, 20);
|
|
jLabel2.setText("int");
|
|
cp.add(jLabel2);
|
|
jLabel3.setBounds(8, 104, 78, 20);
|
|
jLabel3.setText("long");
|
|
cp.add(jLabel3);
|
|
jLabel4.setBounds(96, 40, 110, 20);
|
|
jLabel4.setText("240");
|
|
cp.add(jLabel4);
|
|
jLabel5.setBounds(96, 72, 110, 20);
|
|
jLabel5.setText("text");
|
|
cp.add(jLabel5);
|
|
jLabel6.setBounds(96, 104, 166, 20);
|
|
jLabel6.setText("text");
|
|
cp.add(jLabel6);
|
|
jButton3.setBounds(288, 104, 75, 25);
|
|
jButton3.setText("+1");
|
|
jButton3.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton3.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton3_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton3);
|
|
jButton4.setBounds(392, 40, 75, 25);
|
|
jButton4.setText("-1");
|
|
jButton4.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton4.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton4_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton4);
|
|
jButton5.setBounds(392, 72, 75, 25);
|
|
jButton5.setText("-1");
|
|
jButton5.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton5.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton5_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton5);
|
|
jButton6.setBounds(392, 104, 75, 25);
|
|
jButton6.setText("-1");
|
|
jButton6.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton6.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton6_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton6);
|
|
jLabel7.setBounds(8, 8, 78, 20);
|
|
jLabel7.setText("byte");
|
|
cp.add(jLabel7);
|
|
jLabel8.setBounds(96, 8, 110, 20);
|
|
jLabel8.setText("text");
|
|
cp.add(jLabel8);
|
|
jButton7.setBounds(288, 8, 75, 25);
|
|
jButton7.setText("+1");
|
|
jButton7.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton7.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton7_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton7);
|
|
jButton8.setBounds(392, 8, 75, 25);
|
|
jButton8.setText("-1");
|
|
jButton8.setMargin(new Insets(2, 2, 2, 2));
|
|
jButton8.addActionListener(new ActionListener() {
|
|
public void actionPerformed(ActionEvent evt) {
|
|
jButton8_ActionPerformed(evt);
|
|
}
|
|
});
|
|
cp.add(jButton8);
|
|
jLabel4.setText(""+s);
|
|
jLabel5.setText(""+i);
|
|
jLabel6.setText(""+l);
|
|
jLabel8.setText(""+b);
|
|
|
|
// Ende Komponenten
|
|
setDefaultCloseOperation(EXIT_ON_CLOSE);
|
|
setResizable(false);
|
|
setVisible(true);
|
|
}
|
|
|
|
// Anfang Methoden
|
|
public void jButton1_ActionPerformed(ActionEvent evt) {
|
|
s++;
|
|
jLabel4.setText(""+s);
|
|
} // end of jButton1_ActionPerformed
|
|
|
|
public void jButton2_ActionPerformed(ActionEvent evt) {
|
|
i++;
|
|
jLabel5.setText(""+i);
|
|
} // end of jButton2_ActionPerformed
|
|
|
|
public void jButton3_ActionPerformed(ActionEvent evt) {
|
|
l++;
|
|
jLabel6.setText(""+l);
|
|
} // end of jButton3_ActionPerformed
|
|
|
|
public void jButton4_ActionPerformed(ActionEvent evt) {
|
|
s--;
|
|
jLabel4.setText(""+s);
|
|
} // end of jButton4_ActionPerformed
|
|
|
|
public void jButton5_ActionPerformed(ActionEvent evt) {
|
|
i--;
|
|
jLabel5.setText(""+i);
|
|
} // end of jButton5_ActionPerformed
|
|
|
|
public void jButton6_ActionPerformed(ActionEvent evt) {
|
|
l--;
|
|
jLabel6.setText(""+l);
|
|
} // end of jButton6_ActionPerformed
|
|
|
|
public void jButton7_ActionPerformed(ActionEvent evt) {
|
|
b++;
|
|
jLabel8.setText(""+b);
|
|
} // end of jButton7_ActionPerformed
|
|
|
|
public void jButton8_ActionPerformed(ActionEvent evt) {
|
|
b--;
|
|
jLabel8.setText(""+b);
|
|
} // end of jButton8_ActionPerformed
|
|
|
|
// Ende Methoden
|
|
|
|
public static void main(String[] args) {
|
|
new Zaehlen();
|
|
}
|
|
} |