Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package bal2;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.*;
- public class Balpaneel extends JPanel implements ActionListener
- {
- private JTextField size;
- private JButton actieknop;
- private JTextField xveld;
- private JTextField yveld;
- private int groot;
- private int ypos;
- private int xpos;
- public Balpaneel ()
- {
- size = new JTextField("300",5);
- size.addActionListener(this);
- add(size);
- actieknop = new JButton("teken");
- add(actieknop);
- actieknop.addActionListener(this);
- add(new JLabel("X"));
- xveld = new JTextField(3);
- xveld.addActionListener(this);
- add(xveld);
- yveld = new JTextField(3);
- yveld.addActionListener(this);
- add(new JLabel("Y"));
- add(yveld);
- }
- public void paintComponent(Graphics g)
- {
- repaint();
- super.paintComponent(g);
- //int hoog = getHeight();
- int lijn = getWidth() - 30;
- int y = getHeight() - 30;
- // int lijnmidden = (lijn / 2);
- // int balmidden = (groot / 2);
- // int beginbal = lijnmidden - balmidden;
- // int middenscherm
- // int boven = (getHeight() /4 );
- //groot = 300;
- g.setColor(Color.GREEN);
- g.drawLine(30, y, lijn, y);
- // int horizontaal = (getWidth() / 2) - (groot / 2); //Horizontale locatie berekening voor bal
- // int verticaal = (getHeight() - 30) - groot; //Verticale locatie berekening voor bal
- g.setColor(Color.ORANGE);
- // g.fillOval((horizontaal -1), (verticaal -1),(groot -1),( groot -1));
- g.fillOval(xpos, ypos, groot, groot);
- g.setColor(Color.BLACK);
- g.drawOval(xpos, ypos, groot, groot);
- // int horizontaal2 = (xpos) - (groot / 2);
- g.drawOval((xpos + (groot / 4)), ypos, (groot / 2), groot);
- }
- public void actionPerformed(ActionEvent e)
- {
- groot = Integer.parseInt(size.getText());
- ypos = Integer.parseInt(yveld.getText());
- xpos = Integer.parseInt(xveld.getText());
- //paintComponent(null, groot);
- }
- }
Add Comment
Please, Sign In to add comment