Felhasználói eszközök

Eszközök a webhelyen


oktatas:programozas:java:java_komponensek

Különbségek

A kiválasztott változat és az aktuális verzió közötti különbségek a következők.

Összehasonlító nézet linkje

Következő változat
Előző változat
oktatas:programozas:java:java_komponensek [2023/01/01 22:20] – létrehozva adminoktatas:programozas:java:java_komponensek [2023/09/12 19:33] (aktuális) admin
Sor 3: Sor 3:
 ====== Java komponensek ====== ====== Java komponensek ======
  
-  * **Szerző:** Sallai András +  * [[oktatas:programozás:java:Java komponensek:Buttonpanel]] 
-  * Copyright (c) Sallai András, 2023 +  * [[oktatas:programozás:java:Java komponensek:Inputpanel]]
-  * Licenc: [[https://creativecommons.org/licenses/by-sa/4.0/|CC Attribution-Share Alike 4.0 International]] +
-  * Webhttps://szit.hu +
- +
-===== Bevezetés ===== +
- +
-Java komponensek készítése. +
- +
- +
-===== Könyvtárszerkezet ===== +
- +
-<code> +
-app01/ +
-  |-lib/ +
-  |-src/ +
-  |  |-controllers/ +
-  |  |   `-MainController.java +
-  |  |-models/ +
-  |  |-views/ +
-  |  |   |-ButtonPanel.java +
-  |  |   `-Mainwindow.java +
-  |  `-App.java +
-  |-.gitignore +
-  `-README.md +
-</code> +
- +
-===== ButtonPanel ===== +
- +
-<code java src/views/ButtonPanel.java> +
-package views; +
- +
-import java.util.HashMap; +
- +
-import javax.swing.BoxLayout; +
-import javax.swing.JButton; +
-import javax.swing.JPanel; +
- +
-public class ButtonPanel extends JPanel{ +
-    public HashMap<String, JButton> buttons; +
-    public ButtonPanel() { +
-        this.initPanel(); +
-    } +
-    public void addButton(String text) { +
-        JButton button = new JButton(text); +
-        this.add(button); +
-        this.buttons.put(text, button);         +
-    } +
-    private void initPanel() { +
-        this.buttons = new HashMap<>(); +
-        this.setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); +
-    } +
-+
-</code> +
- +
- +
-===== A ButtonPanel használata ===== +
- +
-<code java src/App.java> +
-import controllers.MainController; +
- +
-public class App { +
-    public static void main(String[args) throws Exception { +
-        new MainController(); +
-    } +
-+
-</code> +
- +
- +
-<code java src/views/Mainwindow.java> +
-package views; +
- +
-import javax.swing.JFrame; +
- +
-public class Mainwindow extends JFrame { +
-    public ButtonPanel buttonPanel; +
-    public Mainwindow() { +
-        initApp(); +
-    } +
-    private void initApp() { +
-        this.initComponent(); +
-        this.setComponent(); +
-        this.addComponent(); +
-        this.initWindow(); +
-    } +
-    private void initComponent() { +
-        this.buttonPanel = new ButtonPanel();     +
-    } +
-    private void setComponent() { +
-        this.buttonPanel.addButton("Számít"); +
-        this.buttonPanel.addButton("Névjegy"); +
-        this.buttonPanel.addButton("Kilépés"); +
-    } +
-    private void addComponent() { +
-        this.add(this.buttonPanel); +
-    } +
-    private void initWindow() { +
-        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); +
-        this.setSize(400, 300); +
-        this.setVisible(true); +
-    } +
-+
- +
-</code> +
- +
-<code java src/controllers/MainController.java> +
-package controllers; +
- +
-import javax.swing.JButton; +
- +
-import views.Mainwindow; +
- +
-public class MainController { +
-    Mainwindow mainwindow; +
-    public MainController() { +
-        this.mainwindow = new Mainwindow(); +
-        this.handleEvent(); +
-    } +
-    private void handleEvent() { +
- +
-        JButton calcButton = this.mainwindow.buttonPanel.buttons.get("Számít"); +
-        JButton aboutButton = this.mainwindow.buttonPanel.buttons.get("Névjegy"); +
-        JButton exitButton = this.mainwindow.buttonPanel.buttons.get("Kilépés"); +
-        calcButton.addActionListener(e -> { +
-            System.out.println("Számít árnyékeljárás..."); +
-        }); +
-        aboutButton.addActionListener(e -> { +
-            System.out.println("Névjegy árnyékeljárás..."); +
-        }); +
-        exitButton.addActionListener(e -> { +
-            System.out.println("Kilépés árnyékeljárás..."); +
-        }); +
-    } +
-+
-</code> +
oktatas/programozas/java/java_komponensek.1672608023.txt.gz · Utolsó módosítás: 2023/01/01 22:20 szerkesztette: admin