hello every body
this is part of my datastructure project//i used java lang.

i have a problem in using GUI,
see :

JButton button3 = new JButton("Sub Users Access: Students & Teachers");   
    button3.addActionListener(new ActionListener()
 {
public void actionPerformed(ActionEvent e)
      {
           String Option2 = JOptionPane.showInputDialog(null, "\n1-Show list of bookes\n2-Search book\n3-Exit\n\nEnter a number of service", "Sub-Users Options", JOptionPane.INFORMATION_MESSAGE);
           int ConvOption2 = Integer.parseInt(Option2);
           theUser.SubUser(ConvOption2,Option2);//go to SubUser method 
      }//end method public void actionListener      
      });//end button3

Q1: is it right that i call SubUser method of class users by theUser object< inside a button method.>
//the code gave me no error & it is run but the task of the method not work
//no action & it just hanging when reach to any task
//i had already checked the method alone befor >>> its work .

Q2: i want to pass the variables inside a button( ConvOption2,Option2)
so is there any way to calling out the putton and can pass these variable?
//pleazzzzzzzzzzze if any one have an idea about this>>> i wait for a help

*** e.g.: when user chosse 2 to search about book>>>hang & nothing appear

thanks all.
All ideas are welcome.

Recommended Answers

All 10 Replies

It depends on what the SubUser (subUser using standard naming conventions) does.
If it doesn't do any Swing GUI things or run too long, it should be OK.
What does the subUser method do?

Thanks a lot NormR1 :)

This is the method of SubUser:
its inside a class: Users
all variables are initilized before

my question was about the way>> is it right?!>>(that I call method inside method(... .method()...);
?!

public void SubUser(int ConvOption2,String Option2)
{
while(ConvOption2!=3)
      {
     switch (ConvOption2)
       {
      case 1:{
              theList.displayList();// theList is defined as an object of class LinkList
              System.out.println("---------------------------------------------------------------------------\n");
             }
      break;
      case 2:{
             System.out.println("Enter Book Number:");
             key = input.nextInt();
             f = theList.find(key);          // find item
             if( f != null)
             {         
             theList.displayState(f);
             }
             else
             System.out.println("Can't find The book");
             System.out.println("---------------------------------------------------------------------------\n");
             }
      break;
        }//end switch
   Option2 = JOptionPane.showInputDialog(null, "\n1-Show list of bookes\n2-Search book\n3-Exit\n\nEnter a number of service", "Sub-Users Options", JOptionPane.INFORMATION_MESSAGE);
   ConvOption2 = Integer.parseInt(Option2);
   }//end while
}//end SubUser method

waiting for UR replying.
Tanks again

What do you mean by "is right"?
Does it compile ok?
Does it execute OK?
What is printed out when you execute it?

Your mixing console I/O (input.nextInt()) with GUI can be a problem.
How are you executing the program? Command prompt Console or IDE

i have 4 classes :
1- Main (interface photo date-buttones-)>>> GUI all
2- Users (has 3 method :Users-mainUsers-SubUsers)>>> this is not in the frame of class Main / it's performs all taskes >>> in IDE while frame window open so i ca back to buttons.
3- Linklist class(which have insert,delete,find,state...methodes)
4- class Link.

my system start work from Main
.......................................
Does it compile ok? yes
Does it execute OK? no the problem faced when the user choose 1 or 2 or 3 from th options "

String Option2 = JOptionPane.showInputDialog(null, "\n1-Show list of bookes\n2-Search book\n3-Exit\n\nEnter a number of service", "Sub-Users Options", JOptionPane.INFORMATION_MESSAGE);           int ConvOption2 = Integer.parseInt(Option2);           theUser.SubUser(ConvOption2,Option2)

"
>>>here program supose to go to SubUser method and let say the user choose 2 : search
it go and user can enter choice but nothing done after that

case 2:{             System.out.println("Enter Book Number:");             key = input.nextInt();             f = theList.find(key);          // find item             if( f != null)             {                      theList.displayState(f);             }             else             System.out.println("Can't find The book");             System.out.println("---------------------------------------------------------------------------\n");             }      break;

>>here program hang and not dispaly the required jop.


Thanx alot
pleaze help me,

here program hang

Do you know which statement the program hangs on?
Add lots of println statements to find which statement the program hangs on.
Copy all of the console contents here.

How are you executing the program? Command prompt Console or IDE?

I didn't study all the code, but I get a strong smell of a Swing EDT thread problem here - trying to execute user interactions while still inside a Swing event handler?
Sorry, no time to go any further into this now,
J

NormR1\
i did not understand UR question :(
>>I use blueJ

J\
Swing EDT thread problem ?!!!
at the first i had already tried putting all SubUser tasks here

button3.addActionListener(new ActionListener()
 {
public void actionPerformed(ActionEvent e) 
     {   
        String Option2 = JOptionPane.showInputDialog(null, "\n1-Show list of bookes\n2-Search book\n3-Exit\n\nEnter a number of service", "Sub-Users Options", JOptionPane.INFORMATION_MESSAGE);   
        int ConvOption2 = Integer.parseInt(Option2);   
        //was here all subUser task//
   }//end method public void actionListener       
     });//end button3

rather than make it in seperate class and call its as method<<<this was before>>and it was not work >>error when compile
so i create a class Users
---
pleaze keep helping if you can
i get confused.

what can i do to help you got a clear concept of my problem
//its my first time i share a disscution here!
can i provide you with picture of my program //if yes how?

Thanks again

Add lots of println statements to find which statement the program hangs on.

Look at the output in the console to see the last thing printed.

input.nextInt();

What class is the input object? Is it Scanner?

You should NOT mix GUI and console input in a program.
Use the JOptionPane class to prompt a user and get a response in a GUI program.

You should NOT mix GUI and console input in a program.<<<< That is !
i made class Users by GUI and i put it into the Main
it works and every thing ok

Thanks NormR1
thanks
thanks alot

You're very welcome.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.