JAVA GUI QUESTION...

J

justineee

I have two classes of GUI named LoginGui and Journalizing... I made
them in GuiGenie.. There is an okButton in the LoginGui and what I
want is when I press that button.. the LoginGui disappears and the
Journalizing GUI appears.. However, I don't have any idea on how to do
it.. Any help please?


Justine.
 
R

RedGrittyBrick

justineee said:
I have two classes of GUI named LoginGui and Journalizing... I made
them in GuiGenie.. There is an okButton in the LoginGui and what I
want is when I press that button.. the LoginGui disappears and the
Journalizing GUI appears.. However, I don't have any idea on how to do
it.. Any help please?

There are two ways to answer.

* How to do it using GUIGenie:
I've no idea, you could ask the author.

* How to do it using a normal editor or IDE:
Add an ActionListener to the JButton,
in that, call loginGui.setVisible(false);
and instantiate Journalizing.
 
J

justineee

* How to do it using a normal editor or IDE:
   Add an ActionListener to the JButton,
   in that, call loginGui.setVisible(false);
   and instantiate Journalizing.


This worked for me except in calling the loginGui.setVisible(false);
Here is my code..

public static void loginFrame()
{
JFrame loginGui = new JFrame ("Log-In");
loginGui.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
loginGui.getContentPane().add (new LoginGuiTwo());
loginGui.pack();
loginGui.setVisible (true);
}

public static void main(String[] args)
{
loginFrame();
}

public void actionPerformed(ActionEvent e)
{
if (e.getSource()==loginButton)
{
loginGui.setVisible(false);
Journalizing j = new Journalizing();
j.journalFrame();
}
}

it says 'cannot find variable loginGui'. Help thanks..
 
K

Knute Johnson

justineee said:
I have two classes of GUI named LoginGui and Journalizing... I made
them in GuiGenie.. There is an okButton in the LoginGui and what I
want is when I press that button.. the LoginGui disappears and the
Journalizing GUI appears.. However, I don't have any idea on how to do
it.. Any help please?


Justine.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class test {

public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
final JFrame f1 = new JFrame("frame1");
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
final JFrame f2 = new JFrame("frame2");
f2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JButton b = new JButton("frame2");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
f1.setVisible(false);
f2.setVisible(true);
}
});
f1.add(b);

b = new JButton("frame1");
b.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
f2.setVisible(false);
f1.setVisible(true);
}
});
f2.add(b);

f1.setSize(400,300);
f2.setSize(400,300);

f1.setVisible(true);
}
});
}
}
 
R

RedGrittyBrick

justineee said:
This worked for me except in calling the loginGui.setVisible(false);
Here is my code..

public static void loginFrame()

private final JFrame loginGui; // see comments below
{
JFrame loginGui = new JFrame ("Log-In");

Promote loginGui from local variable in the constructor to an instance
field.

loginGui = new JFrame ("Log-In");

loginGui.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
loginGui.getContentPane().add (new LoginGuiTwo());
loginGui.pack();
loginGui.setVisible (true);
}

public static void main(String[] args)
{
loginFrame();
}

public void actionPerformed(ActionEvent e)
{
if (e.getSource()==loginButton)
{
loginGui.setVisible(false);

loginGui isn't visible here, it's out of scope.

Journalizing j = new Journalizing();
j.journalFrame();
}
}

it says 'cannot find variable loginGui'. Help thanks..

Variables defined locally in one method (or constructor) are not visible
in another method.
 
R

Roedy Green

However, I don't have any idea on how to do
it.. Any help please?

to make a Frame appear, the first time you need a new Frame. To make
it reappear you need setVisible(true);
--
Roedy Green Canadian Mind Products
http://mindprod.com

"Pollution is nothing but the resources we are not harvesting. We allow them to disperse because we’ve been ignorant of their value."
~ Richard Buckminster (Bucky) Fuller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,678
Members
48,796
Latest member
Greg L.

Latest Threads

Top