Boa tarde a todos.
Iniciei no mundo java faz pouco tempo , e optei pelo livro Use a cabeça java para começar a aprender sobre o assunto.
Acontece que acabei “encalhando” em uma parte, onde inicia o construção de GUI’s em java.
Ficaria muito agradecido se alguem pudesse me ajudar.
A duvida minha esta na pagina 261 onde tenho que fazer um botão que desenhe circulos em um JPanel , acontece que não tenho a minima ideia de como fazer isso.
Segue o codigo das classes:
[code]import java.awt.;
import javax.swing.;
public class MyDrawPanel extends JPanel{
}
public void MyDrawPanel(){
Graphics2D g2d = (Graphics2D) g;
int red = (int) (Math.random()*255);
int green = (int) (Math.random()*255);
int blue = (int) (Math.random()*255);
Color startColor = new Color(red, green, blue);
red = (int) (Math.random()*255);
green = (int) (Math.random()*255);
blue = (int) (Math.random()*255);
Color endColor = new Color(red, green, blue);
GradientPaint gradient = new GradientPaint(70,70,startColor,150,150,endColor);
g2d.setPaint(gradient);
g2d.fillOval(70,70,100,100);
}
}[/code]
[code]import javax.swing.;
import java.awt.;
import java.awt.event.*;
public class SimpleGui3C implements ActionListener{
JFrame frame;
public static void main(String[] args){
SimpleGui3C gui = new SimpleGui3C();
gui.go();
}
public void go(){
frame = new JFrame();
frame.setDefaultCloseOperation(Jframe.EXIT_ON_CLOSE);
JButton button = new JButton(“Change color”);
button.addActionListener(this);
Graphics gra;
MyDrawPanel drawPanel = new MyDrawPanel(gra);
frame.getContentPane().add(BorderLayout.SOUTH, button);
frame.getContentPane().add(BorderLayout.CENTER, drawPanel);
frame.setSize(300,300);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent event){
frame.repaint();
}
public void repaint(){
}
}[/code]
Obrigado desde já…