Xhamolk_ 0 Newbie Poster

I am not sure to understand what you really want to do with that code, or what do you mean with 'abort construction a window'.

First of all, your code has a few of errors:

1. CriarEquipamentoGUI is defined like the constructor of a class of the same name, but it is not enclosed in any class. I guess you decided to paste only the part of your interests.

2. The reason why the 'return' screws the problem is because you forgot to add brackets.

You have something like this:

if( do not show ) { 
    doSomething();
}
return; // The rest of code is unreachable.
else {  
  initComponents();
}

When you should have something like this:

if( do not show ) {
    doSomething();
    return;
} else {
    initComponents();
}

3. I am not sure if this is what you want, but after all the components are ready, you can still decide not to have the window shown.

jframeInstance.setVisible(false); // although false is its default value.

That is all I can tell by now, if you need any more help then please expand your ideas a bit more.

~ Xhamolk_

Xhamolk_ 0 Newbie Poster

This is really easy.

Just let me get some points clear, actually I will just base my answer in Windows OS.

Assuming you know how to modify your Environmental Variables, and you know how to modify your PATH so it can work with Javac,...

Step 1: 'Edit' your PATH.

Step 2: Go to the end of the line containing the PATH's value.

Step 3: Type ; - right at the end of the line

Step 4: Add the path to either javac or your c++ compiler.

Step 5: Type ; - right at the end of the line

Step 6: Add the path to the other compiler you left behind in Step 4.

Step 7: Click 'OK' until you get rid of all those frames.

Step 8: Test both compilers, and you are ready to go.

I hope this did hep you :)

Xhamolk_ 0 Newbie Poster

A summary of the errors I have received can be found here - [IMG]http://i46.tinypic.com/2cdcvat.jpg[/IMG]

import javax.swing.event.*;
import javax.swing.*;
import java.awt.*;
import java.io.*;
import java.net.*; 
import java.applet.AudioClip;

You just missed one import: java.awt.event.*;
There is where ActionListener and ActionEvent are located.

Try compiling again with that, should work correctly this time. ;)

Xhamolk_ 0 Newbie Poster

I think its due to what the compiler checks first..

Anyways, if you know the error the compiler tells you is already solver, move out and check for other type of errors.

Xhamolk_ 0 Newbie Poster

I'm not sure about what im going to say,

But i guess you'll have to create/modify something like the PC's System boot; which is what starts the windows OS.

Perhaps if you know ASM that would be easy, but in Java i cant find any solution to start anything without an OS. ( ASM to create/modify System Boot, the "OS" could still be written in Java ).

Also, for some reason im thinking in JNI; but i don't really know its capacities.


Hope it Helped, but i doubt it did.

~ Xhamolk_

Xhamolk_ 0 Newbie Poster

Well you may want to consider what Xhamolk_ suggested in post # 2. Have an ArrayList or some other Collection (as opposed to an array) of JFrames. Deleting an element is easy. Just use ArrayList's remove methods. And you can check the size with its size method.

http://java.sun.com/javase/6/docs/api/java/util/ArrayList.html

If you use a 10-element array and set an element to null, that element will be null, but the array length would still be 10. You would have to go through the array and check for null values. Use an ArrayList and it's done for you.

Option #1.
You may also try to override the size method during the declaration of the ArrayList; for example:

ArrayList<JFrame> list = new ArrayList<JFrame>() {
        @Override
        public int size() {
            int size = 0;		
            try {
                for( JFrame frame : this )
                    if( frame != null )
                        size ++;
                return size;
            }catch( Exception e ) {
                return super.size();
            }
        }

    };

That will solve the problem of having null items getting added to the count.
But cause serious problems, such as:
- Indexing
- Iterating
- Retrieving items from the array.

Option #2.

Creating a sub-class of ArrayList , in which you can create a new method, such as getUsableCount , using the same code as above; but obviously renaming.

Xhamolk_ 0 Newbie Poster

oops,

I didn't checked the code carefully enough.

You need to turn your private boolean a to private static.

~ Xhamolk_

Xhamolk_ 0 Newbie Poster

Interesting...

I'll take "kill" as hiding a specific JFrame.

First of all, if you need to know which JFrames are the ones you want to hide. You may implement any of the following methods to keep all your JFrame's identified:
- Use an array ( JFrame[] )
- Use an ArrayList ( ArrayList<JFrame> )
- Give each JFrame a different name that matches with one of your arguments.

Now that you have that done, decide which JFrame you want to hide. For example, if i used the second method, I'd be using:

ArrayList<JFrame> list = new ArrayList<JFrame>(); // Declaration of the JFrame list.
...
int index; // Declaration of the index to be used when you want to hide a JFrame.
...
list.get( index ) // returns a JFrame object
.setVisible( false ) // Turns false "visibility" for the returned JFrame object.

Now, if you need to "kill" the JFrame #3, #4, #6 you may use the following:

// @ <init>
ArrayList<JFrame> list = new ArrayList<JFrame>();
...

/**
* Kills a specific JFrame by using its index.
* @param index The Index of the JFrame you want to "kill".
*/
private void killJFrameByIndex( int index ) {
	if( index >= list.size() ) 
		return; // I don't want to throw an exception here.
	list.get( index ).setVisible( false );
}

/**
 * "Kills" the JFrames #3, #4 and #6
 */
public static void main(String[] args) {
      // Must add all the JFrame's …
Xhamolk_ 0 Newbie Poster

You need to declare a as a global variable/field.
To do so, you need to declare it outside all the methods, but still inside your class.
I saw you had declared it as a globar & private field, but you commented it.

I fixed your code, all i did was commenting the declaration of the local variable a in your main method, and uncomment the global declaration.

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JFrame;

public class WinLsnrExp extends JFrame {
    
	private boolean a=true;
	
    public WinLsnrExp() {
        
        setTitle("Window listener Example : ");
        setSize(150, 150);
    }
    public static void main(String[] args) {
    	
    //int xI,yI;
    //double xD,yD;
    /*boolean*/ a = false;	
    while (a){
    /*	for (int i=0;i<100;i++) {
        WinLsnrExp wle = new WinLsnrExp();
        wle.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        wle.setLocation((int)(Math.random()*1000),(int)(Math.random()*1000));
        wle.setVisible(true);
    }
   
    }}
    	//xD=1000*Math.random();
    	//int xI = (int)xD;  
      
*/
    	
    	System.out.println(Math.random());
        WinLsnrExp wle = new WinLsnrExp();
        wle.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        wle.setLocation((int)(Math.random()*1000),(int)(Math.random()*1000));
        wle.setVisible(true);
        wle.addWindowListener(new WindowListener() {
            public void windowClosed(WindowEvent arg0) {
                System.out.println("Window close event occur");
            }
            public void windowActivated(WindowEvent arg0) {
                System.out.println("Window Activated");
            }
            public void windowClosing(WindowEvent arg0) {
                System.out.println("Window Closing");
                a=true; // cant refer to non final variable a inside an inner class defined in a different method
            }
            public void windowDeactivated(WindowEvent arg0) {
                System.out.println("Window Deactivated");
            }
            public void windowDeiconified(WindowEvent arg0) {
                System.out.println("Window Deiconified");
            }
            public void windowIconified(WindowEvent arg0) {
                System.out.println("Window Iconified");
            }
            public void windowOpened(WindowEvent arg0) {
                System.out.println("Window Opened");
            }
        });
    }
}
}
Xhamolk_ 0 Newbie Poster

Simple Solution, although this has been already solved:

String time = String.format("%d:%02d", Integer.toString(hours), Integer.toString( minutes) );

~ Xhamolk_