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
}
}
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
How can i make the java class seperate into an MVC pattern? public class ChatView implements Acti...
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 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[]...
Why when executed my frame does not contain what i have added to it? Here is my code import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.JPanel; @SuppressWarnings("serial") public class AddressBook1 extends JFrame implements ActionListener { /** * */ JLabel name = new JLabel("Name: "); JLabel address = new JLabel("Address: "); JLabel phone = new JLabel("Phone: "); JLabel email = new JLabel("Email: ");...
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 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;
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...
package timing; import java.awt.event.*; import javax.swing.*; public class Timing implements ActionListener{ JButton button1; JLabel label1; public int minutes=3;//initial time public int time=minutes*60;//total amount of time in seconds only public int seconds=time%60; public String defaulttimeset="0"+Integer.toString(minutes)+":0"+Integer.toString(seconds); public static void main(String[] args) { Timing move=new Timing(); move.go(); } public void go(){ JFrame frame=new JFrame(); frame.setBounds(50,50,400,400); JPanel panel2=new JPanel(); button1=new JButton("Start Time"); panel2.add(button1); button1.setBounds(30,50,150,170); frame.getContentPane().add(button1);...
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 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 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...