From f7a0de004158ae46a701e3895b3dadabaa8becfc Mon Sep 17 00:00:00 2001 From: ahren Date: Mon, 18 Dec 2023 13:07:14 +0100 Subject: [PATCH] erfolg nr 1 --- src/ChatProgramm/Start.java | 8 + .../controller/GrafikController.java | 58 ++++++ src/ChatProgramm/view/ChatView.form | 15 +- src/ChatProgramm/view/ChatView.java | 175 +++++++++--------- src/ChatProgramm/view/GrafikFrame.form | 89 --------- src/ChatProgramm/view/GrafikFrame.java | 171 ----------------- 6 files changed, 159 insertions(+), 357 deletions(-) create mode 100644 src/ChatProgramm/controller/GrafikController.java delete mode 100644 src/ChatProgramm/view/GrafikFrame.form delete mode 100644 src/ChatProgramm/view/GrafikFrame.java diff --git a/src/ChatProgramm/Start.java b/src/ChatProgramm/Start.java index 440bd8d..2980a17 100644 --- a/src/ChatProgramm/Start.java +++ b/src/ChatProgramm/Start.java @@ -6,7 +6,10 @@ package ChatProgramm; import ChatProgramm.controller.CommandController; +import ChatProgramm.controller.GrafikController; +import ChatProgramm.model.GrafikModel; import ChatProgramm.view.ChatView; +import ChatProgramm.view.GrafikView; import javax.swing.JOptionPane; import javax.swing.UIManager; @@ -18,7 +21,12 @@ public class Start { public Start() { + GrafikModel model = new GrafikModel(); ChatView view = new ChatView(); + GrafikView zeichenflaeche = view.getGvZeichenflaeche(); + zeichenflaeche.setModel(model); + GrafikController controller = new GrafikController(zeichenflaeche, model); + controller.registerEvents(); CommandController controller_commands = new CommandController(view); controller_commands.registerEvents(); controller_commands.registerCommands(); diff --git a/src/ChatProgramm/controller/GrafikController.java b/src/ChatProgramm/controller/GrafikController.java new file mode 100644 index 0000000..0fcbb9a --- /dev/null +++ b/src/ChatProgramm/controller/GrafikController.java @@ -0,0 +1,58 @@ +/* + * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license + * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template + */ + +package ChatProgramm.controller; + +import java.awt.Point; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; +import java.awt.event.MouseMotionListener; +import ChatProgramm.model.GrafikModel; +import ChatProgramm.view.GrafikView; + +/** + * + * @author le + */ +public class GrafikController extends MouseAdapter implements MouseMotionListener +{ + private GrafikView view; + private GrafikModel model; + + public GrafikController(GrafikView view, GrafikModel model) + { + this.view = view; + this.model = model; + } + + public void registerEvents() + { + view.addMouseMotionListener(this); + view.addMouseListener(this); + } + + @Override + public void mouseDragged(MouseEvent evt) + { + Point p = evt.getPoint(); + model.addPoint(p); + view.drawPoint(p); + } + + @Override + public void mouseMoved(MouseEvent e) + { + } + + @Override + public void mouseReleased(MouseEvent evt) + { + model.endShape(); +// if (evt.getButton() == MouseEvent.BUTTON3) +// { +// view.doPrint(); +// } + } +} diff --git a/src/ChatProgramm/view/ChatView.form b/src/ChatProgramm/view/ChatView.form index 7a3ee69..4523ccf 100644 --- a/src/ChatProgramm/view/ChatView.form +++ b/src/ChatProgramm/view/ChatView.form @@ -107,24 +107,15 @@ - + - - - - - - - - - - - + + diff --git a/src/ChatProgramm/view/ChatView.java b/src/ChatProgramm/view/ChatView.java index 8c27d57..9a228de 100644 --- a/src/ChatProgramm/view/ChatView.java +++ b/src/ChatProgramm/view/ChatView.java @@ -11,6 +11,14 @@ package ChatProgramm.view; public class ChatView extends javax.swing.JFrame { + /** + * @return the gvZeichenflaeche + */ + public ChatProgramm.view.GrafikView getGvZeichenflaeche() + { + return gvZeichenflaeche; + } + /** * Creates new form ChatView */ @@ -25,91 +33,88 @@ public class ChatView extends javax.swing.JFrame * regenerated by the Form Editor. */ @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() { + // //GEN-BEGIN:initComponents + private void initComponents() + { - dialogChooseMode = new javax.swing.JDialog(); - lblMode = new javax.swing.JLabel(); - BtnServer = new javax.swing.JRadioButton(); - BtnClient = new javax.swing.JRadioButton(); - jPanel1 = new javax.swing.JPanel(); - BtnConnect = new javax.swing.JButton(); - BtnGrpMode = new javax.swing.ButtonGroup(); - jPanel2 = new javax.swing.JPanel(); + dialogChooseMode = new javax.swing.JDialog(); + lblMode = new javax.swing.JLabel(); + BtnServer = new javax.swing.JRadioButton(); + BtnClient = new javax.swing.JRadioButton(); + jPanel1 = new javax.swing.JPanel(); + BtnConnect = new javax.swing.JButton(); + BtnGrpMode = new javax.swing.ButtonGroup(); + gvZeichenflaeche = new ChatProgramm.view.GrafikView(); - dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208)); - dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1)); + dialogChooseMode.setMinimumSize(new java.awt.Dimension(278, 208)); + dialogChooseMode.getContentPane().setLayout(new java.awt.GridLayout(0, 1)); - lblMode.setText(" Choose your mode:"); - dialogChooseMode.getContentPane().add(lblMode); + lblMode.setText(" Choose your mode:"); + dialogChooseMode.getContentPane().add(lblMode); - BtnGrpMode.add(BtnServer); - BtnServer.setText("Server"); - BtnServer.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - BtnServerActionPerformed(evt); - } - }); - dialogChooseMode.getContentPane().add(BtnServer); + BtnGrpMode.add(BtnServer); + BtnServer.setText("Server"); + BtnServer.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(java.awt.event.ActionEvent evt) + { + BtnServerActionPerformed(evt); + } + }); + dialogChooseMode.getContentPane().add(BtnServer); - BtnGrpMode.add(BtnClient); - BtnClient.setText("Client"); - BtnClient.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - BtnClientActionPerformed(evt); - } - }); - dialogChooseMode.getContentPane().add(BtnClient); + BtnGrpMode.add(BtnClient); + BtnClient.setText("Client"); + BtnClient.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(java.awt.event.ActionEvent evt) + { + BtnClientActionPerformed(evt); + } + }); + dialogChooseMode.getContentPane().add(BtnClient); - BtnConnect.setText("Connect"); - BtnConnect.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(java.awt.event.ActionEvent evt) { - BtnConnectActionPerformed(evt); - } - }); + BtnConnect.setText("Connect"); + BtnConnect.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(java.awt.event.ActionEvent evt) + { + BtnConnectActionPerformed(evt); + } + }); - javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); - jPanel1.setLayout(jPanel1Layout); - jPanel1Layout.setHorizontalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap(65, Short.MAX_VALUE) - .addComponent(BtnConnect) - .addContainerGap(76, Short.MAX_VALUE)) - ); - jPanel1Layout.setVerticalGroup( - jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addContainerGap() - .addComponent(BtnConnect) - .addContainerGap(57, Short.MAX_VALUE)) - ); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); + jPanel1.setLayout(jPanel1Layout); + jPanel1Layout.setHorizontalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap(65, Short.MAX_VALUE) + .addComponent(BtnConnect) + .addContainerGap(76, Short.MAX_VALUE)) + ); + jPanel1Layout.setVerticalGroup( + jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(jPanel1Layout.createSequentialGroup() + .addContainerGap() + .addComponent(BtnConnect) + .addContainerGap(57, Short.MAX_VALUE)) + ); - dialogChooseMode.getContentPane().add(jPanel1); + dialogChooseMode.getContentPane().add(jPanel1); - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - setMinimumSize(new java.awt.Dimension(568, 548)); - addWindowListener(new java.awt.event.WindowAdapter() { - public void windowOpened(java.awt.event.WindowEvent evt) { - formWindowOpened(evt); - } - }); + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setMinimumSize(new java.awt.Dimension(568, 548)); + addWindowListener(new java.awt.event.WindowAdapter() + { + public void windowOpened(java.awt.event.WindowEvent evt) + { + formWindowOpened(evt); + } + }); + getContentPane().add(gvZeichenflaeche, java.awt.BorderLayout.CENTER); - javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2); - jPanel2.setLayout(jPanel2Layout); - jPanel2Layout.setHorizontalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 400, Short.MAX_VALUE) - ); - jPanel2Layout.setVerticalGroup( - jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGap(0, 300, Short.MAX_VALUE) - ); - - getContentPane().add(jPanel2, java.awt.BorderLayout.CENTER); - - pack(); - }// //GEN-END:initComponents + pack(); + }// //GEN-END:initComponents private void BtnClientActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnClientActionPerformed {//GEN-HEADEREND:event_BtnClientActionPerformed @@ -180,16 +185,16 @@ public class ChatView extends javax.swing.JFrame }); } - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JRadioButton BtnClient; - private javax.swing.JButton BtnConnect; - private javax.swing.ButtonGroup BtnGrpMode; - private javax.swing.JRadioButton BtnServer; - private javax.swing.JDialog dialogChooseMode; - private javax.swing.JPanel jPanel1; - private javax.swing.JPanel jPanel2; - private javax.swing.JLabel lblMode; - // End of variables declaration//GEN-END:variables + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JRadioButton BtnClient; + private javax.swing.JButton BtnConnect; + private javax.swing.ButtonGroup BtnGrpMode; + private javax.swing.JRadioButton BtnServer; + private javax.swing.JDialog dialogChooseMode; + private ChatProgramm.view.GrafikView gvZeichenflaeche; + private javax.swing.JPanel jPanel1; + private javax.swing.JLabel lblMode; + // End of variables declaration//GEN-END:variables /** * @return the BtnClient diff --git a/src/ChatProgramm/view/GrafikFrame.form b/src/ChatProgramm/view/GrafikFrame.form deleted file mode 100644 index 6672b4f..0000000 --- a/src/ChatProgramm/view/GrafikFrame.form +++ /dev/null @@ -1,89 +0,0 @@ - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/ChatProgramm/view/GrafikFrame.java b/src/ChatProgramm/view/GrafikFrame.java deleted file mode 100644 index 7a2dec7..0000000 --- a/src/ChatProgramm/view/GrafikFrame.java +++ /dev/null @@ -1,171 +0,0 @@ -/* - * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license - * Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template - */ -package ChatProgramm.view; - -/** - * - * @author le - */ -public class GrafikFrame extends javax.swing.JFrame -{ - - /** - * @return the gvZeichenflaeche - */ - public ChatProgramm.view.GrafikView getGvZeichenflaeche() - { - return gvZeichenflaeche; - } - - /** - * @return the FcFileChooser - */ - public javax.swing.JFileChooser getFcFileChooser() - { - return FcFileChooser; - } - - /** - * @return the btnFileOpen - */ - public javax.swing.JButton getBtnFileOpen() - { - return btnFileOpen; - } - - /** - * @return the btnFileSave - */ - public javax.swing.JButton getBtnFileSave() - { - return btnFileSave; - } - /** - * @return the gZeichenflaeche - */ - - - /** - * Creates new form GrafikFrame - */ - public GrafikFrame() - { - initComponents(); - } - - /** - * This method is called from within the constructor to initialize the form. - * WARNING: Do NOT modify this code. The content of this method is always - * regenerated by the Form Editor. - */ - @SuppressWarnings("unchecked") - // //GEN-BEGIN:initComponents - private void initComponents() - { - - FcFileChooser = new javax.swing.JFileChooser(); - jToolBar1 = new javax.swing.JToolBar(); - btnFileOpen = new javax.swing.JButton(); - btnFileSave = new javax.swing.JButton(); - btnPrint = new javax.swing.JButton(); - gvZeichenflaeche = new ChatProgramm.view.GrafikView(); - - setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); - - jToolBar1.setRollover(true); - - btnFileOpen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Open24.gif"))); // NOI18N - btnFileOpen.setToolTipText("Open File"); - btnFileOpen.setFocusable(false); - btnFileOpen.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnFileOpen.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - jToolBar1.add(btnFileOpen); - - btnFileSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Save24.gif"))); // NOI18N - btnFileSave.setToolTipText("Safe File"); - btnFileSave.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnFileSave.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - jToolBar1.add(btnFileSave); - - btnPrint.setIcon(new javax.swing.ImageIcon(getClass().getResource("/mvcgrafik/view/Print24.gif"))); // NOI18N - btnPrint.setToolTipText("Print File"); - btnPrint.setFocusable(false); - btnPrint.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); - btnPrint.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); - jToolBar1.add(btnPrint); - - getContentPane().add(jToolBar1, java.awt.BorderLayout.PAGE_START); - getContentPane().add(gvZeichenflaeche, java.awt.BorderLayout.CENTER); - - setSize(new java.awt.Dimension(540, 412)); - setLocationRelativeTo(null); - }// //GEN-END:initComponents - - /** - * @param args the command line arguments - */ - public static void main(String args[]) - { - /* Set the Nimbus look and feel */ - // - /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. - * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html - */ - try - { - for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) - { - if ("Nimbus".equals(info.getName())) - { - javax.swing.UIManager.setLookAndFeel(info.getClassName()); - break; - } - } - } - catch (ClassNotFoundException ex) - { - java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - catch (InstantiationException ex) - { - java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - catch (IllegalAccessException ex) - { - java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - catch (javax.swing.UnsupportedLookAndFeelException ex) - { - java.util.logging.Logger.getLogger(GrafikFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); - } - // - // - - /* Create and display the form */ - java.awt.EventQueue.invokeLater(new Runnable() - { - public void run() - { - new GrafikFrame().setVisible(true); - } - }); - } - - // Variables declaration - do not modify//GEN-BEGIN:variables - private javax.swing.JFileChooser FcFileChooser; - private javax.swing.JButton btnFileOpen; - private javax.swing.JButton btnFileSave; - private javax.swing.JButton btnPrint; - private ChatProgramm.view.GrafikView gvZeichenflaeche; - private javax.swing.JToolBar jToolBar1; - // End of variables declaration//GEN-END:variables - - /** - * @return the btnPrint - */ - public javax.swing.JButton getBtnPrint() { - return btnPrint; - } -}