Mattie

Mattie

Sep 30th, 2009
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1. package bal2;
  2.  
  3.  
  4. import javax.swing.*;
  5. import java.awt.*;
  6. import java.awt.event.*;
  7.  
  8. public class Balpaneel extends JPanel implements ActionListener
  9. {
  10.  
  11.  
  12.  
  13. private JTextField size;
  14. private JButton actieknop;
  15. private JTextField xveld;
  16. private JTextField yveld;
  17. private int groot;
  18. private int ypos;
  19. private int xpos;
  20.  
  21. public Balpaneel ()
  22. {
  23.  
  24. size = new JTextField("300",5);
  25. size.addActionListener(this);
  26. add(size);
  27. actieknop = new JButton("teken");
  28. add(actieknop);
  29. actieknop.addActionListener(this);
  30. add(new JLabel("X"));
  31. xveld = new JTextField(3);
  32. xveld.addActionListener(this);
  33. add(xveld);
  34. yveld = new JTextField(3);
  35. yveld.addActionListener(this);
  36. add(new JLabel("Y"));
  37. add(yveld);
  38.  
  39. }
  40.  
  41. public void paintComponent(Graphics g)
  42. {
  43.  
  44. repaint();
  45. super.paintComponent(g);
  46. //int hoog = getHeight();
  47. int lijn = getWidth() - 30;
  48. int y = getHeight() - 30;
  49.  
  50. // int lijnmidden = (lijn / 2);
  51. // int balmidden = (groot / 2);
  52. // int beginbal = lijnmidden - balmidden;
  53.  
  54. // int middenscherm
  55. // int boven = (getHeight() /4 );
  56.  
  57. //groot = 300;
  58. g.setColor(Color.GREEN);
  59. g.drawLine(30, y, lijn, y);
  60.  
  61. // int horizontaal = (getWidth() / 2) - (groot / 2); //Horizontale locatie berekening voor bal
  62. // int verticaal = (getHeight() - 30) - groot; //Verticale locatie berekening voor bal
  63. g.setColor(Color.ORANGE);
  64. // g.fillOval((horizontaal -1), (verticaal -1),(groot -1),( groot -1));
  65. g.fillOval(xpos, ypos, groot, groot);
  66.  
  67. g.setColor(Color.BLACK);
  68. g.drawOval(xpos, ypos, groot, groot);
  69.  
  70. // int horizontaal2 = (xpos) - (groot / 2);
  71.  
  72. g.drawOval((xpos + (groot / 4)), ypos, (groot / 2), groot);
  73.  
  74. }
  75.  
  76.  
  77.  
  78. public void actionPerformed(ActionEvent e)
  79. {
  80. groot = Integer.parseInt(size.getText());
  81. ypos = Integer.parseInt(yveld.getText());
  82. xpos = Integer.parseInt(xveld.getText());
  83. //paintComponent(null, groot);
  84.  
  85.  
  86. }
  87.  
  88. }
  89.  
Add Comment
Please, Sign In to add comment