Respuesta :
Answer:
Kindly note that, you're to replace "at" with shift 2 as the brainly text editor can't take the symbol
Explanation:
import java.awt.event.*;
import java.awt.geom.Area;
import javax.swing.*;
class MVCTester implements ActionListener{
JButton b; //button
JTextField t1; //textfiled
JTextArea area; //text area
MVCTester(){
JFrame f=new JFrame("Button Example");
//button
b=new JButton("add");
b.setBounds(0,0,125,27);
f.add(b);
b.addActionListener(this);
//textfiled
t1=new JTextField();
t1.setBounds(0,161,125,24);
f.add(t1);
//textarea
area=new JTextArea();
area.setBounds(0,28,123,130);
f.add(area);
area.setColumns (17);
area.setLineWrap (true);
area.setWrapStyleWord (false);
f.setSize(125,225);
f.setLayout(null);
f.setVisible(true);
}
"at"Override
public void actionPerformed(ActionEvent arg0) {
Control c=new Control(area,t1,b);
}
}
class Control {
Control(JTextArea area,JTextField t1,JButton b){
//simple logic getting text of text area adding text of textfiled and setting the text to text area
area.setText(area.getText()+t1.getText()+"\n");
t1.setText("");
}
}
public class Modal{
public static void main(String[] args) {
MVCTester be=new MVCTester();
}
}
Answer:
import java.awt.event.*;
import java.awt.geom.Area;
import javax.swing.*;
class MVCTester implements ActionListener{
JButton b; //button
JTextField t1; //textfiled
JTextArea area; //text area
MVCTester(){
JFrame f=new JFrame("Button Example");
//button
b=new JButton("add");
b.setBounds(0,0,125,27);
f.add(b);
b.addActionListener(this);
//textfiled
t1=new JTextField();
t1.setBounds(0,161,125,24);
f.add(t1);
//textarea
area=new JTextArea();
area.setBounds(0,28,123,130);
f.add(area);
area.setColumns (17);
area.setLineWrap (true);
area.setWrapStyleWord (false);
f.setSize(125,225);
f.setLayout(null);
f.setVisible(true);
}
atOverride (use the at symbol in your code)
public void actionPerformed(ActionEvent arg0) {
Control c=new Control(area,t1,b);
}
}
class Control {
Control(JTextArea area,JTextField t1,JButton b){
//simple logic getting text of text area adding text of textfiled and setting the text to text area
area.setText(area.getText()+t1.getText()+"\n");
t1.setText("");
}
}
public class Modal{
public static void main(String[] args) {
MVCTester be=new MVCTester();
}
}
Explanation:
This is a MVCTester.java. program. In this program, we started with the initial screen that displays a button labeled "add", a blank text area, and a text field. A user places a line in the text field and clicks on the add button. Then, the text area displays the line.
The program follows the MVC model. Also Listeners are implemented in an anonymous class. Its Model is a separate class from the client (test) program.
After implementing the function, the executed program performed optimally by producing the required output.