The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 3 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
myJbutton
import java.awt.*;
import javax.swing.*;
Â
public class myJButton extends JButton
{
               public myJButton(String text)
               {
                               super(text);
                               setBackground(Color.red);
                               setOpaque(true);
               }
}
My java frame 6
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.*;
Â
myJpanel panel6
Â
public class myJPanel6 extends JPanel
{
               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);
               }
Â
Â
}
Â
Student
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<) 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;
               }
               //--------------------------------------------
}
myJbutton
import java.awt.*;
import javax.swing.*;
Â
public class myJButton extends JButton
{
               public myJButton(String text)
               {
                               super(text);
                               setBackground(Color.red);
                               setOpaque(true);
               }
}
App 6
public class app6
{
 public static void main(String args[])
 {
   myJFrame6 mjf = new myJFrame6();
 }
}
Based on the files available here (Links to an external site.) or on the Angel folder Lab6 (app6.java, myJFrame6.java, myJPanel6.java, student.java)
An example of how to add images to buttons is available here (Links to an external site.).
Â
Create a solution that tracks the use of the button #1 (student’s name)
Every time a user clicks on the first button (the button with the student’s name), you show a different what’sUp.
do it in 2 parts
Just show the what's up as a text
Just show the what's up as a text
Â
myJbutonimport java.awt.*;import javax.swing.*;public class myJBuTon extends JBuTon{public myJBuTon(String text){super(text);setBackground(Color.red);setOpaque(true);}}My java frame 6import 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 J±extFieldp6 = new myJPanel6();//------------------------------------------------------// Choose a Layout for JFrame and
Attachments:
-----------