Question

Deliverables
app.java, myJFrame.java, myJPanel.java and student.java as requested below.


(Use the student.java class that you already have from previous labs)

Contents
Based on the graphics you learned this week

Create an instance (an object, i.e., st1) of student in myJPanel
Display his/her basic information
Display for 10 times what he/she is up to (using the method whatIsUp() that your student class already has)

My First Frame NAME - Fred Fonseca Age-44 L NAME= Fred Fonseca Age=44 Listening to endless lecture doing Javadoing Java searching the web doing Java doing Java doing Java searching the web doing Java doing Java doing Javasearching the web doing Java searching the web istening to endless lectureListening to endless lecture Listening to endless lecture Listening to endless lecture doing Java doing Java

--------------------------------------------------------------------------------------------------

\\app.java
public class app
{
public static void main(String args[])
{
myJFrame mjf = new myJFrame();
}
}

-----------------------------------------------------------------------------

\\myJFrame.java
import java.awt.*;
import javax.swing.*;
import static javax.swing.JFrame.EXIT_ON_CLOSE;
public class myJFrame extends JFrame
{
public myJFrame ()
{
super ("My First Frame");
myJPanel mjp = new myJPanel();
getContentPane().add(mjp,"Center");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize (800, 480);
setVisible(true);

}
}

-------------------------------------------------------------------------------

\\myJPanel.java
import java.awt.*;
import javax.swing.*;
public class myJPanel extends JPanel
{
public myJPanel ()
{
super ();
GridLayout grid = new GridLayout(1,1);
setLayout(grid);
setBackground(Color.green);
PanelLeft left = new PanelLeft();
PanelRight right = new PanelRight();
add(left);
add(right);
//BorderLayout border = new BorderLayout();
//setLayout(border);
//setBackground(Color.pink);
//JButton jb1 = new JButton("Hello");
//jb1.setBackground(Color.WHITE);
//JButton jb2 = new JButton(" Goodbye");
//jb2.setBackground(Color.yellow);
//JButton jb3 = new JButton("I am a JButton");
//jb3.setBackground(Color.CYAN);
//add(jb1,"North");
//add(jb2,"Center");
//add(jb3,"South");
}
}

--------------------------------------------------------------------------------

\\student.java

//student is a person with a status ("traditional" or "non-traditional")
//Displays all the info (and "status" reusing class person) about them in the most efficient way possible (avoid unnecessary duplication)
class student extends person
{
   String status;
  
   public student(String informedFirstName, String informedLastName, int informedAge)
   {
       super(informedFirstName, informedLastName, informedAge);
       if (age <= 25) status = "Traditional";
       else status = "Non-Traditional";
   }
  
   public String whatIsUp()
   {
   int n = 0;
   String b = "...";
   n = (int) (Math.random()*2);
   if (n == 0) b = "reading";
   if (n == 1) b = "talking";
   return b;
   }
   String getStatus()
   {
       return status;
   }
   //void display()
//{
public String getInfo()
{
return super.getInfo()+"\nStatus: "+getStatus()+"\nState: "+whatIsUp();
}
//System.out.println("---------------------");
//System.out.println("Student Information");
//System.out.println(getInfo()+ "Status: " + getStatus());
//System.out.println();
//}
}

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

//app.java
public class app
{
   public static void main(String args[])
   {
      
       //Instantiate the myJFrame
       myJFrame mjf = new myJFrame();
   }
}

----------------------------------------------------------------------------------------

//myJFrame.java
import java.awt.*;

import javax.swing.*;
public class myJFrame extends JFrame
{
  
   //Declare panel variable
   private JPanel studentPanel;
   //set width and height of the frame
   private final int APPLICATION_WIDTH=450;
   private final int APPLICATION_HEIGHT=350;
  
   private static JButton name=new JButton();
  
  
   public myJFrame ()
   {
       super ("My First Frame");
       //Call the method createStudentPanel that adds the student info
       //to the panel add to the frame
       createStudentPanel();
       setDefaultCloseOperation(EXIT_ON_CLOSE);
       setSize(APPLICATION_WIDTH, APPLICATION_HEIGHT);
       setVisible(true);

   }
  
   public void createStudentPanel()
   {  
       //Create myJPanel
       studentPanel = new myJPanel();
       //Create an instance of student class      
       student std1=new student("Fred","Fonseca", 45);
       //set layout flow layout
       studentPanel.setLayout(new FlowLayout());
       //create a JButton for name and age
       JButton nameage=new JButton(std1.getNameAge());
       //add name and age
       studentPanel.add(nameage);
       //call getinfo on std1 object and add
       //the name info to the studentPanel 10 times
       for (int index = 0; index < 10; index++)
       {                      
           JButton status=new JButton(std1.whatIsUp());
           studentPanel.add(status);
          
          
       }
       //add student panel to the frame
       add(studentPanel);  
   }
  
  
}

------------------------------------------------------------------------------------------------

//myJPanel.java
import java.awt.*;
import javax.swing.*;
public class myJPanel extends JPanel
{
   public myJPanel ()
   {
       super ();
       GridLayout grid = new GridLayout(1,1);
       setLayout(grid);
       setBackground(Color.pink);
      
      
      
   }
}
----------------------------------------------------------------------
//student.java

//student is a person with a status ("traditional" or "non-traditional")
//Displays all the info (and "status" reusing class person) about them in the most efficient way possible (avoid unnecessary duplication)
class student extends person
{
   String status;

   public student(String informedFirstName, String informedLastName, int informedAge)
   {
       super(informedFirstName, informedLastName,informedAge);
       if (informedAge <= 25)
           status = "Traditional";
       else
           status = "Non-Traditional";
   }

   public String whatIsUp()
   {
       int n = 0;
       String b = "...";

//create three random whatisup options
       n = (int) (Math.random()*3);
       if (n == 0) b = "Listening to endless lecture";
       if (n == 1) b = "doing java";
       if (n == 2) b = "Searching the web";
      

       return b;
   }
   String getStatus()
   {
       return status;
   }
  
   public String getInfo()
   {
       return super.getInfo()+"\nStatus: "+getStatus()+"\nState: "+whatIsUp();
   }
  
   public String getNameAge()
   {
       return super.getInfo();
   }
  
  
}
----------------------------------------------------------------------------------------------------


//Create a person class with first name and last name
public class person
{
   private String informedFirstName;
   private String informedLastName;
   private int informedAge;

   //constructor that sets the first name and last name
   public person(String informedFirstName, String informedLastName,int informedAge)
   {
       this.informedFirstName=informedFirstName;
       this.informedLastName=informedLastName;
       this.informedAge=informedAge;
   }
  
   //Returns the name of the person
   public String getInfo()
   {
       return "Name = "+informedFirstName+" "+informedLastName+"Age ="+informedAge;
   }
  
  
}

------------------------------------------------------------------------------------

Sample output:

My First Frame Name Fred FonsecaAge 5ching the web Listening to endless lecture doing java Listening to endless lecture Searc

Hope this helps you

Add a comment
Know the answer?
Add Answer to:
Deliverables app.java, myJFrame.java, myJPanel.java and student.java as requested below. (Use the student.java class that you already...
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
  • Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with...

    Basic button tracking Deliverables Updated files for app6.java myJFrame6.java myJPanel6.java student.java Contents You can start with the files available here. public class app6 { public static void main(String args[]) {     myJFrame6 mjf = new myJFrame6(); } } import java.awt.*; import javax.swing.*; import java.awt.event.*; public class myJFrame6 extends JFrame {    myJPanel6 p6;    public myJFrame6 ()    {        super ("My First Frame"); //------------------------------------------------------ // Create components: Jpanel, JLabel and JTextField        p6 = new myJPanel6(); //------------------------------------------------------...

  • Any thoughts on this, i can get it to run but can't pass code around and...

    Any thoughts on this, i can get it to run but can't pass code around and the button doesnt move around. i didnt pass the student, or the app.java. What will you learn Combined use of Timer and the tracking of user interactions Deliverables app.java myJFrame.java myJPanel.java and other necessary Java files Contents The objective of the lab is to create a game in which the player has to click on a moving student-button to score. The student button has...

  • **Using NetBeans** Lesson Using inheritance to reuse classes. Deliverables person.java student.java studentAthlete.java app.java Using inheritance and...

    **Using NetBeans** Lesson Using inheritance to reuse classes. Deliverables person.java student.java studentAthlete.java app.java Using inheritance and the classes (below) The person class has first name last name age hometown a method called getInfo() that returns all attributes from person as a String The student class is a person with an id and a major and a GPA student has to call super passing the parameters for the super class constructor a method called getInfo() that returns all attributes from student...

  • The method m() of class B overrides the m() method of class A, true or false?...

    The method m() of class B overrides the m() method of class A, true or false? class A int i; public void maint i) { this.is } } class B extends A{ public void m(Strings) { 1 Select one: True False For the following code, which statement is correct? public class Test { public static void main(String[] args) { Object al = new AC: Object a2 = new Object(); System.out.println(al); System.out.println(a): } } class A intx @Override public String toString()...

  • JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** *...

    JAVA 3files seprate 1.Classroom.java 2.ClassroomTester.java (provided) 3.Student.java(provided) Use the following files: ClassroomTester.java import java.util.ArrayList; /** * Write a description of class UniversityTester here. * * @author (your name) * @version (a version number or a date) */ public class ClassroomTester { public static void main(String[] args) { ArrayList<Double> grades1 = new ArrayList<>(); grades1.add(82.0); grades1.add(91.5); grades1.add(85.0); Student student1 = new Student("Srivani", grades1); ArrayList<Double> grades2 = new ArrayList<>(); grades2.add(95.0); grades2.add(87.0); grades2.add(99.0); grades2.add(100.0); Student student2 = new Student("Carlos", grades2); ArrayList<Double> grades3 = new...

  • How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java...

    How do I start this Java: Inheritance problem? • person.java • student.java • studentAthlete.java • app.java • Students should apply consistent indenting in all submissions. This can be done via the NetBeans Source menu. Contents person First name Last name app Creates 1 student-athlete object Hometown Retinfo) 1-Displays the complete information about the student-athlete object student New attributes Maior attributes getinfo) method from the superlas person Student-athlete student's rankine Overrides the method from the superclass student Video from Professor Fisher...

  • Given a class called Student and a class called Course that contains an ArrayList of Student....

    Given a class called Student and a class called Course that contains an ArrayList of Student. Write a method called getDeansList() as described below. Refer to Student.java below to learn what methods are available. I will paste both of the simple .JAVA codes below COURSE.JAVA import java.util.*; import java.io.*; /****************************************************** * A list of students in a course *****************************************************/ public class Course{     /** collection of Students */     private ArrayList<Student> roster; /***************************************************** Constructor for objects of class Course *****************************************************/...

  • 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 currently a functional Java progam with a gui. Its a simple table of contacts...

    I have currently a functional Java progam with a gui. Its a simple table of contacts with 3 buttons: add, remove, and edit. Right now the buttons are in the program but they do not work yet. I need the buttons to actually be able to add, remove, or edit things on the table. Thanks so much. Here is the working code so far: //PersonTableModel.java import java.util.List; import javax.swing.table.AbstractTableModel; public class PersonTableModel extends AbstractTableModel {     private static final int...

  • java This lab is intended to give you practice creating a class with a constructor method,...

    java This lab is intended to give you practice creating a class with a constructor method, accessor methods, mutator methods, equals method , toString method and a equals method. In this lab you need to create two separate classes, one Student class and other Lab10 class. You need to define your instance variables, accessor methods, mutator methods, constructor, toString method and equals method in Student class. You need to create objects in Lab10 class which will have your main method...

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