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: | Jul 2017 |
| Last Sign in: | 304 Weeks Ago, 2 Days Ago |
| Questions Answered: | 15833 |
| Tutorials Posted: | 15827 |
MBA,PHD, Juris Doctor
Strayer,Devery,Harvard University
Mar-1995 - Mar-2002
Manager Planning
WalMart
Mar-2001 - Feb-2009
there is only one version of a student.
student information is shown in the upper button (in myJPanel1).
when the user clicks on the upper button in myJPanel1, then WhatsUp() is shown in the lower button (in myJPanel2).
The difference here is that you are required to:
do everything the in second panel, myJPanel2.
No changes in myJPanel1.java
Therefore:
You have to change one line (or at most 3 lines) in myJPanel.java (the panel that creates the two other panels)
A lot of changes in myJPanel2.java
NO changes in myJPanel1.java (of course there are changes in myJPanel1 screen, where the button b1 is located)
GIVEN CODE
app.java
Â
public class app
{
public static void main(String args[])
{
myJFrame mjf = new myJFrame();
}
}
myJFrame,java
Â
import java.awt.*;
import javax.swing.*;
public class myJFrame extends JFrame
{
public myJFrame()
{
super("Communication Between Classes - Assignment");
myJPanel mjp = new myJPanel();
add(mjp, "Center");
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(640, 480);
setVisible(true);
}
}
myJPanel.java
Â
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class myJPanel extends JPanel
{
public myJPanel()
{
super();
setBackground(Color.gray);
setLayout(new BorderLayout());
myJPanel1 p1 = new myJPanel1();
myJPanel2 p2 = new myJPanel2();
student st1 = new student("Kerry","Collins",20);
add(p1, "North");
add(p2, "Center");
}
}
myJPanel1.java
Â
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class myJPanel1 extends JPanel
{
JButton b1;
public myJPanel1()
{
super();
setBackground(Color.yellow);
b1 = new JButton("student info will be here later ...");
add(b1);
}
}
myJPanel2.java
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class myJPanel2 extends JPanel
{
JButton b2;
public myJPanel2()
{
super();
setBackground(Color.pink);
b2 = new JButton("whats Up will be shown here");
add(b2);
}
}
student.java
Â
import java.awt.*;
import javax.swing.*;
public class student
{
String firstName;
String lastName;
int age;
public student(String a, String b, int x)
{
super();
firstName = a;
lastName = b;
age = x;
}
String getInfo()
{
return "NAME = " + firstName + " " + lastName + " " + "Age = " + age;
}
String whatsUp()
{
double r = Math.random();
int myNumber = (int) (r * 3f); //comment: a random number between 0 and 2
String answer = "I don't know";
if (myNumber == 0)
{
answer = "searching the web";
}
if (myNumber == 1)
{
answer = "doing Java";
}
if (myNumber == 2)
{
answer = "Listening to endless lecture";
}
return answer;
}
}
----------- Â ----------- H-----------ell-----------o S-----------ir/-----------Mad-----------am ----------- Th-----------ank----------- yo-----------u f-----------or -----------you-----------r i-----------nte-----------res-----------t a-----------nd -----------buy-----------ing----------- my----------- po-----------ste-----------d s-----------olu-----------tio-----------n. -----------Ple-----------ase----------- pi-----------ng -----------me -----------on -----------cha-----------t I----------- am----------- on-----------lin-----------e o-----------r i-----------nbo-----------x m-----------e a----------- me-----------ssa-----------ge -----------I w-----------ill----------- be----------- qu-----------ick-----------ly