Code:
[COLOR="Navy"]
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class oefening3_13 extends JFrame {
public static void main( String args[] ) {
JFrame frame = new oefening3_13();
frame.setSize( 300, 200 );
frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
frame.setTitle( "circel" );
frame.setContentPane( new Cirkelpaneel() );
frame.setVisible( true );
}
}
class Cirkelpaneel extends JPanel {
private JButton knoprechts,knoplinks,knopgroot,knopklein;
private int diameter;
public Cirkelpaneel() {
setBackground( Color.YELLOW );
diameter = 120;
knoprechts = new JButton( "rechts" );
knoplinks = new JButton ("links");
knopgroot = new JButton ("groot");
knopklein = new JButton ("klein");
knoprechts.addActionListener( new KnopHandler1() );
knoplinks.addActionListener (new KnopHandler2());
knopgroot.addActionListener (new KnopHandler3());
knopklein.addActionListener (new KnopHandler4());
add (knoplinks);
add (knoprechts);
add (knopgroot);
add (knopklein );
}
public void paintComponent( final Graphics g ) {
super.paintComponent( g );
g.setColor( Color.RED );
// Teken een cirkel
g.fillOval (diameter, 50,20,20);
}
//Hier gebeurt de afhandeling van de knoppen
class KnopHandler1 implements ActionListener {
public void actionPerformed( ActionEvent e ) {
diameter++;
repaint();
}
}
class KnopHandler2 implements ActionListener {
public void actionPerformed( ActionEvent e ) {
diameter--;
repaint();
}
}
class KnopHandler3 implements ActionListener {
public void actionPerformed( ActionEvent e ) {
diameter++;
repaint();
}
}
class KnopHandler4 implements ActionListener {
public void actionPerformed( ActionEvent e ) {
diameter++;
repaint();
}
}
}
[/COLOR]
Laatst bewerkt door een moderator: