Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package de[PRIVAT].main;
- import java.awt.Font;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.util.ArrayList;
- import java.util.InputMismatchException;
- import javax.swing.ImageIcon;
- import javax.swing.JButton;
- import javax.swing.JCheckBox;
- import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JTextField;
- import javax.swing.text.AttributeSet;
- import javax.swing.text.BadLocationException;
- import javax.swing.text.Document;
- import javax.swing.text.PlainDocument;
- @SuppressWarnings("serial")
- public class Punkterechner extends JFrame {
- Font font = new Font("Verdana", Font.BOLD, 15);
- ArrayList<String> liste1 = new ArrayList<String>();
- static JLabel text1;
- static JLabel anzahl1;
- static JLabel klasse1;
- static JLabel text2;
- static JLabel anzahl2;
- static JLabel klasse2;
- JPanel panel2 = new JPanel();
- JPanel panel3 = new JPanel();
- ImageIcon img = new ImageIcon("GCG.jpg");
- JPanel panel = new JPanel();
- static JTextField A0;
- static JTextField A2;
- static JTextField A3;
- static JTextField A4;
- JCheckBox box1 = new JCheckBox("Klimmzüge");
- JCheckBox box2 = new JCheckBox("Standweitsprung");
- JCheckBox box3 = new JCheckBox("Beugestütz");
- JButton button = new JButton("Auswählen");
- static JButton berechnen1 = new JButton("Berechnen");
- JButton berechnen2 = new JButton("Berechnen");
- JButton berechnen3 = new JButton("Berechnen");
- public static void main(String[] args) {
- Punkterechner pr = new Punkterechner();
- pr.b1click();
- pr.Punkterechner();
- JOptionPane.showMessageDialog(null, "[DATENSCHUTZ ENTFERNT]");
- }
- private Document createNumericDocumentWithMaxLength(final int maxLength) {
- Document doc = new PlainDocument(){
- @Override
- public void insertString(int offs, String str, AttributeSet a)
- throws BadLocationException {
- if(getLength() + str.length() > maxLength)
- return;
- if(!str.matches("^[\\d]*$"))
- return;
- super.insertString(offs, str, a);
- }
- };
- return doc;
- }
- private Document createNumericDocumentWithMaxLength1(final int maxLength) {
- Document doc = new PlainDocument(){
- @Override
- public void insertString(int offs, String str, AttributeSet a)
- throws BadLocationException {
- if(getLength() + str.length() > maxLength)
- return;
- if(!str.matches("^[\\d]*$"))
- if(!str.matches("[5-12]+"))
- return;
- super.insertString(offs, str, a);
- }
- };
- return doc;
- }
- public void Punkterechner() {
- panel.setLayout(null);
- JFrame f = new JFrame();
- f.setIconImage(img.getImage());
- f.setVisible(true);
- f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f.setLocationRelativeTo(null);
- f.setTitle("Punkterechner");
- f.setBounds(100, 300, 500, 500);
- text1 = new JLabel("Bitte wählen Sie die Disziplin aus!");
- text1.setVisible(true);
- text1.setBounds(135, 30, 300, 50);
- text1.setFont(new Font("Calabria", Font.BOLD, 16));
- button.setBounds(195, 350, 100, 35);
- box1.setVisible(true);
- box1.setBounds(195, 110, 150, 35);
- box2.setVisible(true);
- box2.setBounds(195, 190, 150, 35);
- box3.setVisible(true);
- box3.setBounds(195, 270, 150, 35);
- button.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ae) {
- if(box1.isSelected()) {
- panel2.setLayout(null);
- f.setVisible(false);
- JFrame f5 = new JFrame();
- f5.setVisible(true);
- f5.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f5.setLocationRelativeTo(null);
- f5.setTitle("Klimmzug");
- f5.setBounds(100, 300, 500, 500);
- anzahl1 = new JLabel("Anzahl: ");
- anzahl1.setFont(font);
- anzahl1.setBounds(140, 123, 75, 15);
- anzahl1.setVisible(true);
- JTextField A0 = new JTextField(5);
- A0.setBounds(210, 120, 32, 25);
- A0.setDocument(createNumericDocumentWithMaxLength(3));
- JTextField A2 = new JTextField();
- A2.setDocument(createNumericDocumentWithMaxLength1(2));
- A2.setBounds(210, 180, 32, 25);
- klasse1 = new JLabel("Alter: ");
- klasse1.setFont(font);
- klasse1.setBounds(140, 183, 75, 15);
- klasse1.setVisible(true);
- JLabel t2 = new JLabel("Anzahl:");
- //Erg�nzen//
- JLabel t3 = new JLabel("Alter:");
- //Erg�nzen//
- berechnen1.setBounds(160, 280, 115, 35);
- panel2.add(A0);
- panel2.add(A2);
- panel2.add(anzahl1);
- panel2.add(klasse1);
- panel2.add(berechnen1);
- f5.add(panel2);
- }else {
- if(box2.isSelected()) {
- panel2.setLayout(null);
- f.setVisible(false);
- JFrame f2 = new JFrame();
- f2.setVisible(true);
- f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f2.setLocationRelativeTo(null);
- f2.setTitle("Standweitsprung");
- f2.setBounds(100, 300, 500, 500);
- anzahl2 = new JLabel("Anzahl: ");
- anzahl2.setFont(font);
- anzahl2.setBounds(140, 123, 75, 15);
- anzahl2.setVisible(true);
- JTextField A3 = new JTextField(5);
- A3.setBounds(210, 120, 32, 25);
- A3.setDocument(createNumericDocumentWithMaxLength(3));
- JTextField A4 = new JTextField();
- A4.setDocument(createNumericDocumentWithMaxLength1(2));
- A4.setBounds(210, 180, 32, 25);
- klasse2 = new JLabel("Alter: ");
- klasse2.setFont(font);
- klasse2.setBounds(140, 183, 75, 15);
- klasse2.setVisible(true);
- JLabel t2 = new JLabel("Anzahl:");
- //Erg�nzen//
- JLabel t3 = new JLabel("Klasse:");
- //Erg�nzen//
- berechnen2.setBounds(160, 280, 115, 35);
- panel3.add(A3);
- panel3.add(A4);
- panel3.add(anzahl2);
- panel3.add(klasse2);
- panel3.add(berechnen2);
- }else {
- if(box3.isSelected()) {
- f.setVisible(false);
- JFrame f4 = new JFrame();
- f4.setVisible(true);
- f4.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- f4.setLocationRelativeTo(null);
- f4.setTitle("Beugestütz");
- f4.setBounds(100, 300, 500, 500);
- JLabel t2 = new JLabel("Anzahl:");
- t2.setBounds(12, 50, 100, 300);
- t2.setVisible(true);
- JLabel t3 = new JLabel("Alter:");
- //Erg�nzen//
- panel.add(t2);
- }
- }
- }
- }
- });
- box1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ac) {
- // TODO Auto-generated method stub
- if(box1.isSelected() == true) {
- box2.setSelected(false);
- box3.setSelected(false);
- }
- }
- });
- box2.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ac) {
- // TODO Auto-generated method stub
- if(box2.isSelected() == true) {
- box1.setSelected(false);
- box3.setSelected(false);
- }
- }
- });
- box3.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent ac) {
- // TODO Auto-generated method stub
- if(box3.isSelected() == true) {
- box1.setSelected(false);
- box2.setSelected(false);
- }
- }
- });
- panel.add(button);
- panel.add(box1);
- panel.add(box2);
- panel.add(box3);
- panel.add(text1);
- f.add(panel);
- }
- public void b1click() {
- berechnen1.addActionListener(new ActionListener() {
- @Override
- public void actionPerformed(ActionEvent a) {
- // TODO Auto-generated method stub
- int parse = Integer.parseInt(A0.getText());
- if(parse >= 14) {
- JOptionPane.showMessageDialog(null, "It works!");
- } else {
- JOptionPane.showMessageDialog(null, "Bitte benutzen Sie den Punkterechner für unter 14 Jährige!");
- }
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement