Hi Everyone,
I have a question concerning the scope of a number of Listener methods. The following code snippet describes what I want to achieve(please see comments in each actionPerformed method). Unfortunately I have know idea of how to make my comments a reality in Java code terms. Any help will be greatly appreciated.
import java.awt.*;
import java.swing.*;
import java.event.*;
public class Untitled1 {
public static void main(String[] args) {
GUIV1 x = new GUIV1();
GUIV2 x = new GUIV2();
}
}
class GUIV1 extends JFrame implements ActionListener{
JButton btn1 = new JButton("Forward"
JLabel lbl1 = new JLabel("Default JFrame"
GUIV1()
{
Container Con = getContentPane();
Con.setLayout(null);
Con.add(btn1);
Con.add(lbl1);
btn1.setBounds(200,200,70,70);
lbl1.setBounds(100,50,100,100);
setSize(450,450);
setLocation(20,20);
setTitle("Default Frame"
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
/* GUIV1 is setVisible(true) by default, so that this is the first screen the user
sees. The one ActionEvent that is triggered by button 1 on GUIV1 should
result in GUIV1 being made invisible, setVisible(false). Also GUIV2 should
be made visible, so that the user now sees this programs second screen.
*/
}
}
class GUIV2 extends JFrame implements ActionListener{
JButton btn1 = new JButton("Backward"
JLabel lbl2 = new JLabel("User initiated JFrame"
GUIV2()
{
Container Con1 = getContentPane();
Con1.setLayout(null);
Con1.add(btn1);
Con1.add(lbl1);
btn1.setBounds(200,200,70,70);
lbl1.setBounds(100,50,100,100);
setSize(350,350);
setLocation(10,10);
setTitle("User Created Frame"
setVisible(false);
}
public void actionPerformed(ActionEvent e)
{
/* When button 1 of GUIV2 is pressed I would like for GUIV2
to be set invisible, setVisible(false), and GUIV1 should once more be
made visible, setVisible(true).
*/
}
}
I have a question concerning the scope of a number of Listener methods. The following code snippet describes what I want to achieve(please see comments in each actionPerformed method). Unfortunately I have know idea of how to make my comments a reality in Java code terms. Any help will be greatly appreciated.
import java.awt.*;
import java.swing.*;
import java.event.*;
public class Untitled1 {
public static void main(String[] args) {
GUIV1 x = new GUIV1();
GUIV2 x = new GUIV2();
}
}
class GUIV1 extends JFrame implements ActionListener{
JButton btn1 = new JButton("Forward"
JLabel lbl1 = new JLabel("Default JFrame"
GUIV1()
{
Container Con = getContentPane();
Con.setLayout(null);
Con.add(btn1);
Con.add(lbl1);
btn1.setBounds(200,200,70,70);
lbl1.setBounds(100,50,100,100);
setSize(450,450);
setLocation(20,20);
setTitle("Default Frame"
setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
/* GUIV1 is setVisible(true) by default, so that this is the first screen the user
sees. The one ActionEvent that is triggered by button 1 on GUIV1 should
result in GUIV1 being made invisible, setVisible(false). Also GUIV2 should
be made visible, so that the user now sees this programs second screen.
*/
}
}
class GUIV2 extends JFrame implements ActionListener{
JButton btn1 = new JButton("Backward"
JLabel lbl2 = new JLabel("User initiated JFrame"
GUIV2()
{
Container Con1 = getContentPane();
Con1.setLayout(null);
Con1.add(btn1);
Con1.add(lbl1);
btn1.setBounds(200,200,70,70);
lbl1.setBounds(100,50,100,100);
setSize(350,350);
setLocation(10,10);
setTitle("User Created Frame"
setVisible(false);
}
public void actionPerformed(ActionEvent e)
{
/* When button 1 of GUIV2 is pressed I would like for GUIV2
to be set invisible, setVisible(false), and GUIV1 should once more be
made visible, setVisible(true).
*/
}
}