| | |
Passing control
Thread Solved
![]() |
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
however this get me following error
with call doSomething() I want to triger this
I don't even what to google for
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
Java Syntax (Toggle Plain Text)
public void actionPerformed(ActionEvent e) { if(e.getSource() == btnFirst) { myApp.setVisible(false); // pass control to selected function doSomething(); myApp.setVisible(true); // retrive control } }
Java Syntax (Toggle Plain Text)
C:\MyApp.java:54: cannot find symbol symbol : method doSomething() location: class MyApp doSomething(); ^
with call doSomething() I want to triger this
Java Syntax (Toggle Plain Text)
public RenameImage() { myFrame = new JFrame("Do Something"); myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); buildGUI(); myFrame.setSize(470,470); myFrame.setVisible(true); }
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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
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?
Now this peace of code doesn't do exactly what I want to do
Java Syntax (Toggle Plain Text)
if(e.getSource() == btnFirst) { myApp.setVisible(false); // pass control to selected function doSomething(); myApp.setVisible(true); // retrive control }
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
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?
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
Finaly found solution to my problem :cheesy:
Bellow is example code from java forum(link here) which shows how this thing can be done
Bellow is example code from java forum(link here) which shows how this thing can be done
Java Syntax (Toggle Plain Text)
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class test extends JFrame implements ActionListener { JButton frame1Button, frame2Button; JFrame frame1, frame2; public test() { super("Frame 1"); frame2 = new JFrame("Frame 2"); frame2Button = new JButton("Hide"); frame2Button.addActionListener(this); JPanel frame2ButtonPanel = new JPanel(); frame2ButtonPanel.add(frame2Button); frame2.getContentPane().add(frame2ButtonPanel, "North"); frame2.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame2.setSize(300,200); frame2.setLocation(350,350); frame2.setVisible(true); frame1 = this; frame1Button = new JButton("Hide"); frame1Button.addActionListener(this); JPanel frame1ButtonPanel = new JPanel(); frame1ButtonPanel.add(frame1Button); getContentPane().add(frame1ButtonPanel, "North"); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(300,200); setLocation(100,100); setVisible(true); } public void actionPerformed(ActionEvent e) { JButton button = (JButton)e.getSource(); if(button == frame1Button) { frame1.setVisible(false); frame2.setVisible(true); } if(button == frame2Button) { frame1.setVisible(true); frame2.setVisible(false); } } public static void main(String[] args) { new test(); } }
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
Publilius Syrus
(~100 BC)
LJC - London Java Community, Graduate & Undergraduate Software Development Community, JAVAWUG (Java Web User Group), The London Android Group
![]() |
Similar Threads
- Please help with passing data from one form to another form (VB.NET)
- POpulate DataGrid (VB.NET)
- need halp passing array data (C#)
- Setting a Home-Made Browser as Default (Visual Basic 4 / 5 / 6)
- message passing interfaces (C)
Other Threads in the Java Forum
- Previous Thread: Wireless information sharing system
- Next Thread: java swing
| Thread Tools | Search this Thread |
addball android applet application apps array automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) button card class classes client code collision columns component constructor crashcourse css database designadrawingapplicationusingjavajslider draw eclipse ee error eventlistener exception expand fractal free game givemetehcodez graphics gui guidancer html ide image integration intellij j2me java javaarraylist javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia jvm linux loan loop method migrate mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle phone physics plazmic print problem program programming project radio scanner server service set sharepoint smart sms smsspam software sql subclass support swing textfield threads tree trolltech unlimited utility windows






