Advertisement
Guest User

Untitled

a guest
Oct 25th, 2014
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.52 KB | None | 0 0
  1. public void paintComponent(Graphics g){
  2. super.paintComponent(g);
  3.  
  4.  
  5.  
  6. Rectangle r = new Rectangle(500,300,250,400);
  7. g.setColor(jpp.bodyColour);
  8. g.fillRect((int)r.getX(),(int)r.getY(),(int)r.getHeight(),(int)r.getWidth());
  9.  
  10.  
  11. g.setColor(Color.BLUE);
  12. g.drawString("banana", 50, 60);
  13.  
  14. }
  15.  
  16. import java.awt.*;
  17. import java.awt.event.*;
  18.  
  19. import javax.swing.*;
  20.  
  21.  
  22. public class TestProjectJPanel extends JFrame {
  23.  
  24.  
  25.  
  26. public JButton b;
  27. public JButton u;
  28. public JButton l;
  29. public JButton r;
  30.  
  31. public String s;
  32.  
  33. public Color color = (Color.WHITE);
  34. public JPanel panel;
  35. public Color bodyColour;
  36. public Color doorColour;
  37. public Color wheelColour;
  38.  
  39.  
  40.  
  41.  
  42.  
  43. public TestProjectJPanel(){
  44.  
  45. JFrame f = new JFrame();
  46.  
  47. panel = new JPanel();
  48. panel.setBackground(color);
  49.  
  50. // bodyColour button
  51. b = new JButton("Body Colour");
  52. b.addActionListener(
  53. new ActionListener(){
  54. public void actionPerformed(ActionEvent event){
  55. bodyColour = JColorChooser.showDialog(null, "Pick the colour", bodyColour);
  56. if(bodyColour==null)
  57. bodyColour = (Color.RED);
  58.  
  59.  
  60. }
  61. }
  62. );
  63.  
  64. u = new JButton("Wheel Colour");
  65. u.addActionListener(
  66. new ActionListener(){
  67. public void actionPerformed(ActionEvent event){
  68. wheelColour = JColorChooser.showDialog(null, "Pick the colour", wheelColour);
  69. if(wheelColour==null)
  70. wheelColour = (Color.BLACK);
  71.  
  72. }
  73. }
  74. );
  75.  
  76. l = new JButton("Door Colour");
  77. l.addActionListener(
  78. new ActionListener(){
  79. public void actionPerformed(ActionEvent event){
  80. doorColour = JColorChooser.showDialog(null, "Pick the colour", doorColour);
  81. if(doorColour==null)
  82. doorColour = (Color.RED);
  83.  
  84. }
  85. }
  86. );
  87.  
  88. r = new JButton("Change Name");
  89. r.addActionListener(
  90. new ActionListener(){
  91. public void actionPerformed(ActionEvent event){
  92. s = JOptionPane.showInputDialog("What name do you want to change it to?");
  93.  
  94.  
  95.  
  96. }
  97. }
  98. );
  99.  
  100. }
  101.  
  102.  
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement