quinta-feira, 30 de dezembro de 2010

Feliz Ano Novo a todos.

Desejo Feliz Ano Novo a todos, felicidades e boas festas e que 2011 seja repleto de felicidades, paz, harmonia, só alegria e etc,etc,etc,etc,etc.
E muito mais posts!kkkk

terça-feira, 28 de dezembro de 2010

Criando um Preloader - Java

Criando um preloader em java.
Basta adequar para sua nescessidade.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.beans.*;
import java.util.Random;

public class Preloader extends JPanel
implements ActionListener,
PropertyChangeListener {

private JProgressBar progressBar;
private JButton startButton;
private Task task;
private String status;

class Task extends SwingWorker"<"Void, Void">" {
/*
* Main task. Executed in background thread.
*/
@Override
public Void doInBackground() {
Random random = new Random();
int progress = 0;
//Initialize progress property.
setProgress(0);
while (progress "<" 100) {
//Sleep for up to one second.
try {
Thread.sleep(random.nextInt(1000));
} catch (InterruptedException ignore) {}
//Make random progress.
progress += random.nextInt(10);
setProgress(Math.min(progress, 100));
}
return null;
}

/*
* Executed in event dispatching thread
*/
@Override
public void done() {
Toolkit.getDefaultToolkit().beep();
startButton.setEnabled(true);
setCursor(null); //turn off the wait cursor
//taskOutput.append("Done!\n");
progressBar.setString("Terminou!");
}
}

public Preloader() {
super(new BorderLayout());

//Create the demo's UI.
startButton = new JButton("Iniciar");
startButton.setActionCommand("start");
startButton.addActionListener(this);

progressBar = new JProgressBar(0, 100);
progressBar.setValue(0);
progressBar.setStringPainted(true);

JPanel panel = new JPanel();
panel.add(startButton);
panel.add(progressBar);

add(panel, BorderLayout.PAGE_START);
setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));

}

/**
* Invoked when the user presses the start button.
*/
public void actionPerformed(ActionEvent evt) {
startButton.setEnabled(false);
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
//Instances of javax.swing.SwingWorker are not reusuable, so
//we create new instances as needed.
task = new Task();
task.addPropertyChangeListener(this);
task.execute();
}

/**
* Invoked when task's progress property changes.
*/
public void propertyChange(PropertyChangeEvent evt) {
if ("progress" == evt.getPropertyName()) {
int progress = (Integer) evt.getNewValue();
progressBar.setString(String.format(Progresso(task.getProgress()) + " %d%%", progress));

}
}

public String Progresso(int progresso){

if(progresso "<"= 10){
status = "Processando...\n";
}
if((progresso ">"= 10) & (progresso "<"= 30)){
status = "Aguarde...\n";
}
if((progresso ">"= 30) & (progresso "<"= 50)){
status = "Calculando...\n";
}
if((progresso ">"= 50) & (progresso "<"= 70)){
status = "Verificando...\n";
}
if((progresso ">"= 70) & (progresso "<"= 80)){
status = "Processando...\n";
}
if((progresso ">"= 80) & (progresso "<"= 100)){
status = "Finalizando...\n";
}

return status;
}

/**
* Create the GUI and show it. As with all GUI code, this must run
* on the event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("Preloader");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
JComponent newContentPane = new Preloader();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}

Obs: Nos sinais de "<>" foram colocados aspas "" por causa do Blogger! basta retira-los para funcionar normal!

Referência:
http://download.oracle.com/javase/tutorial/uiswing/components/progress.html#contentsapi

sábado, 27 de novembro de 2010

Capturar o título da Janela Ativa - Delphi

procedure CapturarTituloJanelaAtiva();
var
h : THandle;
titulo : PChar;
tamanho : Integer;
begin
try
h := GetForegroundWindow;
tamanho := (GetWindowTextLength(h)+1) * SizeOf(Char);
GetMem(titulo,tamanho);
fillchar(titulo^, tamanho,#0);
GetWindowText(h, titulo, tamanho);
Memo1.Lines.Append(string(titulo) + ' - Data/Hora: ' + DateToStr(date) + ' - ' + TimeToStr(Time) );
finally
FreeMem(titulo, tamanho);
end;

end;


Para este método foi utilizado um Componente Memo para exibir os Títulos das janelas

segunda-feira, 11 de outubro de 2010

Vetor em C/C++

#include "cstdlib"
#include "iostream"
#include "time.h"
using namespace std;
int main(int argc, char *argv[])
{
//---[Trabalhando com Vetor em C/C++]---*
int i; //contador
int vetor[5] = {1,2,3,4,5};//declaração e inicialização do vetor
//percorre todo o vetor para imprimir seu conteúdo de acordo com o índice nesse caso todos os índices
for(i = 0; i "<" 5; i++){ //se você perceber o for() é igual no Java
// Iprime o resultado
printf("Valor do vetor : %d = %d \n",i,vetor[i]);
}
system("PAUSE");
return EXIT_SUCCESS;
}

Obs: Nos sinais de "<>" foram colocados aspas "" por causa do Blogger! basta retira-los para funcionar normal!

Usando a função RAND() para gerar números aleatórios em C/C++


#include "cstdlib"
#include "iostream"
#include "time.h"

using namespace std;

int main(int argc, char *argv[])
{
//---[Trabalhando com a função rand() em C/C++]---*
int r; //declaração da variável r
//OBS: alguns chamam isso de semente "inicialização de semente"
srand(time(NULL));//inicializando a semente do rand()
/*---
atribuindo a "r" um número aleatório gerado pelo rand() entre 0 e 10
quem determina que será de 0 a 10 é o mode dez "%10" se for %20 será de 0 a 20 e se quiser
gerar de 10 a 20 "%10+10"
---*/
r = rand()%10;
/*---*/
// Iprime o resultado
printf("Um número gerado pelo Rand() entre 0 e 10 : %d\n" ,r);
system("PAUSE");
return EXIT_SUCCESS;
}

sábado, 2 de outubro de 2010

Obtendo Propriedades do Sistema Operacional - Java

public void Prop_SO(){
String so;
String soverion;
String soarch;

so = System.getProperty("os.name");
soverion = System.getProperty("os.version");
soarch = System.getProperty("os.arch");
System.out.println("Obtendo Informações do Sistema Operacional:");
System.out.println("Sistema Operacional: " + so);
System.out.println("Versão do SO: " + soverion);
System.out.println("Arquitetura do SO: " + soarch);
}