dear all,

i have a problem in creating a triangle custom cursor in my paint program. i had tried to use a GIF file type of triangle shape but nothing happened. could anybody please help me?

below is the paint program

thank you in advance.

package org.me.hello;

import java.awt.event.*;
import java.awt.*;
import java.applet.*;
import java.util.Vector;
import javax.swing.*;

public class DrawTest extends Applet{
    DrawPanel panel;


    public void init() {

    setLayout(new BorderLayout());
    panel = new DrawPanel();
    add("Center", panel);
    }

    public static void main(String args[]) {


    Frame f = new Frame("DrawTest");
    DrawTest drawTest = new DrawTest();
    drawTest.init();
    drawTest.start();

    f.add("Center", drawTest);
    f.setSize(800, 800);
    f.show();
    }
    public String getAppletInfo() {
        return "A simple drawing program.";
    }
}

class DrawPanel extends Panel implements MouseListener, MouseMotionListener {

    public DrawPanel(){

        setBackground(Color.white);
    addMouseMotionListener(this);
    addMouseListener(this);

        JButton button = new JButton("Quit");
        button.addActionListener (new ActionListener () { 
            public void actionPerformed (ActionEvent e) { 
                System.exit (0);
            } 
        } );
        add(button);
    }

    public static final int POINTS = 1;
    int       mode = POINTS;
    Vector points = new Vector();
    Vector colors = new Vector();
    int x1,y1;
    int x2,y2;

    public void setDrawMode(int mode) {
    switch (mode) {
      case POINTS:
        this.mode = mode;
        break;
      default:
        throw new IllegalArgumentException();
    }
    }

    public void mouseDragged(MouseEvent e) {
        e.consume();
        switch (mode) {
            case POINTS:
            default:
                colors.addElement(getForeground());
                points.addElement(new Rectangle(x1, y1, e.getX(), e.getY()));
                x1 = e.getX();
                y1 = e.getY();
                break;
        }
        repaint();
    }

    public void mouseMoved(MouseEvent e) {
    }

    public void mousePressed(MouseEvent e) {
        e.consume();
        switch (mode) {
            case POINTS:
            default:
                colors.addElement(getForeground());
                points.addElement(new Rectangle(e.getX(), e.getY(), -1, -1));
                x1 = e.getX();
                y1 = e.getY();
                repaint();
                break;
        }
    }

    public void mouseReleased(MouseEvent e) {
        e.consume();
        switch (mode) {
            case POINTS:
            default:
                break;
        }
        repaint();
    }

    public void mouseEntered(MouseEvent e) {

    }

    public void mouseExited(MouseEvent e) {

    }

    public void mouseClicked(MouseEvent e) {
    }

    public void paint(Graphics g) {
    int np = points.size();

    /* draw the current lines */
    g.setColor(getForeground());
    for (int i=0; i < np; i++) {
        Rectangle p = (Rectangle)points.elementAt(i);
        g.setColor((Color)colors.elementAt(i));
        if (p.width != -1) {
        g.drawLine(p.x, p.y, p.width, p.height);
        } else {
        g.drawLine(p.x, p.y, p.x, p.y);
        }
    }
    }
}

Recommended Answers

All 2 Replies

There's nothing to do with cursors in there, no wonder you don't get a custom cursor to show up :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.