Question: Java Lab Tracking Buttons Deliverables Updated files for app6.java, myJFrame6.java, myJPanel6.java, student.java Create a solution that tracks the use of the button #1 (students name)
Java Lab Tracking Buttons Deliverables Updated files for app6.java, myJFrame6.java, myJPanel6.java, student.java
Create a solution that tracks the use of the button #1 (students name) Every time a user clicks on the first button (the button with the students name), you show a different whatsUp. do it in 2 parts
Part1.just show the whats up as a text
Part2.then show it graphically with a different picture for each whatsUp( ) result.
public class app6 {
public static void main(String args[]) {
myJFrame6 mjf = new myJFrame6();
}
}
import java.awt.*;
import javax.swing.*;
public class myJButton extends JButton {
public myJButton(String text) {
super(text);
setBackground(Color.red); setOpaque(true);
}
}
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();
//------------------------------------------------------
// Choose a Layout for JFrame and
// add Jpanel to JFrame according to layout getContentPane().setLayout(new BorderLayout()); getContentPane().add(p6, "Center");
//------------------------------------------------------
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize (550, 400); setVisible(true);
}
//-------------------------------------------------------------------
}
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class myJPanel6 extends JPanel implements ActionListener {
myJButton b1,b2;
public myJPanel6() {
setLayout(new GridLayout(1,1));
//=====================================
student st1 = new student("Michael", "Robinson", 20);
//=====================================
b1 = new myJButton(st1.getName());
add(b1);
//=====================================
b2 = new myJButton(st1.WhatIsUp());
add(b2);
}
public void actionPerformed(ActionEvent event) {
Object obj = event.getSource();
//=====================================
if (obj == b1){
b2.setText("-"+b1.getText()+"- was clicked");
}
}
}
class student {
//---------Declaring attributes----
String firstName;
String lastName;
int age;
String status;
//------------------------------
//----------Constrcutor------------
public student(String a, String b, int c) {
firstName = a;
lastName = b;
age = c;
if(age<=25) status = "Traditional";
else status = "Non-Traditional";
}
//---------------------------------
//---------- METHODS --------
String getName() {
return("NAME = "+firstName+ " "+lastName + ", Age = "+age+", Status = "+status);
}
int getAge() {
return age;
}
String getStatus() {
return status;
}
String WhatIsUp() {
String b = "dunno";
double r = Math.random();
int myNumber = (int)(r*3f);
if (myNumber == 0) b = "reading";
if (myNumber == 1) b = "talking";
if (myNumber == 2) b = "interacting";
return b;
}
//--------------------------------------------
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
