Question

In: Computer Science

In Java: 1) Create a new eclipse project. 2) Create a basic SWING window 3) Create...

In Java:

1) Create a new eclipse project.

2) Create a basic SWING window

3) Create a Label Called Name

4) Create a Text Field for entering the name

5) Create a Text Field for entering and email

5) Create a text area to push the results to

6) Create two buttons, one that says submit and the other that says clear.

7) When the user enters their name and email, they should press submit and see the Text area populate with the data they submitted.

8) When the user presses clear it should clear any text from all fields.

Solutions

Expert Solution

Code:

//importing sswing package
import javax.swing.*;
//as we are using event listeners
//we need to import awt.event package
import java.awt.event.*;
//class name is Frame, so the file should be named as Frame.java
class Frame{
   //main method
   public static void main(String[] args) {
       //creating an istance of frame
       JFrame f = new JFrame();
       //a label
       JLabel name = new JLabel("Name: ");
       //seting boundaries
       name.setBounds(50,50,100,30);
       JLabel email = new JLabel("E-mail: ");
       email.setBounds(50,100,100,30);
       //textfield
       JTextField tf = new JTextField();
       JTextField tf2 = new JTextField();
       tf.setBounds(100,50,100,30);
       tf2.setBounds(100,100,100,30);
       //buttons
       JButton b1 = new JButton("Submit");
       JButton b2 = new JButton("Clear");
       b1.setBounds(50,150,100,50);
       b2.setBounds(200,150,100,50);
       //textArea
       JTextArea ta = new JTextArea();
       ta.setBounds(50,250,300,100);
       //adding all the components to the frame
       f.add(name);
       f.add(email);
       f.add(tf);
       f.add(tf2);
       f.add(b1);
       f.add(b2);
       f.add(ta);
       //setting action listeners for buttons
       //submit
       b1.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               //collecting textfrom textfields
               String s1 = tf.getText();
               String s2 = tf2.getText();
               //putting it in text Area
               ta.setText("Name: "+s1+"\nE-mail: "+s2);
           }
       });
       //clear
       b2.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent e){
               //setting all the fields to empty
               ta.setText("");
               tf.setText("");
               tf2.setText("");
           }
       });

       f.setSize(500,500);
       f.setLayout(null);
       f.setVisible(true);


   }
  
}

Output:

When clicked submit:

When clicked clear:

Code Screnshot:

Code Snippet:

//importing sswing package
import javax.swing.*;
//as we are using event listeners
//we need to import awt.event package
import java.awt.event.*;
//class name is Frame, so the file should be named as Frame.java
class Frame{
        //main method
        public static void main(String[] args) {
                //creating an istance of frame
                JFrame f = new JFrame();
                //a label
                JLabel name = new JLabel("Name: ");
                //seting boundaries
                name.setBounds(50,50,100,30);
                JLabel email = new JLabel("E-mail: ");
                email.setBounds(50,100,100,30);
                //textfield
                JTextField tf = new JTextField();
                JTextField tf2 = new JTextField();
                tf.setBounds(100,50,100,30);
                tf2.setBounds(100,100,100,30);
                //buttons
                JButton b1 = new JButton("Submit");
                JButton b2 = new JButton("Clear");
                b1.setBounds(50,150,100,50);
                b2.setBounds(200,150,100,50);
                //textArea
                JTextArea ta = new JTextArea();
                ta.setBounds(50,250,300,100);
                //adding all the components to the frame
                f.add(name);
                f.add(email);
                f.add(tf);
                f.add(tf2);
                f.add(b1);
                f.add(b2);
                f.add(ta);
                //setting action listeners for buttons
                //submit
                b1.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                                //collecting textfrom textfields
                                String s1 = tf.getText();
                                String s2 = tf2.getText();
                                //putting it in text Area
                                ta.setText("Name: "+s1+"\nE-mail: "+s2);
                        }
                });
                //clear
                b2.addActionListener(new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                                //setting all the fields to empty
                                ta.setText("");
                                tf.setText("");
                                tf2.setText("");
                        }
                });

                f.setSize(500,500);
                f.setLayout(null);
                f.setVisible(true);


        }
        
}

Related Solutions

JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes...
JAVA LANGUAGE Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign4. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign4Test.java. Copy your code from Assignment 3 into the Student.java and StudentList.java. Assign4Test.java should contain the main method. In Student.java, add a new private variable of type Integer called graduationYear. In Student.java, create a new public setter method setGraduationYear to set the graduationYear. The method will have one parameter of type Integer. The method will set...
For this coding exercise, you need to create a new Java project in Eclipse and finish...
For this coding exercise, you need to create a new Java project in Eclipse and finish all the coding in Eclipse. Run and debug your Eclipse project to make sure it works. Then you can just copy and paste the java source code of each file from Eclipse into the answer area of the corresponding box below. The boxes will expand once you paste your code into them, so don’t worry about how it looks J All data members are...
Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in...
Required Tasks: In Eclipse, create a Java Project as CS-176L-Assign5. Create 3 Java Classes each in its own file Student.java, StudentList.java, and Assign5Test.java. Copy your code from Assignment 4 into the Student.java and StudentList.java Classes. Assign5Test.java should contain the main method. Modify StudentList.java to use an ArrayList instead of an array. You can find the basics of ArrayList here: https://www.w3schools.com/java/java_arraylist.asp In StudentList.java, create two new public methods: The addStudent method should have one parameter of type Student and should add...
open up a new Java project on Eclipse named Review and create a new class called...
open up a new Java project on Eclipse named Review and create a new class called Review.java. Copy and paste the below starter code into your file: /** * @author * @author * CIS 36B */ //write your two import statements here public class Review {        public static void main(String[] args) { //don't forget IOException         File infile = new File("scores.txt");         //declare scores array         //Use a for or while loop to read in...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week...
Create a new Java Project named “Packages” from within Eclipse. Following the example in the Week 6 lecture, create six packages: Main, add, subtract, multiply, divide, and modulo. ALL of these packages should be within the “src” folder in the Eclipse package Explorer. ALL of the packages should be on the same “level” in the file hierarchy. In the “Main” package, create the “Lab04.java” file and add the needed boilerplate (“Hello, World!” style) code to create the main method for...
JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You...
JAVA LANGUAGE Create a new project named BankAccount in Eclipse. Then, implement the following requirements. You need to create two classes, one for BankAccount (BankAccount.java) and the other for the tester (BankAccountTest.java). Make sure your program compile without errors before submitting. Submit .java files to eCampus by the end of next Thursday, 10/15/2020. Part 1: Create the BankAccount class (template is attached after the project description) in the project. You must add the following to the BankAccount class: An instance...
Using eclipse IDE, create a java project and call it applets. Create a package and call...
Using eclipse IDE, create a java project and call it applets. Create a package and call it multimedia. Download an image and save it in package folder. In the package, create a java applet where you load the image. Use the drawImage() method to display the image, scaled to different sizes. Create animation in Java using the image. In the same package folder, download a sound. Include the sound in your applets and make it repeated while the applet executes....
1. Create a new Java project called L2 and a class named L2 2. Create a...
1. Create a new Java project called L2 and a class named L2 2. Create a second class called ArrayExaminer. 3. In the ArrayExaminer class declare the following instance variables: a. String named textFileName b. Array of 20 integers named numArray (Only do the 1st half of the declaration here: int [] numArray; ) c. Integer variable named largest d. Integer value named largestIndex 4. Add the following methods to this class: a. A constructor with one String parameter that...
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java,...
GETTING STARTED Create an Eclipse Java project containing package “bubble”. Import the 3 starter files BubbleSorter.java, BubbleSortTestCaseMaker.java, and Statistician.java. PART 1: Implementing BubbleSorter Implement a very simple BubbleSorter class that records how many array visits and how many swaps are performed. Look at the starter file before reading on. This class has an instance variable called “a”. Its type is int[]. This is the array that will be bubble-sorted in place. Usually a single letter is a bad variable name,...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT