Created
February 11, 2020 20:49
-
-
Save HurricanKai/17cd6763130c2d528b223b6fa38f0244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.event.ActionEvent; | |
| import java.awt.event.ActionListener; | |
| public class ActionHandler implements ActionListener { | |
| @Override | |
| public void actionPerformed(ActionEvent e) { | |
| if (e.getSource() == Var.btnResume) { | |
| Var.imSpiel = true; | |
| Var.jf1.requestFocus(); | |
| Var.imMen� = false; | |
| Var.imOptionsmen� = false; | |
| Var.btnResume.setVisible(false); | |
| Var.btnOptionen.setVisible(false); | |
| Var.btnExit.setVisible(false); | |
| Var.btnFragen.setVisible(true); | |
| Var.fragenField.setVisible(true); | |
| KeyHandler.tempKeyHandler = 0; | |
| Var.jf1.requestFocus(); | |
| }else if (e.getSource() == Var.btnFragen) { | |
| Var.imSpiel = false; | |
| Var.jf1.requestFocus(); | |
| Var.imMen� = false; | |
| Var.imOptionsmen� = false; | |
| Var.btnResume.setVisible(false); | |
| Var.btnOptionen.setVisible(false); | |
| Var.btnExit.setVisible(false); | |
| Var.btnFragen.setVisible(true); | |
| Var.fragenField.setVisible(true); | |
| KeyHandler.tempKeyHandler = 0; | |
| Var.jf1.requestFocus(); | |
| } else if (e.getSource() == Var.btnOptionen) { | |
| Var.imSpiel = false; | |
| Var.imMen� = false; | |
| Var.imOptionsmen� = true; | |
| Var.btnResume.setVisible(true); | |
| Var.btnOptionen.setVisible(false); | |
| Var.btnExit.setVisible(false); | |
| Var.btnFragen.setVisible(false); | |
| Var.fragenField.setVisible(false); | |
| KeyHandler.tempKeyHandler = 1; | |
| Var.jf1.requestFocus(); | |
| }else if(e.getSource()==Var.btnExit) { | |
| System.exit(0); | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.Color; | |
| import java.awt.Container; | |
| import java.awt.FlowLayout; | |
| import java.awt.Font; | |
| import java.awt.event.ActionEvent; | |
| import java.awt.event.ActionListener; | |
| import java.awt.event.MouseAdapter; | |
| import java.awt.event.MouseEvent; | |
| import javax.swing.*; | |
| public class Gui{ | |
| public Gui() { | |
| Var.jf1 = new JFrame(); | |
| Var.jf1.setSize(Var.screenwidth, Var.screenheight); | |
| Var.jf1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
| Var.jf1.setLocationRelativeTo(null); | |
| Var.jf1.setLayout(null); | |
| Var.jf1.setTitle("Die inoffizielle Beratungsapp der Bundeswehr"); | |
| Var.jf1.setResizable(false); | |
| Var.jf1.requestFocus(); | |
| Var.jf1.addKeyListener(new KeyHandler()); | |
| Var.jf1.setVisible(true); | |
| Var.lbl1 = new Label(); | |
| Var.lbl1.setBounds(0, 0, Var.screenwidth, Var.screenheight); | |
| Var.lbl1.setVisible(true); | |
| Var.jf1.add(Var.lbl1); | |
| Var.btnFragen = new JButton("Welche Fragen kann ich stellen?"); | |
| // Var.btnFragen.setText("Welche Fragen kann ich stellen?"); | |
| Var.btnFragen.setBounds(950, 40, 300, 25); | |
| // Var.btnFragen.addActionListener(new ActionHandler()); | |
| // Var.btnFragen.setBackground(Color.BLACK); | |
| // Var.btnFragen.setFont(new Font("Arial", Font.BOLD, 15)); | |
| // Var.btnFragen.setForeground(Color.WHITE); | |
| Var.btnFragen.addActionListener(new ActionListener() { | |
| @Override | |
| public void actionPerformed(ActionEvent e) { | |
| int z = (int) (Math.random() * 5); | |
| Var.fragenField.setText(Var.word[z]); | |
| } | |
| }); | |
| // Var.btnFragen.setBorder(null); | |
| // Var.btnFragen.setFocusPainted(false); | |
| // Var.btnFragen.addMouseListener(new MouseAdapter() { | |
| // | |
| // public void mouseEntered(MouseEvent evt) { | |
| // Var.btnFragen.setBackground(new Color(0, 255, 115)); | |
| // Var.btnFragen.setForeground(Color.BLACK); | |
| // } | |
| // | |
| // public void mouseExited(MouseEvent evt) { | |
| // Var.btnFragen.setBackground(Color.BLACK); | |
| // Var.btnFragen.setForeground(Color.WHITE); | |
| // } | |
| // }); | |
| Var.btnFragen.setVisible(true); | |
| Var.jf1.add(Var.btnFragen); | |
| Var.btnFragen.setVisible(true); | |
| Var.fragenField = new JTextField(25); | |
| Var.fragenField.setEditable(false); | |
| Var.fragenField.setBounds(950, 70, 300, 25); | |
| Var.fragenField.setVisible(true); | |
| Var.jf1.add(Var.fragenField); | |
| Var.fragenField.setVisible(true); | |
| Var.word = new String[5]; | |
| Var.word[0] = "Probieren Sie es mit Fragen zu: Panzern"; | |
| Var.word[1] = "Probieren Sie es mit Fragen zu: Soldaten"; | |
| Var.word[2] = "Probieren Sie es mit Fragen zu: Waffen"; | |
| Var.word[3] = "Probieren Sie es mit Fragen zu: Fahrzeugen"; | |
| Var.word[4] = "Probieren Sie es mit Fragen zu: Bundeswehr"; | |
| Var.btnOptionen = new JButton(); | |
| Var.btnOptionen.setText("Optionen"); | |
| Var.btnOptionen.setBounds(330, 250, 725, 50); | |
| Var.btnOptionen.setVisible(false); | |
| Var.btnOptionen.addActionListener(new ActionHandler()); | |
| Var.btnOptionen.setBackground(Color.BLACK); | |
| Var.btnOptionen.setFont(new Font("Arial", Font.BOLD, 40)); | |
| Var.btnOptionen.setForeground(Color.WHITE); | |
| Var.btnOptionen.setBorder(null); | |
| Var.btnOptionen.setFocusPainted(false); | |
| Var.btnOptionen.addMouseListener(new MouseAdapter() { | |
| public void mouseEntered(MouseEvent evt) { | |
| Var.btnOptionen.setBackground(new Color(0, 255, 115)); | |
| Var.btnOptionen.setForeground(Color.BLACK); | |
| } | |
| public void mouseExited(MouseEvent evt) { | |
| Var.btnOptionen.setBackground(Color.BLACK); | |
| Var.btnOptionen.setForeground(Color.WHITE); | |
| } | |
| }); | |
| Var.jf1.add(Var.btnOptionen); | |
| Var.btnExit = new JButton(); | |
| Var.btnExit.setText("Exit"); | |
| Var.btnExit.setBounds(330, 350, 725, 50); | |
| Var.btnExit.setVisible(false); | |
| Var.btnExit.addActionListener(new ActionHandler()); | |
| Var.btnExit.setBackground(Color.BLACK); | |
| Var.btnExit.setFont(new Font("Arial", Font.BOLD, 40)); | |
| Var.btnExit.setForeground(Color.WHITE); | |
| Var.btnExit.setBorder(null); | |
| Var.btnExit.setFocusPainted(false); | |
| Var.btnExit.addMouseListener(new MouseAdapter() { | |
| public void mouseEntered(MouseEvent evt) { | |
| Var.btnExit.setBackground(new Color(0, 255, 115)); | |
| Var.btnExit.setForeground(Color.BLACK); | |
| } | |
| public void mouseExited(MouseEvent evt) { | |
| Var.btnExit.setBackground(Color.BLACK); | |
| Var.btnExit.setForeground(Color.WHITE); | |
| } | |
| }); | |
| Var.jf1.add(Var.btnExit); | |
| Var.eingabefeld = new JTextField(); | |
| Var.eingabefeld.setEditable(true); | |
| Var.eingabefeld.setBounds(250, 500,750,25); | |
| Var.eingabefeld.setVisible(true); | |
| Var.jf1.add(Var.eingabefeld); | |
| Var.eingabefeld.setVisible(true); | |
| Var.jf1.add(Var.eingabefeld); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.event.KeyEvent; | |
| import java.awt.event.KeyListener; | |
| public class KeyHandler implements KeyListener { | |
| static int tempKeyHandler = 0; | |
| @Override | |
| public void keyTyped(KeyEvent e) { | |
| } | |
| @Override | |
| public void keyPressed(KeyEvent e) { | |
| if (e.getKeyCode() == KeyEvent.VK_END) { | |
| System.exit(0); | |
| } | |
| if(Var.imSpiel==true) { | |
| Var.btnFragen.setVisible(true); | |
| Var.fragenField.setVisible(true); | |
| } | |
| // Men� | |
| if (tempKeyHandler == 0) { | |
| if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { | |
| Var.imSpiel = false; | |
| Var.imMen� = true; | |
| Var.imOptionsmen� = false; | |
| Var.btnResume.setVisible(true); | |
| Var.btnExit.setVisible(true); | |
| Var.btnOptionen.setVisible(true); | |
| Var.btnFragen.setVisible(true); | |
| Var.fragenField.setVisible(true); | |
| tempKeyHandler++; | |
| } | |
| } else if (tempKeyHandler == 1) { | |
| if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { | |
| Var.imSpiel = true; | |
| Var.imMen� = false; | |
| Var.imOptionsmen� = false; | |
| Var.btnResume.setVisible(false); | |
| Var.btnExit.setVisible(false); | |
| Var.btnOptionen.setVisible(false); | |
| Var.imOptionsmen� = false; | |
| Var.btnFragen.setVisible(true); | |
| Var.fragenField.setVisible(true); | |
| Var.jf1.requestFocus(); | |
| tempKeyHandler--; | |
| } | |
| } | |
| } | |
| @Override | |
| public void keyReleased(KeyEvent e) { | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.Color; | |
| import java.awt.Font; | |
| import java.awt.Graphics; | |
| import java.awt.RenderingHints; | |
| import java.awt.Graphics2D; | |
| import javax.swing.JLabel; | |
| public class Label extends JLabel { | |
| private static final long serialVersionUID = 1L; | |
| protected void paintComponent(Graphics g) { | |
| super.paintComponent(g); | |
| Graphics2D g2d = (Graphics2D) g; | |
| g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); | |
| if (Var.imSpiel||Var.imMen�==false) { | |
| g.drawImage(Var.back, 0, 0, 1500, 1000, null); | |
| repaint(); | |
| g.setColor(new Color(255,255,255)); | |
| g.setFont(new Font("Arial", Font.BOLD, 15)); | |
| g.drawString("Willkommen zur inoffiziellen Beratungsapp der Bundeswehr. Wie kann ich Ihnen helfen?", 325, 150); | |
| g.drawRect(10, 10, Var.screenwidth-35, Var.screenheight-55); | |
| g.drawImage(Var.kreuz, 600, 15, 100,100, null); | |
| g.setFont(new Font("Arial", Font.BOLD, 40)); | |
| g.drawString("Systemdaten werden geladen... ", 350, 350); | |
| }else if(Var.imMen�) { | |
| g.drawImage(Var.back, 0, 0, 1500, 1000, null); | |
| g.setColor(new Color(255,255,255)); | |
| g.setFont(new Font("Arial", Font.BOLD, 20)); | |
| g.drawString("Sie befinden sich im Men�", 525, 50); | |
| g.drawRect(10, 10, Var.screenwidth-35, Var.screenheight-55); | |
| } | |
| }} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public class Main { | |
| public static void main(String[] args) { | |
| new Var(); | |
| new Gui(); | |
| new Label(); | |
| new ActionHandler(); | |
| new KeyHandler(); | |
| } | |
| } | |
| /* | |
| Fehler: | |
| JButtons werden nicht richtig angezeigt: | |
| JButton Fragen | |
| JButton Exit | |
| JButton Resume | |
| JButton Optionen | |
| JButton Mute | |
| JTextFields werden nicht richtig angezeigt: | |
| JTextField fragenField | |
| JTextField eingabefeld | |
| KeyHandler funktioniert nicht richtig: | |
| ESC - �ffnet Men�, schlie�t es aber nicht wieder. | |
| */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import java.awt.image.BufferedImage; | |
| //import java.io.File; | |
| //import java.io.IOException; | |
| import java.io.File; | |
| import java.io.IOException; | |
| import javax.imageio.ImageIO; | |
| //import javax.imageio.ImageIO; | |
| import javax.swing.JButton; | |
| import javax.swing.JFrame; | |
| import javax.swing.JTextField; | |
| public class Var { | |
| static JFrame jf1; | |
| static BufferedImage back; | |
| static int screenwidth = 1300, screenheight = 725; | |
| static Label lbl1; | |
| static String[] word; | |
| static JTextField fragenField; | |
| static JTextField eingabefeld; | |
| static JButton btnFragen,btnResume, btnOptionen, btnExit; | |
| static JButton mute; | |
| static boolean spielende = false; | |
| static boolean imSpiel = true, imMen� = false, imOptionsmen� = false; | |
| static BufferedImage kreuz; | |
| static boolean inApp; | |
| public Var() { | |
| try { | |
| back = ImageIO.read(new File("rsc/back.png")); | |
| kreuz= ImageIO.read(new File("rsc/kreuz.png")); | |
| } catch (IOException e) { | |
| e.printStackTrace(); | |
| System.out.println("Bilder konnten nicht geladen werden"); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment