Suppose to pull up 3 different windows with different Labels and Strings in the frames. Below is a picture of the projected output
I have three classes.
- P1Panel that extends JPanel
- P1Frame that extends JFrame
P1Driver used for main
----------------------------------------------------------P1Panel class below:
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class P1Panel extends JPanel { private String s0; public P1Panel(String s0){ { add(new P1Panel(s0)); } } }
---------------------------------------------This is P1Frame class below:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class P1Frame extends JFrame
{
private String s1;
public P1Frame (String s1){
this.s1 = s1;
{
add(new P1Panel(s1));
}
P1Frame p1 = new P1Frame(s1);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p1.setSize(300,200);
p1.setVisible(true);
}
}
----------------------------------------This is P1Driver class:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class P1Driver
{
public static void main(String [] args)
{
P1Frame p1 = new P1Frame("This is window 1");
//JFrame f2 = new JFrame("This is window 2");
//JFrame f3 = new JFrame("This is window 3");
p1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
p1.setSize(300,200);
p1.setVisible(true);
}
}
I believe my P1Panel class is correct in that I called a constructor and added it to itself. The text in my label is passing the P1Panel constructor as a parameter
My P1Frame class I am having difficult with. In the constructor I am wanting to make a P1Panel object and add it to the P1Frame. I think I need to pass a string into the P1Frame constructor as a parameter and then pass string to P1Panel?
I believe my Driver class is correct too as I am just putting main here and setting items size and visibility.
I believe my fix is a small one, but I am stuck and unsure in how to do so. When I run the program as is, it runs infinite with nothing popping up.