The Artima Developer Community
Sponsored Link

Java Answers Forum
little help please. i am sure u could do it in secs.

4 replies on 1 page. Most recent reply: Dec 11, 2003 6:38 PM by Senthoorkumaran Punniamoorthy

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 4 replies on 1 page
luke

Posts: 7
Nickname: phillyhus
Registered: Dec, 2003

little help please. i am sure u could do it in secs. Posted: Dec 11, 2003 3:02 PM
Reply to this message Reply
Advertisement
here is my coding for a java 2d drawing package.

/** GrafPack.java - Version 1.0 - created - 2003 */
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.geom.*;

abstract class Shape
{
/** This is the base class for Shapes in the application. It must be subclassed */
Shape() // constructor
{
}

abstract void draw(Graphics g);
/** This method will draw the shape using the supplied Graphics object */
}

abstract class Shape
{
/** This is the base class for Shapes in the application. It must be subclassed */
Shape() // constructor
{
}

abstract void draw(Graphics g);
/** This method will draw the shape using the supplied Graphics object */
}


public class GrafPack extends JFrame implements ActionListener, MouseListener
{
JMenuBar mainMenu;
JMenu fileMenu;
JMenu createMenu;
JMenu transformMenu;
JMenu colourMenu;
JMenuItem exit;
JMenuItem createSquare;
JMenuItem createCircle;
JMenuItem createRectangle;
JMenuItem createTriangle;
JMenuItem move;
JMenuItem fillRed;
JMenuItem fillGreen;
JMenuItem fillBlue;

Shape aShape = null;
Point nextPoint = null;
String command = "";

public GrafPack()
{
super("2D Drawing Package"); // call base class constructor
Dimension size = Toolkit.getDefaultToolkit().getScreenSize(); // get screen dimensions
setBounds(0,0,size.width,size.height); // use all screen

mainMenu = new JMenuBar(); // main menu bar

fileMenu = new JMenu("File"); // main menu options
createMenu = new JMenu("Create");
transformMenu = new JMenu("Transform");
colourMenu = new JMenu("Colour");

exit = new JMenuItem("Exit"); // menu items
createSquare = new JMenuItem("Create Square");
createCircle = new JMenuItem("Create Circle");
move = new JMenuItem("Move");
fillRed = new JMenuItem("Fill Red");
fillGreen = new JMenuItem("Fill Green");
fillBlue = new JMenuItem("Fill Blue");

// Build Menus
setJMenuBar(mainMenu);

fileMenu.add(exit);

mainMenu.add(fileMenu);
mainMenu.add(createMenu);
mainMenu.add(transformMenu);
mainMenu.add(colourMenu);

createMenu.add(createSquare);
createMenu.add(createCircle);
createMenu.add(createRectangle);
createMenu.add(createTriangle);
transformMenu.add(move);
colourMenu.add(fillRed);
colourMenu.add(fillGreen);
colourMenu.add(fillBlue);

// activate action listeners
exit.addActionListener(this);
createSquare.addActionListener(this);
createCircle.addActionListener(this);
move.addActionListener(this);

// and mouse listener
addMouseListener(this);

// see the screen
setVisible(true);

// process comamnds. The command will be set by the action performed in response to menu selections
while (!command.equals("Exit"))
{
processCommand(); // act upon selected command
}

// On leaving loop, closedown
System.exit(0);
}

public void mouseClicked(MouseEvent eve)
{
nextPoint = eve.getPoint(); // collect point
command =" "; // reset command that was last called.
}
;
public void mouseEntered(MouseEvent e)
{
}
;
public void mouseExited(MouseEvent e)
{
}
;
public void mousePressed(MouseEvent e)
{
}
;
public void mouseReleased(MouseEvent e)
{
}
;

public void actionPerformed(ActionEvent e)
{
aShape=null; // cancel any incomplete shapes
nextPoint=null; // and any waiting points
command = e.getActionCommand(); // collect String used to define menu item's text
}

public void processCommand()
{
if (command.equals("Create Square"))
{
aShape = new Square(getPoint(),getPoint()); // create the square by 2 mouse clicks
repaint(); // redraw screen
}
}

public Point getPoint()
{

Point aPoint = null; // Point to be returned
while (nextPoint==null); // wait for mouse click to change nextPoint
{
aPoint = nextPoint; // store the Point found
nextPoint=null; // reset nextPoint
return aPoint;
}
}

public void paint(Graphics g)
{
// to redraw screen
super.paint(g); // repaint parent
if (aShape != null)
aShape.draw(g); // draw the shape if it exists
}

}









the problem is it returns this error. any clues what i have to do. any help much appreciated. cheers luke

shapeSquare should be declared abstract
shapeCircle should be decalred abstract


any clues. i am lost. cheers


Jonathon Brozny

Posts: 24
Nickname: jonathon
Registered: Oct, 2003

Re: little help please. i am sure u could do it in secs. Posted: Dec 11, 2003 3:24 PM
Reply to this message Reply
if you look to the right next time you post you will see this.

Java code between [ java] and [/java ] will appear in syntax highlighted code font exactly as you format it. (without the spaces I have added)

Then you can even Preview your post to see if you did it correctly.

It makes it easier to read, and help you.

example
public class LooksBetter
{
	String whenFormatted;
}

luke

Posts: 7
Nickname: phillyhus
Registered: Dec, 2003

Re: little help please. i am sure u could do it in secs. Posted: Dec 11, 2003 3:52 PM
Reply to this message Reply
cheers

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: little help please. i am sure u could do it in secs. Posted: Dec 11, 2003 6:37 PM
Reply to this message Reply
Luke,

Its good to cheer up. But why don't you actually go ahead and post your code inside the
 tag Jonathan mentioned.

Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: little help please. i am sure u could do it in secs. Posted: Dec 11, 2003 6:38 PM
Reply to this message Reply
Oh SOrry about it. I later discovered you have actually done that :-) My Mistake

Flat View: This topic has 4 replies on 1 page
Topic: Digitally Signed Java Applet works in IE but not Netscape 7.x.... Previous Topic   Next Topic Topic: Exporting Ms Excel Data To Database

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use