The following four classes are an attempt to set up three different JFrames and switch between them. The three frames are: MainView, DetailView, and FormView. The main class is MultipleFramesExample. The four source codes constitute a NetBeans project with a package called FrameViews. MainView, DetailView, and FormView are essentially identical source codes, each containing a JButton. When a button in one of the views is clicked, you are to be taken to another view.
When I try to Run the project, the last line of each source code creates a compile error, "Cannot find variable". Can anyone tell me how to correct the following four source codes?
package FrameViews;
import java.awt.*;
import javax.swing.*;
public class MultipleFramesExample extends JFrame {
public MultipleFramesExample() {
}
public void main(String[] args) {
mV.createMainView();
}
}
_______________________________________
package FrameViews;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class MainView extends JFrame implements ActionListener {
MainView MV = new MainView();
public void createMainView() {
JFrame frame1 = new JFrame();
frame1.setTitle("Main View");
frame1.setSize(50,50);
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame1.setVisible(true);
JButton button1 = new JButton("Click for Detail View");
frame1.getContentPane().add(button1);
button1.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
dV.createDetailView();
}
}
__________________________________________
package FrameViews;
import java.awt.event.*;
import javax.swing.*;
public class DetailView extends JFrame implements ActionListener {
DetailView dV = new DetailView();
public void createDetailView() {
JFrame frame2 = new JFrame();
frame2.setTitle("Detail View");
frame2.setSize(100,100);
frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame2.setVisible(true);
JButton button2 = new JButton("Click for Form View");
frame2.getContentPane().add(button2);
button2.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
fV.createFormView();
}
}
____________________________________________
package FrameViews;
import java.awt.event.*;
import javax.swing.*;
public class FormView extends JFrame implements ActionListener {
FormView fV = new FormView();
public void createFormView() {
JFrame frame3 = new JFrame();
frame3.setTitle("Form View");
frame3.setSize(75,75);
frame3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame3.setVisible(true);
JButton button3 = new JButton("Click for Main View");
frame3.getContentPane().add(button3);
button3.addActionListener(this);
}
public void actionPerformed(ActionEvent event) {
mV.createMainView();
}
}
_______________________________________
Thank you,
J.D. Seader