Some tips in Java

You are programming in Java and you want to know some simple but new things? So read this post and maybe you’ll know some new things 🙂 .

The first tip is about the focus. What is a focus? If you have a JTextField and you want to have the cursor automatically activated in it when you open the window, you put a focus. Here is the code :


jtf.setFocusable(true);

SwingUtilities.invokeLater(new Runnable()
{
@Override
public void run()
{
jtf.requestFocus();

}

});

pan.setVisible(true);

Here the JTextField name is jtf and you have to do this like this if you want to put the pan.setVisible(true); after the focus (for example if you want to put the “visibility” at the end of the code).

Now you have a grid of buttons and you want to know which one is clicked. It’s very simple, you just have to set a name to your buttons :


JButton[][] myGrid = new JButton [10][10];

for(int i = 0; i < myGrid.length; i++ ) {
for(int j = 0; j < myGrid[0].length; j++ ) {
myGrid[i][j] = new JButton();
myGrid[i][j].setSize(30,30);
myGrid[i][j].setBackground(Color.BLUE);
myGrid[i][j].setLocation(50+30*i,80+30*j);
myGrid[i][j].setName("" + i + j);
pan.add(myGrid[i][j]);
}

}

Here I put the name with myGrid[i][j].setName("" + i + j); and the name will be 00 for the first button and so on. And now if you want to have the name, you must do this in a listener :


String name = ((JButton) ev.getSource()).getName();

int a = name.charAt(0)-48;
int b = name.charAt(1)-48;

And here you have the name and you can use it as you want.

A last very little tip (it’s pretty sure you already know it), how to unactivate a button. It’s very simple, when you’ve created your button, just put this :


button.setEnabled(false);

You have to change button with the name of your button.

It’s the end of this post. If you have any question, feel free to ask. Hope it will help you and I’ll try to make an other post about tips in Java.

How to run little java programs in MobileTerminal

Here is a new little tutorial that shows you how to run littles Java programs in MobileTerminal.

Needed for this tutorial :

  • A jailbroken iDevice
  • MobileTerminal installed on it

First, go in Cydia. Be sure to have the developer “profile” turned on (Manage –>; Settings –>; Developer). Now, you have to search this :

  • iPhone/Java (it will install others needed packages).
  • Jikes.

20121229-011323.jpg

20121229-011331.jpg

Just install these packages. Now, you have to do a Java file. For example, you can just type this in the file (name it test.java in this case) :

public class test{
public static void main (String args[]){
System.out.println("Hello World!");
}
}

You can do it on your iDevice if you have iFile or any other file manager or you can do it on your computer and then transfer it with iFunBox (in this tutorial, I put the file in /var/mobile).

Now that you’ve made all what is written, open MobileTerminal. Type jikes test.java -cp /usr/lib/rt.jar (or the name_of_your_file.java).

20121229-011743.jpg

Type on the “return” button. You have now to type java test (or the_name_of_your_file), just type one more time on the “return” button, wait a bit and it will show the message 🙂 .

20121229-011845.jpg

If you have any tip or problem, you can post a comment 😉 .

The DM Team

So I’ve a new team and a new project. I made a team with a friend and the name of our group is “DM Team”.

We love developping and so we made this little team just to work with each other and to enjoy the development. We will make a website and after that some programs. We haven’t got the same knowledge in the programming language, but we will try to do some cool stuf.

You can find our blog here :
DM Team’s Blog

And you can follow us on Twitter :
@DMTeam92

Task/Staff Manager Advancements

My project of a task and staff manager to use offline advance but is not finished. I think it won’t be long before I release it, but wait :).

20120918-004729.jpg

I have to build my website before I put the program on the web so wait and see.

I have two others programs that are ready to be released, a temperature converter and a timer to know how much time you passed on the computer.

20120918-004555.jpg

First Project

I will present you my first project. I will develop a “task manager” for your website/forum. You will be able to enter the name of the member and what he has for a project. There will be others stuffs.

This will be an offline programm, you will just be able to know or remembers these things in case you don’t have an internet connection.

20120915-015827.jpg