This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Please Help? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Please Help?" Watch "Please Help?" New topic
Author

Please Help?

Jose Carrillo
Greenhorn

Joined: Nov 13, 2003
Posts: 17
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.
Sonny Gill
Ranch Hand

Joined: Feb 02, 2002
Posts: 1211

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


The future is here. It's just not evenly distributed yet. - William Gibson
Consultant @ Xebia. Sonny Gill Tweets
David Crossett
Ranch Hand

Joined: Feb 05, 2003
Posts: 102
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
-nothing important to say, but learnin' plenty-
David Crossett
Ranch Hand

Joined: Feb 05, 2003
Posts: 102
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

Joined: Nov 13, 2003
Posts: 17
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.
Jason Menard
Sheriff

Joined: Nov 09, 2000
Posts: 6450
Moving to Swing / JFC / AWT.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Please Help?
 
Similar Threads
HELP
HELP 5
HELP2
Help 3
Hello