Showing posts with label Compile. Show all posts
Showing posts with label Compile. Show all posts

Saturday, February 18, 2012

Using Netbeans to Create a CardLayout V2

In the previous post, I went to great length to write a tutorial on how to use CardLayout in Netbeans. when it came to choosing which panels to use, I just chose the next panel that is within the bottomPanel.


  private void clickButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(bottomPanel.getLayout());
        cl.next(bottomPanel);
    }

If you want to choose which panel would be shown, all you have to do is just change the cl.next(bottomPanel) to 
cl.show(bottomPanel,"card4");

so the previous method will become: 

  private void clickButtonActionPerformed(java.awt.event.ActionEvent evt) {
        // TODO add your handling code here:
        CardLayout cl = (CardLayout)(bottomPanel.getLayout());
       cl.show(bottomPanel,"card4");
    }

"card4" is the name of the panel that is red for me. It might be different for you but essentially you have to put the layout name of the panel you want to show. Note that the layout name of the panel might be different from the name of the panel that you set it to. The layout name of the  panel will be under the properties tab on the right hand of the screen.




Saturday, February 11, 2012

Java Compiling

I got so engrossed in watching movies and playing games yesterday that I did not get back to the blog and learn how to use CardLayout :S. Watching too many movies can be quite taxing on the mind as I felt that I did not achieve much during the day :S. Oh well, what's done is done and its back to business. This time I am going to blog about Java compiling using the -d (directory) flag.

Because I have been using Netbeans all this time, I learned that even though Netbeans made many things easier, it is not the best way to relearn or learn Java. The directories and java paths and imports when creating through Netbeans are all managed automatically and while this would make it easier for Java Developers, I feel that while re-learning Java, it would be better to go back to the basics of using command line and understanding what is happening. This post will be dedicated to simple compiling of java, especially with the directory flag.

When it comes to making my own project I have decided to start using packages when it comes to my java files. I will try to compile each java file under the general packages of "net.sambel.samuel.tambunan.***" where *** are the package names. So for example, if MyApp is a package and MyAppClass is the first java class in the package, i would have to run it under

javac net/sambel/samuel/tambunan/MyApp/*.java;

When using the -d (directory) flag,

I can type javac -d ../classes net/sambel/samuel/tambunan/MyApp/*.java

to compile everything from inside net/sambel/samuel/tambunan/MyApp/*.java and put all the compiled classes into a separate folder in

classes/net/sambel/samuel/tambunan/MyApp

This would help me keep all my java source codes in a separate folder form my classes files.

So my overall directories would look in the end like

MyProject -> source ->net -> sambel -> samuel -> tambunan ->MyApp -> ***.java
                 -> classes ->net -> sambel -> samuel -> tambunan ->MyApp -> ***.class

NOTE: when compiling using:

javac net/sambel/samuel/tambunan/MyApp/*.java;

be sure that you are inside the source directory.