Tuesday, November 16, 2010

Interface AWT no processing

import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class exemplo_awt extends PApplet implements ActionListener{

float r, ang;
// tipos do AWT
Button okButton;
Button wrongButton;
TextField nameField;


public void setup()
{
size(400, 400); // define o tamnho da tela
background(255); // define a cor de fundo como branco
r = min(width,height) / 2 * 0.9f;
ang = 0;
//
setLayout(new FlowLayout());
okButton = new Button("Action!");
wrongButton = new Button("Don't click!");
nameField = new TextField("Type here Something",35);
//
add(okButton);
add(wrongButton);
add(nameField);
//
// Attach actions to the components
okButton.addActionListener(this);
wrongButton.addActionListener(this);
}

public void draw()
{
background(255);
star(r, 5, 3, ang);
ang += 0.01f;
}

public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == okButton){
nameField.setText("OK button!");
repaint();
}

if (evt.getSource() == wrongButton){
nameField.setText("Wrong button!");
repaint();
}
}

public void star(float raio, float lado, float divisor, float angulo)
{
float next, k, i,inc,y0,x0,y1,x1,pi=3.141596f;
float pi2 = 2*pi;
inc = pi2/lado;
k = divisor;
next = inc * k;
for(i=angulo;i<=pi2+angulo;i+=inc)
{
x0 = sin(i)*raio;
y0 = -cos(i)*raio;
x1 = sin(i+next)*raio;
y1 = -cos(i+next)*raio;
line(width/2+round(x0),height/2+round(y0),width/2+round(x1),height/2+round(y1));
}
}


}

No comments:

Post a Comment