How to rotate packman? Java Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • The Lord
    New Member
    • Dec 2010
    • 1

    #1

    How to rotate packman? Java Problem

    Hi,

    I have had this question :

    The “mouth” of the Packman is open by 60 degrees.
    Clicking Start should rotate the figure 180 degrees and change the button caption to "Undo", clicking the button again restore the original position and change the caption back to "Start".

    My program now is working, but I need it to totate, so would you please help me doing that ?

    Here is the code:
    Code:
    /**
    
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    
    public class packman extends JFrame implements ActionListener{
    
    	JButton flip = new JButton("Start");
        JPanel draw = new JPanel();
        JPanel button = new JPanel();
        int start = 30;
        boolean right = false;
    
        public packman() {
        	setSize(400,400);
        	setLocationRelativeTo(null);
        	setDefaultCloseOperation(EXIT_ON_CLOSE);
        	setLayout(new BorderLayout());
    
        	flip.addActionListener(this);
        	button.add(flip);
        	add(button, BorderLayout.SOUTH);
        	add(draw, BorderLayout.CENTER);
    
        }
    
            public void actionPerformed(ActionEvent e) {
        	Graphics g = draw.getGraphics();
        	g.setColor(Color.YELLOW);
    
        	if(right) {
        		flip.setText("Start");
        		right = false;
        	}
    
        	else {
        		start = 210;
        		flip.setText("Undo");
        		right = true;
        	}
    
    
        }
    
        public void paint(Graphics g) {
        	super.paint(g);
        	//Graphics gg = packman.getGraphics();
        	g.setColor(Color.RED);
        	g.fillArc(150,150,65,65,30,300);
    		//start.getText
        }
    
        public static void main(String[] args) {
        	packman obj = new packman();
        	obj.setVisible(true);
        }
    
        public class Rotate{
        int pac,a,s;
        	 public Rotate(int pac, int a, int s) {
        	 	this.pac = pac;
        	 	this.a = a;
        	 	this.s = s;
        }
    
     }
    
    
    }
Working...