473,395 Members | 1,595 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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:
Expand|Select|Wrap|Line Numbers
  1. /**
  2.  
  3. import javax.swing.*;
  4. import java.awt.*;
  5. import java.awt.event.*;
  6.  
  7. public class packman extends JFrame implements ActionListener{
  8.  
  9.     JButton flip = new JButton("Start");
  10.     JPanel draw = new JPanel();
  11.     JPanel button = new JPanel();
  12.     int start = 30;
  13.     boolean right = false;
  14.  
  15.     public packman() {
  16.         setSize(400,400);
  17.         setLocationRelativeTo(null);
  18.         setDefaultCloseOperation(EXIT_ON_CLOSE);
  19.         setLayout(new BorderLayout());
  20.  
  21.         flip.addActionListener(this);
  22.         button.add(flip);
  23.         add(button, BorderLayout.SOUTH);
  24.         add(draw, BorderLayout.CENTER);
  25.  
  26.     }
  27.  
  28.         public void actionPerformed(ActionEvent e) {
  29.         Graphics g = draw.getGraphics();
  30.         g.setColor(Color.YELLOW);
  31.  
  32.         if(right) {
  33.             flip.setText("Start");
  34.             right = false;
  35.         }
  36.  
  37.         else {
  38.             start = 210;
  39.             flip.setText("Undo");
  40.             right = true;
  41.         }
  42.  
  43.  
  44.     }
  45.  
  46.     public void paint(Graphics g) {
  47.         super.paint(g);
  48.         //Graphics gg = packman.getGraphics();
  49.         g.setColor(Color.RED);
  50.         g.fillArc(150,150,65,65,30,300);
  51.         //start.getText
  52.     }
  53.  
  54.     public static void main(String[] args) {
  55.         packman obj = new packman();
  56.         obj.setVisible(true);
  57.     }
  58.  
  59.     public class Rotate{
  60.     int pac,a,s;
  61.          public Rotate(int pac, int a, int s) {
  62.              this.pac = pac;
  63.              this.a = a;
  64.              this.s = s;
  65.     }
  66.  
  67.  }
  68.  
  69.  
  70. }
Dec 13 '10 #1
0 1304

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Tejus | last post by:
Hi All, A strange problem in java on unix. When i use File.renameTo(File) to move a file from one location to another,it does not work if I try to move to a different partition. or (a file...
1
by: Christian W. Guenther | last post by:
Hallo, please excuse if I violate any group etiquette etc. but I am not very experienced both regarding the usenet and your group. I have installed Xindice, integrated into Tomcat, and can use...
15
by: Steve Horrillo | last post by:
I can't figure out why this script won't insert the subject in the email and why can't I control the font and size being used? I'm not sure where to post this. Let me know where if this is OT. ...
7
by: vj | last post by:
Hello Group, I am C++/OOP newbie and was working on a project when i came accross this puzzleing problem with inheritence. C++ Code ================== class Parent {
2
by: Tim Murray | last post by:
First of all, I don't know much about Java, even its naming and version numbering nomenclature, and second, if there is a better group to ask this in, please let me know. System is Mac with...
3
by: Sam Gutteridge | last post by:
I'm having problems running what seems like all Java applets and programs. Java applets in Internet Explorer do not load while I'm trying to install software using java and I get the error message...
1
by: alik | last post by:
I am having problem with understanding the project's concept and what exactly we need to follow. I don't know if we have to create files and how many. This is my first programing experience and I am...
4
by: keveaton | last post by:
hi guys and girls, hope all is well. im not sure if this is the right place to post this, so apologies if so, here goes anyway. i have a customer who uses a java applet to view real time stock...
6
by: frozzenn | last post by:
I'm getting this message: "C:\Documents and Settings\Evaldas\Desktop\mokslas\JAVA 2kursas\L2\cubemethod.java:5: class L2cubemethod is public, should be declared in a file named L2cubemethod.java...
1
by: jimismint | last post by:
Hi guys, i'm stuck on this problem. only just recently started coding java using blue J. Can you guys help me. import java.util.*;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.