Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void paintComponent(Graphics g){
- super.paintComponent(g);
- Rectangle r = new Rectangle(500,300,250,400);
- g.setColor(jpp.bodyColour);
- g.fillRect((int)r.getX(),(int)r.getY(),(int)r.getHeight(),(int)r.getWidth());
- g.setColor(Color.BLUE);
- g.drawString("banana", 50, 60);
- }
- import java.awt.*;
- import java.awt.event.*;
- import javax.swing.*;
- public class TestProjectJPanel extends JFrame {
- public JButton b;
- public JButton u;
- public JButton l;
- public JButton r;
- public String s;
- public Color color = (Color.WHITE);
- public JPanel panel;
- public Color bodyColour;
- public Color doorColour;
- public Color wheelColour;
- public TestProjectJPanel(){
- JFrame f = new JFrame();
- panel = new JPanel();
- panel.setBackground(color);
- // bodyColour button
- b = new JButton("Body Colour");
- b.addActionListener(
- new ActionListener(){
- public void actionPerformed(ActionEvent event){
- bodyColour = JColorChooser.showDialog(null, "Pick the colour", bodyColour);
- if(bodyColour==null)
- bodyColour = (Color.RED);
- }
- }
- );
- u = new JButton("Wheel Colour");
- u.addActionListener(
- new ActionListener(){
- public void actionPerformed(ActionEvent event){
- wheelColour = JColorChooser.showDialog(null, "Pick the colour", wheelColour);
- if(wheelColour==null)
- wheelColour = (Color.BLACK);
- }
- }
- );
- l = new JButton("Door Colour");
- l.addActionListener(
- new ActionListener(){
- public void actionPerformed(ActionEvent event){
- doorColour = JColorChooser.showDialog(null, "Pick the colour", doorColour);
- if(doorColour==null)
- doorColour = (Color.RED);
- }
- }
- );
- r = new JButton("Change Name");
- r.addActionListener(
- new ActionListener(){
- public void actionPerformed(ActionEvent event){
- s = JOptionPane.showInputDialog("What name do you want to change it to?");
- }
- }
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement