The Artima Developer Community
Sponsored Link

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

1 reply on 1 page. Most recent reply: Dec 12, 2003 2:51 AM by Sunitha C S

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 1 reply 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:54 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


Sunitha C S

Posts: 20
Nickname: sunics
Registered: Dec, 2003

Re: little help please. i am sure u could do it in secs. Posted: Dec 12, 2003 2:51 AM
Reply to this message Reply
hi,

U have to define the class Shape with some other name since in java.geom, there is an interface with the name Shape. and hence the square and circle classes are implementing shape, they became abstract class since u havent overridden the abstract method
best of luck
sunitha

Flat View: This topic has 1 reply on 1 page
Topic: JAXB - unmarshall / marshall (xml) comments Previous Topic   Next Topic Topic: Execute a batch file from a Java class

Sponsored Links



Google
  Web Artima.com   

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