Question: Deliverables app.java myJFrame.java myJPanel.java myJPanel1.java myJPanel2.java student.java. Contents Use this Netbeans project to get started: Communication_Starter.zip public class app { public static void main(String args[])
Deliverables
app.java myJFrame.java myJPanel.java myJPanel1.java myJPanel2.java student.java.
Contents
Use this Netbeans project to get started: Communication_Starter.zip
public class app {
public static void main(String args[]) { myJFrame mjf = new myJFrame(); } }
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); }
}
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"); }
}
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); }
}
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); }
}
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; }
}
It is a follow-up of the assignment from the previous assignment. Some of the requirements are the same:
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.
The ActionListener has to be implemented in 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)
As you might have guessed by now, one of the new things here is that you will have to implement in the second panel a listener for a button in the first panel.
myJPanel Student's myJPanel1 ame e, myJPanel2 Student's whatsUp( Student created hereStep by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
