Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package PROJ_0_GUI;
- import javax.swing.*;
- import java.util.List;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- public class ChildWindowView extends JFrame {
- private final LogController ctrl;
- private JPanel jPanel;
- private JPanel jPanel2;
- private JPanel jPanel3;
- JScrollPane jsp;
- public ChildWindowView(LogController ctrl) {
- this.ctrl = ctrl;
- body();
- }
- private void body() {
- setTitle("Hello, world3!");
- jPanel = new JPanel(); //Tworzę wnętrzę (w srodku ScrollPane i jpanel2)
- jPanel2 = new JPanel(); //Tworzę wnętrzę
- jPanel3 = new JPanel(); //Tworzę wnętrzę // tutaj umieszczoy pole do wpisania danych i przycisk
- jPanel.setLayout(new BoxLayout(jPanel, BoxLayout.Y_AXIS)); //Ustawiam układ pionowy
- jPanel2.setLayout(new BoxLayout(jPanel2, BoxLayout.Y_AXIS)); //Ustawiam układ pionowy
- jPanel3.setLayout(new BoxLayout(jPanel3, BoxLayout.X_AXIS)); //Ustawiam układ poziomy
- this.add(jPanel);
- jsp = new JScrollPane(jPanel2); // Tworzymy opakowanie z możliwością scrolla //w srodku jpanel2 to ktorego bedzie dostawiane dane
- jPanel.add(jsp); // dodanie scroolpane
- //Komponenty
- JTextField textArea = new JTextField();
- JButton jButton = new JButton("Add");
- // Dodanie komponentów
- jPanel.add(jPanel3);
- jPanel3.add(textArea);
- jPanel3.add(jButton);
- jButton.addActionListener(new ActionListener() { //Akcja przycisku
- @Override
- public void actionPerformed(ActionEvent e) {
- if (textArea.getText().trim().length() > 0) {
- ctrl.addText(textArea); //metoda dodaje napis listy danych
- //ctrl.updateAll(); //metoda przechodzi po liscie okienek, czysci dane, wypisuje cała liste
- ctrl.updateLast(); //metoda przechodzi po liscie okienek, dodaje ostatni element listy
- }
- }
- });
- pack();
- setSize(512, 384);
- System.out.println(textArea.getHeight());
- // jsp.setMinimumSize(new Dimension(100, 300)); //ustawienie rozmiaru scrollpane
- jPanel3.setMaximumSize(new Dimension(this.getWidth(), 100)); //ustawienie rozmiaru scrollpane
- }
- @Override
- public void invalidate() {
- super.invalidate();
- jsp.setMinimumSize(new Dimension(this.getWidth(), this.getHeight()-jPanel3.getHeight())); //ustawienie rozmiaru scrollpane
- jPanel3.setMaximumSize (new Dimension(this.getWidth(),jPanel3.getHeight()));
- }
- public void showLogs(List<Log> data) { //metoda dodaje liste w postaci labeli
- for (Log log : data) {
- JLabel jLabel = new JLabel(log.toString());
- jPanel2.add(jLabel);
- }
- jPanel2.revalidate();
- }
- public void start() {
- setVisible(true);
- }
- public void clearData() { //metoda kasuje labele w widoku
- jPanel2.removeAll();
- }
- public void addLast(Log log) { //metoda dodaje labele
- JLabel jLabel = new JLabel(log.toString());
- jPanel2.add(jLabel);
- jPanel2.revalidate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement