• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Please Help?

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm having problems with a program that save the shapes of a paint program this program has three buttons draw line, oval, rect here is my code:
import java.awt.*;
import java.awt.event.*;
import java.util.Vector;
import javax.swing.*;
public class shapes extends JApplet implements MouseListener, MouseMotionListener, ActionListener
{
public shapes()
{
buttons = new JButton[3];
shapes = new Vector();
}
public void init()
{
buttons[0] = new JButton("Line");
buttons[1] = new JButton("Rectangle");
buttons[2] = new JButton("Oval");
buttons[0].setBackground(Color.red);
controlPanel = new JPanel();
controlPanel.setLayout(new FlowLayout());
controlPanel.setBackground(Color.orange);
for(int i = 0; i < 3; i++)
controlPanel.add(buttons[i]);
drawPanel = new JPanel();
drawPanel.setBackground(new Color(0xffffcc));
Container container = getContentPane();
container.setLayout(new BorderLayout());
container.add(controlPanel, "North");
container.add(drawPanel, "Center");
for(int j = 0; j < 3; j++)
buttons[j].addActionListener(this);
addMouseListener(this);
addMouseMotionListener(this);
}
public void mouseMoved(MouseEvent mouseevent)
{
mouseX = mouseevent.getX();
mouseY = mouseevent.getY();
showStatus("Mouse is moved to (" + mouseX + "," + mouseY + ")");
}
public void mouseDragged(MouseEvent mouseevent)
{
mouseX = mouseevent.getX();
mouseY = mouseevent.getY();
showStatus("Mouse is dragged to (" + mouseX + "," + mouseY + ")");
s.setSize(mouseX, mouseY);
shapes.addElement(s);
repaint();
}
public void mouseEntered(MouseEvent mouseevent)
{
}
public void mouseExited(MouseEvent mouseevent)
{
}
public void mousePressed(MouseEvent mouseevent)
{
s = new Shape(shape, mouseX, mouseY);
}
public void mouseReleased(MouseEvent mouseevent)
{
}
public void mouseClicked(MouseEvent mouseevent)
{
}
public void actionPerformed(ActionEvent actionevent)
{
for(int i = 0; i < 3; i++)
{
buttons[i].setBackground(Color.lightGray);
if(actionevent.getSource() == buttons[i])
{
shape = i;
buttons[i].setBackground(Color.red);
}
}
}
public void paint(Graphics g)
{
super.paint(g);
g.setColor(Color.blue);
for(int i = 0; i < shapes.size(); i++)
((Shape)shapes.elementAt(i)).draw(g);
}
private int mouseX;
private int mouseY;
private int mouseXold;
private int mouseYold;
private JButton buttons[];
private JPanel controlPanel;
private JPanel drawPanel;
private int shape;
private Shape s;
private Vector shapes;

and having these problems when I compile it:
jcarrill@linux:~/cs201> javac shapes.java
shapes.java:51: cannot resolve symbol
symbol : method setSize (int,int)
location: interface java.awt.Shape
s.setSize(mouseX, mouseY);
^
shapes.java:66: java.awt.Shape is abstract; cannot be instantiated
s = new Shape(shape, mouseX, mouseY);
^
shapes.java:96: cannot resolve symbol
symbol : method draw (java.awt.Graphics)
location: interface java.awt.Shape
((Shape)shapes.elementAt(i)).draw(g);
^
please help I'm fustrated.
 
Ranch Hand
Posts: 1211
Mac IntelliJ IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jose Carrillo:
Hi I'm having problems with a program that save the shapes of a paint program this program has three buttons draw line, oval, rect here is my code:
----
public void mouseDragged(MouseEvent mouseevent)
{
mouseX = mouseevent.getX();
mouseY = mouseevent.getY();
showStatus("Mouse is dragged to (" + mouseX + "," + mouseY + ")");
s.setSize(mouseX, mouseY);
shapes.addElement(s);
repaint();
}
----
private int shape;
private Shape s;
private Vector shapes;
----
and having these problems when I compile it:
jcarrill@linux:~/cs201> javac shapes.java
shapes.java:51: cannot resolve symbol
symbol : method setSize (int,int)
location: interface java.awt.Shape
s.setSize(mouseX, mouseY);
^
shapes.java:66: java.awt.Shape is abstract; cannot be instantiated
s = new Shape(shape, mouseX, mouseY);
^
shapes.java:96: cannot resolve symbol
symbol : method draw (java.awt.Graphics)
location: interface java.awt.Shape
((Shape)shapes.elementAt(i)).draw(g);
^
please help I'm fustrated.


You have named ur class shapes, make sure that you are not using Shape instead of shapes anywhere by mistake, which seems to be an abstract class in java.awt package. Better still, name your class MyShape or something else to avoid the confusion.
cheers
 
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What's the Shape object you're trying to use? I don't think there is one that exists (of course, the compiler is telling you that too).
Also, you don't have a main method...
I'm going to try to compile and run this, as I just finished a very similar project.
I'll post code tonight...if I can....
 
David Crossett
Ranch Hand
Posts: 102
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Duh...noticed this was an applet. Could you take me through your thinking here? It seems that the user is to push one of three buttons and then they will turn red. Does the user specify the bounds of the shape (using the mouse) and THEN the object is stored? What is it that this program is supposed to do? I've dissected it, but need some info.
 
Jose Carrillo
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
this program suppose to have three buttons draw line, oval, and rect. when someone click on them they will turn red and the user will be able to draw a oval or a line depends of what button he or she clicked. it works just as the paint program in windows and it has to save the shapes of the lines, ovals, and rect.
 
Sheriff
Posts: 6450
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing / JFC / AWT.
 
reply
    Bookmark Topic Watch Topic
  • New Topic