Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Click button is not function  RSS feed

 
Anne Saizan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello I really need help.
When I click the button, it don't point to other windows.

Below is what I have done so far.
Really appreciate if you guys can help me.


 
Stephan van Hulst
Saloon Keeper
Posts: 6980
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anne,

Instead using one big action listener to handle all buttons, it's much better to use a separate listener for each button. Here's how you can do it:
 
Anne Saizan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I wouldn't work as I want. what should i do to make it popup when i click student Admin.
please really need your help.
thanks
 
Stephan van Hulst
Saloon Keeper
Posts: 6980
110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use an ActionListener as I described above, and use one of the show...Dialog() methods in JOptionPane.

Try it out for yourself, and if you're running into problems, post your code here and we'll try to help you out.
 
Anne Saizan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks I will =)
Really appreciate it...
 
Rob Camick
Ranch Hand
Posts: 2754
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Separate ActionListeners are the way to go. However you do have a problem with your posted code:

private JButton button2 = new JButton("Course Admin\n");
private JButton button3 = new JButton("Staff Admin\n");


You don't want the "\n" as part of the button text. When you text the command in your ActionListener you will never get a match.
 
Anne Saizan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can i do more than three buttosn by using showOptionDialog.
because when i click Student Admin, it will show another 4 button. then the user will click on the button.

Is it possible to do that? I don't think JOptionPane can.

do you have any suggestion?
Thanks
 
Anne Saizan
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for that Rob.
 
Rob Camick
Ranch Hand
Posts: 2754
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JOptionPane can do many things. You can add any component to it that you want and you can create as many buttons as your want.

Read the section from the Swing tutorial on How to Make Dialogs for some examples.

Or you can create custom dialogs, whichever you find easier.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!