Sorry for beeing a little confused. I try to solve problems by myself
and have to learn about the conventions of writing posts.
My main problem is to learn how to manage this: i have many classes and
all of them should be able to use the methods of every other class,
without get recursive.
I checked the net, but I couldn't find the any solution. No problem with
2 classes..but with more i get confused...sorry.
Here is the Code:
<sscce>
public class Go
{
public static void main(String[] args)
{
new Gui_Start();
}
}
public class Gui_Start extends JFrame
{
HIS_Go theGo;
Control theControl;
Gui_Login theLogin;
Gui_Start(Control control)
{
this.theControl = control;
}
Gui_Start(Gui_Login guiLogin)
{
this.theLogin = guiLogin;
}
Gui_Start()
{
if(this.isShowing())
{
this.dispose();
}
else
{
initComponents();
this.setVisible(true);
}
}
private int buttonActive = 0;
private void setButtonActive(int i)
{
this.buttonActive = i;
}
public int getButtonActive()
{
return this.buttonActive;
}
private void button_personalActionPerformed(ActionEvent e){
setButtonActive(1);
new Gui_Login(this);
}
private void button_stationActionPerformed(ActionEvent e){
setButtonActive(2);
new Gui_Login(this);
}
private void initComponents()
{//gui_stuff
}
}
public class Gui_Login extends JFrame
{
Gui_Start guiStart;
Gui_Login(Gui_Start guiStart)
{
if(this.isShowing())
{
this.dispose();
}
else
{
initComponents();
this.setVisible(true);
}
}
private boolean checkIs = false;
private final String loginName = "super";
private final String loginPass = "super";
private String inputLoginName = null;
private String inputLoginPass = null;
private void loginCheck()
{
inputLoginName = getField_login().getText().toString();
inputLoginPass = getField_password().getText().toString();
if(inputLoginName.equals(loginName) &&
inputLoginPass.equals(loginPass))
{
this.checkIs = true;
int buttonActive = guiStart.getButtonActive(); //here i get the problem
switch(buttonActive)
{
case 1: new Gui_Personal(this); //if i make buttonActive in Gui_Start
static, i dont get any exceptions, but the gui_personal will not open
Gui_Personal-Fenster geht nicht auf.
break;
case 2: new Gui_Station(this);//same as case 1
break;
}
}
else
{
JOptionPane.showMessageDialog(null, "Wrong login!", "Login failure",
JOptionPane.ERROR_MESSAGE);
}
}
private void okButtonActionPerformed(ActionEvent e)
{
new Gui_Start(this);
loginCheck();
}
private void cancelButtonActionPerformed(ActionEvent e) {
// TODO add your code here
}
public JTextField getField_login()
{
return this.field_login;
}
public JPasswordField getField_password()
{
return this.field_password;
}
private void initComponents()
{//guiStuff
}
}
public class Gui_Station extends JFrame
{
Gui_Station (Gui_Login guiLogin)
{
initComponents();
this.setVisible(true);
}
private void initComponents()
{//Gui-Stuff
}
</sscce>
Luca S.
Andrew said:
Please refrain from top-posting. I find it most confusing.
Your complete code tells the story. But first, I
will repost your code as an SSCCE*. An SSCCE
is a form of the code inteded to be a (short) self-contained,
compilable example of the problem.
Your code fulfilled most of that description, but
an extra tip is to rework it so it is all in 'one Java file'**
which can be achieved by demoting classes with no
'main()' from 'public' to '' (default/package).
** This is not good for 'real' code, but we are just
trying to sort a basic problem - so it is fine.
Here is what I mean..
<sscce>
public class Start {
public static void main(String[] args)
{
new Control();
}
}
class Control
{
// GOTO create model
Model theModel= new Model();
public Control()
{
System.out.print("Control-Constructor run");
}
}
class Model
{
// GOTO create control
Control theControl= new Control();
}
</sscce>
I put some comments in that code, to indicate why it
is failing, but here is a version that (to the best of my
current understanding of the code - which is 'not much')
does what you are attempting to achieve (without the
recursive element!).
<sscce>
public class StartOnce {
public static void main(String[] args)
{
new Control();
}
}
class Control
{
// Declare model
Model theModel;
public Control()
{
// hand the model a reference to this Control
theModel = new Model(this);
System.out.println("Control-Constructor run");
}
}
class Model
{
// Declare control
Control theControl;
Model(Control control) {
// associate the Control with our Model
theControl = control;
}
}
</sscce>
Each of control and model have a reference to 'the'
*single* instance of the other.
* The full description of the SSCCE, along with
why it is so handy for both debuggin and code
postings, can be found here.
<
http://www.physci.org/codes/sscce/>
BTW - these are very simple questions, and there is
a group better suited to those learning Java, it is..
comp.lang.java.help
..I highly recommend it.
Andrew T.