1 Replies - 899 Views - Last Post: 18 April 2009 - 10:51 PM Rate Topic: -----

#1 kitkat24  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 14-April 09

Java Draw Project Code Errors

Posted 14 April 2009 - 08:06 AM

Attached File  ProjectDraw.zip (7K)
Number of downloads: 49I am trying to create a simple drawing program that will allow two users to draw out math problems to work on together. So, instead of a user typing 2^2 they could instead draw it. I was wanting to add buttons with simple geometric shapes (line, right triangle, rectangle, circle), as well as buttons with mathematical symbols such as (>, <, =, +, v, =, =, -, *, =, ?, , ?, 8) I have been running against a brick wall for a month and cannot find help and have not been able to get even a simple line drawing program to work.

I have tried viewing similar source code files for drawing programs but none contain any comments explaining to me what does what and my instructor is of no use. I have some of the code I have pieced together so far and have included it below.

Could someone please explain to me what I have done wrong and what I need to do to fix it. I need to get a grasp on this so that I can continue with this project and get it completed in time. I wish I could borrow someone's brain for the next 5 weeks to get me through this course as I feel I have learned nothing and wasted my money when I would have been better off teaching myself, but with all the assignments I do not have time to teach myself and I am just skimming by. (sorry for my little rant; just frustrated)

Thank you in advance <3

KitKat

Portion of Current Code:

package simpledraw;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.util.ArrayList;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class drawing extends JFrame implements MouseListener{//this gives me an error
/**
* 
*/
private static final long serialVersionUID = 1L;
int positionX1 = 0;
int positionY1 = 0;

int positionX2 = 0;
int positionY2 = 0;
int maxLines = 1000;
int currentLines = 0;
int[][] drawLines = new int[maxLines][4];

ArrayList al = new ArrayList();//this gives me an error
public drawing(){
setLayout(null);
JPanel p = new JPanel();
p.addMouseListener(this);
p.setBounds(0,0,800,600);	
add(p);

setTitle(title);//
setSize(800,600);
setResizable(false);
setLocationRelativeTo(null);
setVisible(true);	
}

public static void main(String[] args){
drawing DL = new drawing();
}

public void paint(Graphics g){
super.paintComponents(g);
for(int i = 0; i < al.size(); i++){
g.drawLine(drawLines[i][0],drawLines[i][1],drawLines[i][2],drawLines[i][3]);
}
}

public void mouseClicked(MouseEvent e) {
}

public void mouseEntered(MouseEvent e) {}//this gives me an error
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
*/
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {	
drawLines[currentLines][0] = positionX1 = e.getX();
drawLines[currentLines][1] = positionY1 = e.getY();

}

public void mouseReleased(java.awt.event.MouseEvent e) {
drawLines[currentLines][2] = positionX2 = e.getX();
drawLines[currentLines][3] = positionY2 = e.getY();
al.add(drawlines); //this is showing an error
currentLines++;
repaint();
}
}


Attached File  ProjectDraw.zip (7K)
Number of downloads: 49

Is This A Good Question/Topic? 0
  • +

Replies To: Java Draw Project Code Errors

#2 jpete7683  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 80
  • Joined: 18-April 09

Re: Java Draw Project Code Errors

Posted 18 April 2009 - 10:51 PM

Sun has very good examples on how to create buttons:
http://java.sun.com/...#abstractbutton


As for the different sections of code you marked as errors you can make the following changes:

Below int[][] drawLines = new int[maxLines][4];
Add:
ArrayList<int[][]> al = new ArrayList<int[][]>();
public static drawing dl;


change:
drawing dl = new drawing();


to:
dl = new drawing();



Instead of:
setTitle(title);


Use:
setTitle("title");//need to input a string value



Hope this helps!!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1