Skip to content

Tag: Java

Anúncio do NetBeans 6.5 Beta

O Netbeans.org anunciou a disponibilidade do NetBeans IDE 6.5 Beta. Abaixo a tradução do anúncio:

O NetBeans IDE 6.5 introduz várias novas funcionalidades, incluindo uma IDE robusta para PHP, deputação de JavaScript para o Firefox e IE, e suporte a Groovy e Grails. Esse lançamento também inclui várias melhorias para o desenvolvimento em Java, Ruby e Rails, e C/C++. Dentre as melhorias no Java destacam-se: suporte nativo ao Hibernate, importação de projetos do Eclipse, e compilação no salvamento.

Links:

Outros destaques:

  • PHP
    • Completação de código
    • Consertos rápidos e checagem semântica
    • Suporte a FTP
    • Depuração com Xdebug
    • Suporte a Web Services populares
  • Ajax/JavaScript
    • Suporte a depuração no Firefox e IE
    • Monitoramento cliente de HTTP
    • Vêm com as bibliotecas mais populares de JavaScript
  • Java
    • Suporte a Groovy/Grails
    • Compilação/Deploy no momento do salvamento
    • Importação e sincronização de projetos do Eclipse
    • Suporte nativo a Hibernate
    • Gerador de CRUD JSF agora com Ajax
  • Banco de Dados
    • Melhorias no editor
  • C/C++
    • Melhorias na completação de código e destaque de erros
    • Desenvolvimento remoto
  • Ruby
    • Suporte aos Testes Ruby
    • Melhoria no suporte a Rake
  • GlassFish V3 “Prelude”
    • Menor tamanho, inicialização e deployment mais rápido
    • Suporte a scripting, inclusive jRuby

O NetBeans IDE 6.5 final está planejado para ser lançado em Outubro de 2008. Como sempre, é bem vindo e nós encorajamos seu feedback sobre sua experiência usando a IDE NetBeans. Visite nossas listas de email ou faça uma postagem no seu blog.

Java Calendar Examples

import java.util.Calendar;

public class Main {
    public static void main(String[] args) {
        Calendar today = Calendar.getInstance();
        System.out.println("Today is  " + today.getTime());
    }
}

In this simplest example of Calendar, the output would be

Today is : Tue Jul 01 10:56:14 BRT 2008

In the next example how to get information about the day inside the year, month and week.

import java.util.Calendar;

public class Main {
    public static void main(String[] args) {
        Calendar today = Calendar.getInstance();
        int dof = today.get(Calendar.DAY_OF_YEAR);
        int dom = today.get(Calendar.DAY_OF_MONTH);
        int dow = today.get(Calendar.DAY_OF_WEEK);
        System.out.println("Today is the " + dof +"º day in this year,");
        System.out.println("the " + dom +"º day in this month");
        System.out.println("and the " + dow +"º day in this week.");
    }
}

The output could be

Today is the 183º day in this year,
the 1º day in this month
and the 3º day in this week.

The next example is about how to add (and subtract) a duration from a Calendar.

import java.util.Calendar;

public class Main {
    public static void main(String[] args) {
        Calendar today = Calendar.getInstance();
        System.out.println("Today is " + today.getTime());

        Calendar yesterday = (Calendar)today.clone();
        yesterday.add(Calendar.DATE, -1);
        System.out.println("Yesterday was " + yesterday.getTime());

        Calendar tomorow = (Calendar)today.clone();
        tomorow.add(Calendar.DATE, 1);
        System.out.println("Tomorow will be " + tomorow.getTime());
    }
}

A typical output would be

Today is Tue Jul 01 10:44:18 BRT 2008
Yesterday was Mon Jun 30 10:44:18 BRT 2008
Tomorow will be Wed Jul 02 10:44:18 BRT 2008

Event Review: JavaDay Juazeiro do Norte

Rafael Carneiro, Tarso Bersa, Rafael Ponte and me, after 8 hours of bus travel, arrived in Juazeiro do Norte to talk at the first JavaDay there.

Why Free Software?

JavaDay_Juazeiro_do_Norte_Silveira_Rafael Last touches

JavaDay Juazeiro do Norte Silveira Neto Coffee Break Gifts Silveira Rafael Ponte

  • Rafael Carneiro talked about Java Certification.
  • Tarso Bersa talked about Spring Framework for JEE applications.
  • I talked about NetBeans 6.
  • Rafael Ponte talked about JavaServer Faces.

We answered a lot of questions and gave lot of gifts. I also showed the Sun Academic Initiative, which they are already subscribed. We also showed several opportunities they can participate with CEJUG like free vouchers or a free travel for Belgium.

Some pictures we took. These ones during the bus travel. We saw a nice sunrise through beautiful landscapes.

P5260004 P5260005 P5260007 P5260006

We playing guitar hero. 😀 The city have their own shopping with games, restaurant and cinema.

Guitar Hero Guitar Hero

The main atraction at Juazeiro is a statue of Padre (Priest) Cícero with 7 meters itself and more 8 meters of base. Pilgrimage to this statue takes place in his honour every November, attracting thousands of followers. The city’s economy is highly influenced by those travelers devotes.

Padim fitas

eu e o padim Padim

There’s a museum with several personal objects from Padre Cicero. People go there in order to thanks for miracles. If you got your a part of your body cured, of place there a wooden replica of that part of your body. If you got a car, you place a wooden car or a photo, and so on. There is thousands, maybe millions, of objects theres.

P5270054 P5270063

P5270058 P5270056 P5270062

You can see all photos at Carneiro’s album or in my album.

CEJUG, JavaMe, Domain Driven Design and CruiseControl

This saturday we had our CEJUG traditional event CCT (Café com Tapioca) done monthly, each time in a diferent university. This time we had three speakers, Vando Batista, Rafael Pontes and Luthiano Vasconcelos talking about Java ME, Domain Driven Design and Cruise Control respectively.

Rafael Carneiro
Rafael Carneiro opening the event.

Wando

All photos I took (just a few due to weak batteries in my camera) are hosted in this album. This was out first event recorded and streamed by TV Software Livre. Thanks also guys from ArgoHost who made it possible.

Eventos de Software Livre ainda essa semana

Essa semana está cheia de eventos relacionados a Software Livre e quem está em Fortaleza não pode perder essas oportunidades. Para citar alguns:

Esse ano estão havendo várias palestras sobre Software Livre e Cultura Livre dentro da InfoBrasil e a prefeitura de Fortaleza cedeu um bom espaço para a comunidade montar um estande sobre o tema. Aproveitando o espaço nós montamos uma mini-grade de mini-palestras 🙂

14 de maio (Quarta-feira)

Tarde/Noite

16:00 – 17:00

Título: Metodologia de teste de segurança OSSTMM
Palestrante: Fernando Chucre

17:00 – 18:00

Título: Conhecimento Livre e Software Livre…
Entendendo como funciona e o que é.
Palestrante: Roberto Parente é Bacharelando de Ciência da Computação da Universidade Federal do Ceará, faz parte do grupo de pesquisa “Paralelismo, Grafos e Otimização” (ParGO) e membro do Grupo de Estudo de Linux e Software Livre (GELSoL).

15 de maio (Quinta-feira)

Tarde/Noite

16:00 – 18:00

Título: Trabalhando na internet com E-groupware e WordPress MU
Palestrante: Fernando Chucre

16 de maio (Sexta-feira)

Manhã

9:00 – 12:00

Título: Novidades do BrOffice.org 3.0 com sorteio de brindes
Palestrante: Marcus de Vasconcelos Diogo da Silva (ONG BrOffice.org)

Tarde/Noite

15:00 – 16:30

Título: Sistema Operacional OpenSolaris: palestra sobre as novidades e inovações do sistema operacional OpenSolaris e sobre o  lançamento da distribuição OpenSolaris 2008.5.
Palestrante: Silveira Neto, é bacharelando em Computação na Universidade Federal do Ceará, Embaixador de Campus da Sun Microsystems e pesquisador no tema de Computação de Alto Desempenho no grupo de pesquisa ParGO.

* Ao final da palestra haverá sorteio de brindes do OpenSolaris.

16:30 – 18:00

Título: Postgree SQL porque migrar?
Palestrante: Coutinho Nabucodonossor é participante da Comunidade Postgree.

As palestras são gratúitas e o acesso é livre. Maiores informações no site da InforBrasil. Também há a grade do congresso que também conta com mais palestras sobre o tema, mas estas são pagas. Você confere elas também no site da InforBrasil.

E para fechar com chave de ouro a semana, o CEJUG promove o já tradicional evento mensal Café com Tapioca, esse sábado.

O evento acontece na Faculdade Lourenço Filho e a grade é essa:

Horário Palestrante Tema
09:00 as 09:50 Rafael Ponte Entendendo Domain Driven Design
09:55 as 10:50 Vando Batista Desmistificando o JavaME
10:50 as 11:10 coffee-break
11:10 as 11:50 Luthiano Vasconcelos Integração Contínua com Cruise Control

Não percam, maiores informações no site do evento.

Java key listening example

This post continues a serie of posts I’m writing about 2D game development in Java.
A simple example of an JPanel that implements KeyListener (and a little trick) to handle KeyEvents to move a white square.

Java KeyListening Example

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class KeyPanel extends JPanel implements KeyListener{
    private int x=50,y=50;
    public KeyPanel() {
        JTextField textfield = new JTextField();
        textfield.addKeyListener(this);
        add(textfield);
        textfield.setPreferredSize(new Dimension(0,0));
    }

    public void keyTyped(KeyEvent e) {}

    public void keyReleased(KeyEvent e) {}

    public void keyPressed(KeyEvent e) {
        if (e.getKeyCode() == KeyEvent.VK_LEFT)
            x-=5;
        if (e.getKeyCode() == KeyEvent.VK_RIGHT)
            x+=5;
        if (e.getKeyCode() == KeyEvent.VK_DOWN)
            y+=5;
        if (e.getKeyCode() == KeyEvent.VK_UP)
            y-=5;
        this.repaint();
    }

    @Override
    public void paintComponent(Graphics g) {
        super.paintComponent(g);
        g.setColor(Color.black);
        g.fillRect(0, 0, 500, 500);
        g.setColor(Color.white);
        g.fillRect(x, y, 50, 50);
    }
}

Download the complete NetBeans source project files: KeyTest.tar.bz2.

Simple Java Tileset Example

Tilesets are a common technique in game development to create all kinds of tile-based games (from strategy to RPG games).

Here’s a example of simple 2D isometric square tilesets. I decided to use 32×32 pixels tiles and store 10 tiles per row in a single image:

I created a class called public class JGameCanvas that extends from JPanel from swing:

package game;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;
import javax.swing.JPanel;

enum Tile {
GRASS, GRASS_STONE, GRASS_BAGS, T3, T4, T5, T6, T7, T8, T9,
TREE, TREE_CHOMP, TREE_DEAD, T13, T14, T15, T16, T17, T18, T19,
ROAD_H, ROAD_V, ROAD_HV_DOWN, ROAD_HV_UP, ROAD_VH_RIGHT, ROAD_VH_LEFT, ROAD_CROSS, T27, T28, T29,
WALL, WALL_POSTER, WALL_END_RIGHT, WALL_END_LEFT, T34, T35, T36, T37, T38, T39,
T40, T41, T42, T43, T44, T45, T46, T47, T48, T49,
NEWS, T51,      RES_1, RES_2, BUSS_1, BUSS_2, HOSP_1, HOSP_2, MARK_1, MARK_2,
PIZZ_1, PIZZ_2, RES_3, RES_4, BUSS_3, BUSS_4, HOSP_3, HOSP_4, MARK_3, MARK_4,
PIZZ_3, PIZZ_4, RES_5, RES_6, BUSS_5, BUSS_6, HOSP_5, HOSP_6, MARK_5, MARK_6
}

public class JGameCanvas extends JPanel{
    private static final int tW = 32; // tile width
    private static final int tH = 32; // tile height
    private static final Tile map[][] =
    {{Tile.TREE,Tile.TREE, Tile.TREE, Tile.ROAD_V, Tile.GRASS, Tile.TREE, Tile.TREE_DEAD, Tile.GRASS_STONE, Tile.TREE, Tile.TREE},
     {Tile.WALL, Tile.WALL_POSTER, Tile.WALL_END_RIGHT , Tile.ROAD_V, Tile.WALL_END_LEFT, Tile.WALL, Tile.WALL_END_RIGHT, Tile.TREE_CHOMP, Tile.GRASS_STONE, Tile.GRASS_STONE},
     {Tile.GRASS,Tile.GRASS, Tile.GRASS_STONE, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS},
     {Tile.PIZZ_1,Tile.PIZZ_2, Tile.GRASS, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS},
     {Tile.PIZZ_3,Tile.PIZZ_4, Tile.GRASS, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.MARK_1, Tile.MARK_2, Tile.HOSP_1, Tile.HOSP_2},
     {Tile.ROAD_H,Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_VH_LEFT, Tile.TREE, Tile.TREE_DEAD, Tile.MARK_3, Tile.MARK_4, Tile.HOSP_3, Tile.HOSP_4},
     {Tile.GRASS,Tile.BUSS_1, Tile.BUSS_2, Tile.ROAD_V, Tile.TREE, Tile.NEWS, Tile.MARK_5, Tile.MARK_6, Tile.HOSP_5, Tile.HOSP_6},
     {Tile.GRASS,Tile.BUSS_3, Tile.BUSS_4, Tile.ROAD_VH_RIGHT, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H, Tile.ROAD_H},
     {Tile.GRASS,Tile.BUSS_5, Tile.BUSS_6, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS},
     {Tile.GRASS,Tile.GRASS, Tile.GRASS, Tile.ROAD_V, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS, Tile.GRASS}
    };

    private Image tileset;

    public JGameCanvas() {
        tileset = Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("resources/tileset.png"));
    }

    @Override
    protected void paintComponent(Graphics g) {
        g.setColor(Color.black);
        g.fillRect(0, 0, getWidth(), getHeight());

        for(int i=0;i<10;i++)
            for(int j=0;j<10;j++)
                drawTile(g, map[j][i], i*tW,j*tH);
    }

    protected void drawTile(Graphics g, Tile t, int x, int y){
        // map Tile from the tileset
        int mx = t.ordinal()%10;
        int my = t.ordinal()/10;
        g.drawImage(tileset, x, y, x+tW, y+tH,
                mx*tW, my*tH,  mx*tW+tW, my*tH+tH, this);
    }
}

Program running:

Those graphics I created for the game Batalhão and are under Creative Commons Attribution Share Alike 3.0 license. The source code is under GPL license, download the NetBeans project with sources: tileset.tar.bz2.

Integer.MAX_VALUE and Integer.MIN_VALUE

You should know that variable values are cyclic in Java.

public class Test{
  public static void main(String args[]){
     System.out.println(Integer.MAX_VALUE);
     System.out.println(Integer.MIN_VALUE);
     int x = Integer.MAX_VALUE + 1;
     System.out.println(x);
  }
}

This produces:

2147483647
-2147483648
-2147483648