Question

How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...

How can i make the java class seperate into an MVC pattern?

public class ChatView implements ActionListener
{
   public static void main(String[] args)
   {
       JFrame chatFrame = new JFrame();
       JFrame chatFrame1 = new JFrame();
       JFrame chatFrame2 = new JFrame();
      
       JPanel chatPanel = new JPanel();
       JPanel chatPanel1 = new JPanel();
       JPanel chatPanel2 = new JPanel();
       chatFrame.setContentPane(chatPanel);
       chatFrame1.setContentPane(chatPanel1);
       chatFrame2.setContentPane(chatPanel2);
       chatFrame.setLayout(new FlowLayout());
       chatFrame1.setLayout(new FlowLayout());
       chatFrame2.setLayout(new FlowLayout());
       JTextField chatWrite = new JTextField();
       JTextField chatWrite1 = new JTextField();
       JTextField chatWrite2 = new JTextField();
       JTextArea chatDisplay = new JTextArea();
       JTextArea chatDisplay1 = new JTextArea();
       JTextArea chatDisplay2 = new JTextArea();
       JButton chatButton = new JButton("Send Message");
       JButton chatButton1 = new JButton("Send Message");
       JButton chatButton2 = new JButton("Send Message");
       chatDisplay.setPreferredSize(new Dimension(500, 450));
       chatDisplay1.setPreferredSize(new Dimension(500, 450));
       chatDisplay2.setPreferredSize(new Dimension(500, 450));
       chatDisplay.setEditable(false);
       chatDisplay1.setEditable(false);
       chatDisplay2.setEditable(false);
       chatWrite.setPreferredSize(new Dimension(300, 30));
       chatWrite1.setPreferredSize(new Dimension(300, 30));
       chatWrite2.setPreferredSize(new Dimension(300, 30));
       chatButton.addActionListener(new ActionListener()
       {
           public void actionPerformed(ActionEvent event)
           {
               String phrase = chatWrite.getText();
               chatDisplay.append("Derek: " + phrase + "\n");
               chatDisplay1.append("Derek: " + phrase + "\n");
               chatDisplay2.append("Derek: " + phrase + "\n");
               chatWrite.setText("");
           }
       });
      
       chatButton1.addActionListener(new ActionListener()
       {
           public void actionPerformed(ActionEvent event)
           {
               String phrase = chatWrite1.getText();
               chatDisplay.append("Ben: " + phrase + "\n");
               chatDisplay1.append("Ben: " + phrase + "\n");
               chatDisplay2.append("Ben: " + phrase + "\n");
               chatWrite1.setText("");
           }
       });
      
       chatButton2.addActionListener(new ActionListener()
       {
           public void actionPerformed(ActionEvent event)
           {
               String phrase = chatWrite2.getText();
               chatDisplay.append("Steve: " + phrase + "\n");
               chatDisplay1.append("Steve: " + phrase + "\n");
               chatDisplay2.append("Steve: " + phrase + "\n");
               chatWrite2.setText("");
           }
       });
      
       chatPanel.add(chatDisplay);
       chatPanel1.add(chatDisplay1);
       chatPanel2.add(chatDisplay2);
       chatPanel.add(chatWrite);
       chatPanel1.add(chatWrite1);
       chatPanel2.add(chatWrite2);
       chatPanel.add(chatButton);
       chatPanel1.add(chatButton1);
       chatPanel2.add(chatButton2);
       chatFrame.setSize(new Dimension(600, 600));
       chatFrame1.setSize(new Dimension(600, 600));
       chatFrame2.setSize(new Dimension(600, 600));
       chatFrame.setLocationRelativeTo(null);
       chatFrame1.setLocationRelativeTo(null);
       chatFrame2.setLocationRelativeTo(null);
       chatFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       chatFrame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       chatFrame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       chatFrame.setTitle("Chat Room - Derek");
       chatFrame1.setTitle("Chat Room - Ben");
       chatFrame2.setTitle("Chat Room - Steve");
       chatFrame.setVisible(true);
       chatFrame1.setVisible(true);
       chatFrame2.setVisible(true);

   }

   @Override
   public void actionPerformed(ActionEvent e) {
       // TODO Auto-generated method stub
      
   }

  
}

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Explanation:

Hi,

We can not break a single class into the MVC pattern. This has a valid reason. Let me explain...

What is MVC?

MVC Model View Controller.

When we define a project we should keep separating the view logic and DB classes.

So here the model is DB part, View is view(HTML) part and controller have logic and bind all of three.

So in the MVC pattern, we have three different parts.

Hope You understood. If not comment below. I will clear you.

Thanks

Add a comment
Know the answer?
Add Answer to:
How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import...

    Simple java GUI language translator. English to Spanish, French, or German import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class translatorApp extends JFrame implements ActionListener {    public static final int width = 500;    public static final int height = 300;    public static final int no_of_lines = 10;    public static final int chars_per_line = 20;    private JTextArea lan1;    private JTextArea lan2;    public static void main(String[] args){        translatorApp gui = new translatorApp();...

  • With the Code below, how would i add a "Back" Button to the bottom of the...

    With the Code below, how would i add a "Back" Button to the bottom of the history page so that it takes me back to the main function and continues to work? import java.awt.BorderLayout; import java.awt.Color; import java.awt.Dimension; import java.awt.GridLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Scanner; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JTextField; public class RecipeFinder { public static void main(String[]...

  • import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {...

    import java.awt.*; import javax.swing.*; import java.awt.event.*; import javax.swing.BorderFactory; import javax.swing.border.Border; public class Q1 extends JFrame {    public static void createAndShowGUI() {        JFrame frame = new JFrame("Q1");        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);        Font courierFont = new Font("Courier", Font.BOLD, 40);        Font arialFont = new Font("Arial", Font.BOLD, 40);        Font sansFont = new Font("Sans-serif", Font.BOLD, 20);        JLabel label = new JLabel("Enter a word"); label.setFont(sansFont);        Font font1 = new Font("Sans-serif", Font.BOLD, 40);       ...

  • please help me debug this Create a GUI for an application that lets the user calculate...

    please help me debug this Create a GUI for an application that lets the user calculate the hypotenuse of a right triangle. Use the Pythagorean Theorem to calculate the length of the third side. The Pythagorean Theorem states that the square of the hypotenuse of a right-triangle is equal to the sum of the squares of the opposite sides: alidate the user input so that the user must enter a double value for side A and B of the triangle....

  • I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label;...

    I am getting this Error can you please fix my Java code. import java.awt.Dialog; import java.awt.Label; import java.awt.TextArea; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map.Entry; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; public class Fall_2017 {    public TextArea courseInput;    public Label textAreaLabel;    public JButton addData;    public Dialog confirmDialog;    HashMap<Integer, ArrayList<String>> students;    public Fall_2017(){    courseInput = new TextArea(20, 40);    textAreaLabel = new Label("Student's data:");    addData = new JButton("Add...

  • I have been messing around with java lately and I have made this calculator. Is there...

    I have been messing around with java lately and I have made this calculator. Is there any way that I would be able to get a different sound to play on each different button 1 - 9 like a nokia phone? Thank you. *SOURCE CODE* import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font("monspaced",Font.PLAIN, 20); private JTextField textfield; private boolean number = true; private String equalOp = "="; private...

  • In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show...

    In Java Swing, in my ButtonHandler class, I need to have 2 different showDialog messages show when my acceptbutton1 is pressed. One message is if the mouse HAS been dragged. One is if the mouse HAS NOT been dragged. /// I tried to make the Points class or the Mouse Dragged function return a boolean of true, so that I could construct an IF/THEN statement for the showDialog messages, but my boolean value was never accepted by ButtonHandler. *************************ButtonHandler class************************************...

  • import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel...

    import javax.swing.*; import java.awt.event.*; import java.awt.*; public class BookReview extends JFrame implements ActionListener {       private JLabel titleLabel;       private JTextField titleTxtFd;       private JComboBox typeCmb;       private ButtonGroup ratingGP;       private JButton processBnt;       private JButton endBnt;       private JButton clearBnt;       private JTextArea entriesTxtAr;       private JRadioButton excellentRdBnt;       private JRadioButton veryGoodRdBnt;       private JRadioButton fairRdBnt;       private JRadioButton poorRdBnt;       private String ratingString;       private final String EXCELLENT = "Excellent";       private final String VERYGOOD = "Very Good";       private final String FAIR = "Fair";       private final String POOR = "Poor";       String...

  • Swing File Adder: Build a GUI that contains an input file, text box and Infile button....

    Swing File Adder: Build a GUI that contains an input file, text box and Infile button. It also must contain and output file, text box and Outfile button. Must also have a process button must read the infile and write to the outfile if not already written that is already selected and clear button. It must pull up a JFile chooser that allows us to brows to the file and places the full path name same with the output file.  Program...

  • Can you help me to link two frames in Java Swing and then if you click...

    Can you help me to link two frames in Java Swing and then if you click "Proceed button" it will link to the Second Frame...Thank you :) First frame code: //First import javax.swing.*; import java.awt.event.*; import java.io.*; public class Sample extends JFrame implements ActionListener { JMenuBar mb; JMenu file; JMenuItem open; JTextArea ta; JButton proceed= new JButton("Proceed"); Sample() { open = new JMenuItem("Open File"); open.addActionListener(this); file = new JMenu("File"); file.add(open); mb = new JMenuBar(); mb.setBounds(0, 0, 400, 20); mb.add(file); ta...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT