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.
Következő változat | Előző változat | ||
oktatas:programozas:java:java_komponensek [2023/01/01 22:20] – létrehozva admin | oktatas:programozas:java:java_komponensek [2023/09/12 19:33] (aktuális) – admin | ||
---|---|---|---|
Sor 3: | Sor 3: | ||
====== Java komponensek ====== | ====== Java komponensek ====== | ||
- | * **Szerző: | + | * [[oktatas: |
- | * Copyright (c) Sallai András, 2023 | + | * [[oktatas:programozás: |
- | * Licenc: | + | |
- | * Web: https://szit.hu | + | |
- | + | ||
- | ===== Bevezetés ===== | + | |
- | + | ||
- | Java komponensek | + | |
- | + | ||
- | + | ||
- | ===== Könyvtárszerkezet ===== | + | |
- | + | ||
- | < | + | |
- | app01/ | + | |
- | |-lib/ | + | |
- | |-src/ | + | |
- | | |-controllers/ | + | |
- | | | | + | |
- | | |-models/ | + | |
- | | |-views/ | + | |
- | | | | + | |
- | | | | + | |
- | | `-App.java | + | |
- | |-.gitignore | + | |
- | `-README.md | + | |
- | </ | + | |
- | + | ||
- | ===== ButtonPanel ===== | + | |
- | + | ||
- | <code java src/ | + | |
- | 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< | + | |
- | public ButtonPanel() { | + | |
- | this.initPanel(); | + | |
- | } | + | |
- | public void addButton(String text) { | + | |
- | JButton button = new JButton(text); | + | |
- | this.add(button); | + | |
- | this.buttons.put(text, | + | |
- | } | + | |
- | private void initPanel() { | + | |
- | this.buttons = new HashMap<> | + | |
- | this.setLayout(new BoxLayout(this, | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | ===== A ButtonPanel használata ===== | + | |
- | + | ||
- | <code java src/ | + | |
- | import controllers.MainController; | + | |
- | + | ||
- | public class App { | + | |
- | public static void main(String[] args) throws Exception { | + | |
- | new MainController(); | + | |
- | } | + | |
- | } | + | |
- | </ | + | |
- | + | ||
- | + | ||
- | <code java src/ | + | |
- | 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(" | + | |
- | this.buttonPanel.addButton(" | + | |
- | this.buttonPanel.addButton(" | + | |
- | } | + | |
- | private void addComponent() { | + | |
- | this.add(this.buttonPanel); | + | |
- | } | + | |
- | private void initWindow() { | + | |
- | this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | + | |
- | this.setSize(400, | + | |
- | this.setVisible(true); | + | |
- | } | + | |
- | } | + | |
- | + | ||
- | </ | + | |
- | + | ||
- | <code java src/ | + | |
- | 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(" | + | |
- | JButton aboutButton = this.mainwindow.buttonPanel.buttons.get(" | + | |
- | JButton exitButton = this.mainwindow.buttonPanel.buttons.get(" | + | |
- | calcButton.addActionListener(e -> { | + | |
- | System.out.println(" | + | |
- | }); | + | |
- | aboutButton.addActionListener(e -> { | + | |
- | System.out.println(" | + | |
- | }); | + | |
- | exitButton.addActionListener(e -> { | + | |
- | System.out.println(" | + | |
- | }); | + | |
- | } | + | |
- | } | + | |
- | </ | + |
oktatas/programozas/java/java_komponensek.1672608023.txt.gz · Utolsó módosítás: 2023/01/01 22:20 szerkesztette: admin