Passing control

Thread Solved

Join Date: Dec 2004
Posts: 4,176
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 479
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Passing control

 
0
  #1
Feb 17th, 2007
yay this first time that I develop something larger
My problem: main method display a frame with buttons where you choose what function/action you want to perform. Once you press a button I want the main window become invisible and windows with option for function to become visible.
So what I did is
  1. public void actionPerformed(ActionEvent e)
  2. {
  3. if(e.getSource() == btnFirst)
  4. {
  5. myApp.setVisible(false); // pass control to selected function
  6. doSomething();
  7. myApp.setVisible(true); // retrive control
  8. }
  9. }
however this get me following error
  1. C:\MyApp.java:54: cannot find symbol
  2. symbol : method doSomething()
  3. location: class MyApp
  4. doSomething();
  5. ^

with call doSomething() I want to triger this
  1. public RenameImage()
  2. {
  3. myFrame = new JFrame("Do Something");
  4. myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  5. buildGUI();
  6. myFrame.setSize(470,470);
  7. myFrame.setVisible(true);
  8. }

I don't even what to google for
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Nov 2004
Posts: 6,144
Reputation: jwenting is just really nice jwenting is just really nice jwenting is just really nice jwenting is just really nice 
Solved Threads: 212
Team Colleague
jwenting's Avatar
jwenting jwenting is offline Offline
duckman

Re: Passing control

 
0
  #2
Feb 18th, 2007
hmm, the blatantly obvious: check whether the method actually exists in the same class you're calling it from.

And of course rename RenameImage to renameImage.
As people are clearly allowed to attack me but I'm not allowed to defend myself, I no longer post to this site.
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,176
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 479
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Passing control

 
0
  #3
Feb 18th, 2007
Came to same conclusion when I went to bed(funny enought I always find solution to problem went I go to sleep). But thats fine as long there would be solution :lol:
Now this peace of code doesn't do exactly what I want to do
  1. if(e.getSource() == btnFirst)
  2. {
  3. myApp.setVisible(false); // pass control to selected function
  4. doSomething();
  5. myApp.setVisible(true); // retrive control
  6. }
it hidde myApp for time which take to display second application window and then it will display it again. I'm missing sort of control mechanizm which check if second window still in use, if yes keep it hidden. I tried to use while loop and check boolean in second application, but that kicked my CPU activity to 100% and I have to force to shut-down.
So how I do I get around this?
Secondly, I use JFrame setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) to close my windows, but this kill both frames.
So how do I specify I want to close only second JFrame?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,176
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 479
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Passing control

 
0
  #4
Feb 19th, 2007
NEW UPDATE
Problem with killing both JFrames sorted, replaced JFrame.EXIT_ON_CLOSE with JFrame.DISPOSE_ON_CLOSE.
Now I add it WindowEvents so if windowDeactivated it will setVisible to false and windowActivated to setVisible to true. However I can't triger windowActivated when I close the second window.
What shall I do?
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Join Date: Dec 2004
Posts: 4,176
Reputation: peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of peter_budo has much to be proud of 
Solved Threads: 479
Moderator
Featured Poster
peter_budo's Avatar
peter_budo peter_budo is online now Online
Code tags enforcer

Re: Passing control

 
0
  #5
Feb 21st, 2007
Finaly found solution to my problem :cheesy:
Bellow is example code from java forum(link here) which shows how this thing can be done
  1. import java.awt.*;
  2. import java.awt.event.*;
  3. import javax.swing.*;
  4.  
  5. public class test extends JFrame implements ActionListener {
  6. JButton frame1Button, frame2Button;
  7. JFrame frame1, frame2;
  8.  
  9. public test() {
  10. super("Frame 1");
  11. frame2 = new JFrame("Frame 2");
  12. frame2Button = new JButton("Hide");
  13. frame2Button.addActionListener(this);
  14. JPanel frame2ButtonPanel = new JPanel();
  15. frame2ButtonPanel.add(frame2Button);
  16. frame2.getContentPane().add(frame2ButtonPanel, "North");
  17. frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  18. frame2.setSize(300,200);
  19. frame2.setLocation(350,350);
  20. frame2.setVisible(true);
  21. frame1 = this;
  22. frame1Button = new JButton("Hide");
  23. frame1Button.addActionListener(this);
  24. JPanel frame1ButtonPanel = new JPanel();
  25. frame1ButtonPanel.add(frame1Button);
  26. getContentPane().add(frame1ButtonPanel, "North");
  27. setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  28. setSize(300,200);
  29. setLocation(100,100);
  30. setVisible(true);
  31. }
  32.  
  33. public void actionPerformed(ActionEvent e) {
  34. JButton button = (JButton)e.getSource();
  35. if(button == frame1Button) {
  36. frame1.setVisible(false);
  37. frame2.setVisible(true);
  38. }
  39. if(button == frame2Button) {
  40. frame1.setVisible(true);
  41. frame2.setVisible(false);
  42. }
  43. }
  44.  
  45. public static void main(String[] args) {
  46. new test();
  47. }
  48. }
Learn to see in another's calamity the ills which you should avoid.
Publilius Syrus
(~100 BC)

LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC