so far i got this...
but the shapes that i created i need to be able to click and dragg and move around with the mouse..help!!!!
and also some where here i need to draw and equal sided triangle
IN PANEL
import java.awt.*;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.MouseEvent;
import javax.swing.JPanel;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.sql.Array;
import javax.swing.*;
public class Drawing extends JPanel
implements MouseListener, MouseMotionListener {
int size = 60;
int x = 0;
int y = 0;
boolean dragging = false;
public Drawing() {
addMouseListener(this);
addMouseMotionListener(this);
}
/** Creates new form Drawing */
@Override public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(new Color(125, 167, 116));
g2d.fillOval(10, 15, size, size);
g2d.setColor(new Color(42, 179, 231));
g2d.fillRect(130, 15, 90, size);
g2d.setColor(new Color(70, 67, 123));
g2d.fillRect(250, 15, 90, size);
if (dragging) {
g2d.setColor(new Color(255, 255, 255));
g2d.drawString("Dragging",x,y);
}
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
}// </editor-fold>
public void mouseClicked(MouseEvent e) {
size = size + 5;
this.repaint();
}
public void mousePressed(MouseEvent e) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.M OVE_CURSOR));
}
public void mouseReleased(MouseEvent e) {
this.setCursor(Cursor.getPredefinedCursor(Cursor.D EFAULT_CURSOR));
dragging = false;
this.repaint();
}
public void mouseEntered(MouseEvent e) {
}
public void mouseExited(MouseEvent e) {
}
public void mouseDragged(MouseEvent e) {
dragging = true;
x = e.getX();
y = e.getY();
this.repaint();
}
public void mouseMoved(MouseEvent e) {
}
// Variables declaration - do not modify
// End of variables declaration
}
IN FRAME
import java.awt.*;
import javax.swing.JFrame;
/**
*
* @author User
*/
public class Ass4Main {
public static void main(String[] args){
Drawing draw = new Drawing();
JFrame frame = new JFrame("Drawing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.add(draw);
frame.setSize(500,500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}